PDA

View Full Version : Custom .j2a files


Violet CLM
Apr 6, 2015, 07:01 PM
<a href="http://www.jazz2online.com/jj2plus/">JJ2+ version 5.0</a> includes two new .j2a files, but no instructions for how to make your own. Sorry. See, what happened is I came up with an internal tool for us to use, but then never found the time to make anything more user-friendly out of it, and didn't feel quite right bundling the internal tool with the main release.

<a href="http://sam.shemitz.net/static/files/misc/pyJ2A.zip">But here you go, if you do want to make your own .j2a files.</a>

It's just some very basic Python 2.x files using PIL. Run <strong>j2a-extract.py</strong> and type the filepath of one of your existing .j2a files to see what kind of file structure is expected of you, compile your own set of sprites, then run <strong>j2a-import.py</strong>. If you're extracting <code>C:\Games\Jazz2\foo.j2a</code>, the results will be stored in a few folder <code>C:\Games\Jazz2\foo-j2a\</code> as a series of subfolders, one for each anim set in the file. Each subfolder will contain a series of subsubfolders, one for each animation, and those will each contain a series of .png files, one for each anim frame. Then later when you're importing, the file/folder name relation will be the same&mdash;import the folder <code>C:\Games\Jazz2\bar-j2a\</code> to build <code>C:\Games\Jazz2\bar.j2a</code>.

The .png files store all the frame metadata in their filenames, using the format <code>FRAMENUMBER,HOTSPOTX,HOTSPOTY,COLDSPOTX,COLDSPOTY, GUNSPOTX,GUNSPOTY.png</code>. If the frame should be drawn as transparent by default, include the letter "t" right after FRAMENUMBER, e.g. <code>0t,-9,-11,0,0,0,0.png</code>.

It hopefully sounds more complicated than it is. Look at one or more existing .j2a files and you should figure out how it works pretty quickly. What you <em>shouldn't</em> do is try to use this to rebuild anims.j2a, since this has absolutely no support for <em>sounds</em>, only sprites, and anims.j2a has hundreds of sounds in it that you would end up deleting. And if you can't figure how to run .py files, wait around and hope that someone will make an executable version.

Post any related questions here and I'll do my best to answer them, even if that answer is "google python", though consider also the general AngelScript help thread.

(thanks go to Stijn, whose code I modified, and Neobeo, whose research this was based on.)

FawFul
Apr 7, 2015, 01:04 PM
I have python, but i can't seem to get a prompt by just opening the file and selecting the python tool. This could use some more explanation i feel :0.

Violet CLM
Apr 7, 2015, 03:36 PM
You need to <em>run</em> the file, not just open it.

XxMoNsTeRXM
Apr 8, 2015, 07:02 AM
It doesn't work I run it with the specified arguments but still invalid syntax.
http://i.imgur.com/SZpdWFq.png

Stijn
Apr 8, 2015, 07:16 AM
You probably installed Python 3. The scripts are only compatible with Python 2.x, so install that and try again.

XxMoNsTeRXM
Apr 8, 2015, 07:20 AM
You probably installed Python 3. The scripts are only compatible with Python 2.x, so install that and try again.
oh, ok... that explains everything...
EDIT: Another error: http://i.imgur.com/OrIig71.png

FawFul
Apr 8, 2015, 11:33 AM
I have the same error as monster :(.

Violet CLM
Apr 8, 2015, 11:34 AM
Okay, that one's on me. I forgot misc.py in the zip. Sorry, try again now.

XxMoNsTeRXM
Apr 8, 2015, 11:59 AM
Okay, that one's on me. I forgot misc.py in the zip. Sorry, try again now.

Ok, what now? Another file that you forgot?
http://i.imgur.com/wVOd0ty.png
I looked into the code, and the module is imported on j2a.py line 11

FawFul
Apr 8, 2015, 12:05 PM
"No module named image"

Violet CLM
Apr 8, 2015, 12:11 PM
#needs python image library, http://www.pythonware.com/library/pil/
import Image
It's right there in the file.

FawFul
Apr 8, 2015, 01:36 PM
"please type the .j2a file you wish to extract"
Anims
file plus.j2a could not be read!

"please type the .j2a file you wish to extract"
plus
file plus.j2a could not be read!

"please type the .j2a file you wish to extract"
Anims.j2a
file plus.j2a could not be read!

"please type the .j2a file you wish to extract"
plus.j2a
file plus.j2a could not be read!

......

Also it was a pain finding the right PIL library, your link did not provide the right info. I think you meant:

http://www.pythonware.com/products/pil/

not,

http://www.pythonware.com/library/pil/

Even then it link for 2.7 was not working so i searched the internet. Apparently something named PILLOW took it place but i still manage to find the right library here: http://christianakesson.com/compiling-pil/ at the bottom of the article.

Still not working though...

Stijn
Apr 8, 2015, 01:39 PM
I'm not sure what happened for you, but the link in misc.py leads me to http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.7.exe after a few clicks. Is that what you installed?

Looking at j2a.py the error you're getting means the j2a file can't be read. Are you sure the path is right? Are you maybe entering "Anims" instead of "Anims.j2a"? The script needs the full filename, including extension.

FawFul
Apr 8, 2015, 01:57 PM
I can't open the link you just gave, it is the same link on the page i send. It gives a web-page error. 'Web page not available'.. or simply doesn't exist anymore. That's why i downloaded it elsewhere. I'm quite sure this what I have should also work.

Also no, i have D:\Games\Jazz2. so on the D: directory, not C:.
I entered D:\games\jazz2\j2a-extract.py in the command prompt.

Then received a message

"please type the .j2a file you wish to extract"

Anims

and then..

file Anims.j2a could not be read!

It is from C:\Users\Lennart> though, but imo asking 'which j2a I want to extract' shows it has the right .py file in the jazz2 folder.

Stijn
Apr 8, 2015, 02:01 PM
I think I opened the wrong file, and I edited my post accordingly. You need to enter the full file name, including the extension. So "Anims.j2a", not "Anims", unless you renamed your file to not include an extension. Make sure the file is in the same folder as the scripts too, I'm not certain it will work otherwise.

FawFul
Apr 8, 2015, 02:04 PM
jazz2 folder contains the pil library, the given .py extensions in the zip (also the misc). j2a files and i typed "Anims.j2a" and still it doesn't read. Folder is 1.23 if it's important.

XxMoNsTeRXM
Apr 8, 2015, 09:34 PM
jazz2 folder contains the pil library, the given .py extensions in the zip (also the misc). j2a files and i typed "Anims.j2a" and still it doesn't read. Folder is 1.23 if it's important.
Wait, you say the given .py extensions in the zip, you gotta extract them into the jazz2 folder.

EDIT: Wat?
http://i.imgur.com/Ge3Iik2.png
And this is all it gave to me
http://i.imgur.com/89UI1NT.png
This is the command I typed in Command Prompt: python j2a-extract.py "{path to jj2folder, not to .j2a file, I found that by myself}" after this it told me:
Please type the filename of the .j2a file you wish to extract:
So I type: plus.j2a
and then the error happens, and I only get two folders and only one file, fps.10

Violet CLM
Apr 8, 2015, 10:43 PM
Ah, yeah, it's been long enough since I used j2a-extract that I'd forgotten it wants a palette file. I've put that in the zip too.

You'll probably still have trouble with plus.j2a, but the other two .j2a files in your folder should work fine. FawFul noticed earlier that plus.j2a was accidentally assembled in a way that JJ2+ accepts but j2a-extract doesn't :(

XxMoNsTeRXM
Apr 8, 2015, 10:55 PM
Ah, yeah, it's been long enough since I used j2a-extract that I'd forgotten it wants a palette file. I've put that in the zip too.

You'll probably still have trouble with plus.j2a, but the other two .j2a files in your folder should work fine. FawFul noticed earlier that plus.j2a was accidentally assembled in a way that JJ2+ accepts but plus-extract doesn't :(
Now it works! Finally! Thanks!

EDIT: Now help me understand the images:
http://i.imgur.com/GAfBbIH.png
The first zero is the frame, the next numbers I don't know what they are.

EDIT 2: nvm...

Violet CLM
Apr 8, 2015, 10:57 PM
Yay! That's both of you... now I've exhausted the market and don't need to worry about making a proper executable ever. /s

XxMoNsTeRXM
Apr 9, 2015, 12:06 AM
Yay! That's both of you... now I've exhausted the market and don't need to worry about making a proper executable ever. /s

Too many errors... ugh...
BTW... this is on j2a-import.py:
http://i.imgur.com/nvFP9J1.png

Violet CLM
Apr 9, 2015, 09:25 AM
That'll happen if you have one or more improperly formatted image filenames.

FawFul
Apr 9, 2015, 09:55 AM
I used this script:

#pragma require "Mario.j2a"
#pragma name "Play as Mario!"

/************************************************/
/**********Play as Mario! by FawFuL**************/
/************************************************/

void onLevelLoad() {
jjAnimSets[ANIM::SPAZ].load(0, "mario.j2a");
jjAnimSets[ANIM::SPAZ2].load(1, "mario.j2a");
}

void onPlayer(jjPLAYER@ play) {
if (play.charCurr == CHAR::JAZZ || play.charCurr == CHAR::LORI) play.morphTo(CHAR::SPAZ);
}

And i ran into 2 problems:

1: Animation index
the animation indexes for 1.23 and 1.24 are different for set Anim::SPAZ. There are unused animations in 1.23 that clutter the animation order like spaz grabbing ledges, the j2a is based on 1.24. Apparently there are ways to fix this but it's really complicated. It also makes this preset stuff redundant if it doesn't takes differences in indexes into account.

2. Wrong animations on other online players
I overrided Anim::SPAZ and Anim::SPAZ2 and they look right for 1.24 users, however you get weird cluttered images on other players. (bird animations, bullets and a few of the custom animations, iirc). Vanilla jj2 draws your own sprites and others sprites right from Anim::SPAZ, why does my custom j2a make it show 2 different things on local and online players? Is this fixable?

I suggest that it's maybe useful to have a snippet that fixes these 2 problems, because i imagine more players would want to make their own custom j2a characters. afaik there were some already that ppl liked to import :(.. a snippet could be nice and reusable for this.

Violet CLM
Apr 9, 2015, 11:57 AM
This is what the <a href="http://www.jazz2online.com/jj2plus/plus-angelscript.html#rabbit">RABBIT::Anim</a> enum is for! Maybe once you get it working, <em>you</em> can be the one to write the snippet. :)

<a href="http://www.jazz2online.com/jj2plus/plus-angelscript.html#jjanimation">Additional hint.</a>

Lark
Apr 10, 2015, 08:07 PM
eh I'm gonna play with this tomorrow when I have time to be awake late, but you're saying no support for extracting or viewing in game sfx (yet)?? :( bummer dude, I hope to see that soon ;)

Violet CLM
Apr 10, 2015, 09:05 PM
<a href="http://djazz.mine.nu/apps/jj2soundboard/">SFX over here</a>

Seren
Apr 11, 2015, 01:08 AM
DJazz's site also lets you download an archive with all JJ2 sounds (http://djazz.mine.nu/files/sfxTSF_wav.zip) in wav format, although they're unnamed there.

FawFul
Apr 11, 2015, 07:04 AM
I made my anims script work by adding 3 additional sets for 1.23. I tried to do both 1.23 and TSF with a single set, but I didn't manage to make it work (sorry Violet!). It is probably possible with RABBIT::ANIM.

both 1.23 and TSF run the fully correct animation replacements now, however you still see other players wrong. The following explanation is what happens when seeing other online players:

For example RABBIT:: DIVE while it should be RABBIT::STAND, RABBIT::STAND while it should be RABBIT::IDLE2..... RABBIT:: DIVE while it should be RABBIT::JUMPING1. I found out that it does somewhat try to get the right frames, for example it stays stuck in the buttomp frame forever whenever a player buttstomps. It stays stuck in the airboard frame whenever someone had an airboard and whenever someone ducks it stays stuck in that frame aswell. It can even still load the latest 'normal' spaz sprite upon cycling. Is this a bug or can i do something about this in AS? all animations are loaded upon levelload so i don't understand why there is a 'refresh-rate' problem (eventhough some animations won't show at all even if you wait for a delay). when i duck, someone else will see the right animation index 3 seconds late and will only show a single frame instead of a complete animation. I'd like to add that the 'errors' are really consistent. Always the same frames where it gets stuck in and the same RABBIT::ANIM sets that will change with it. The only animation indexes that work somewhat well are RABBIT::AIRBOARD and RABBIT::CORPSE.

Maybe unimportant to say, but this was not the case if you shared custom j2a files back in the day.

DennisKainz
Apr 26, 2015, 02:20 PM
There's a problem. Whether I use Python 2 or Python 3, when I write "C:\", Python highlights the ":" in "C:\" as invalid syntax

Stijn
Apr 26, 2015, 02:23 PM
Try putting it between "quotes".

DennisKainz
Apr 26, 2015, 10:56 PM
http://i.imgur.com/xYxRcu0.png

I don't want to give up! I really need that custom j2a file!

Stijn
Apr 27, 2015, 01:06 AM
...you're not supposed to run things inside the python interpreter.

Open the terminal, go to the right folder, then run "python j2a-extract.py plus.j2a". That's all.

DennisKainz
Apr 27, 2015, 01:45 AM
By terminal you mean cmd.exe in System 32, right?
Because there seems to be yet another problem ...

When I write the line "C:\Games\Jazz2>python j2a-extract.py" I get "Access Denied"

Stijn
Apr 27, 2015, 02:04 AM
https://technet.microsoft.com/en-us/library/cc947813%28v=ws.10%29.aspx

DennisKainz
Apr 27, 2015, 03:07 AM
http://i.imgur.com/s0otDnF.png
EDIT: Solved.
If you get this message, it is because your PNGs aren't color-indexed.

P.S. Thanks for your help, admin! Now I can create my own j2a files!

XxMoNsTeRXM
May 2, 2015, 12:04 AM
http://i.imgur.com/s0otDnF.png
If you get this message, it is because your PNGs aren't color-indexed.


What do you mean aren't colored-index? (I got this error too) :confused:

Violet CLM
May 2, 2015, 12:19 AM
You need to use 8-bit PNGs, not 24/32.

XxMoNsTeRXM
May 2, 2015, 03:13 AM
You need to use 8-bit PNGs, not 24/32.
Still doesn't work, I made them 23x31, same error.

cooba
May 2, 2015, 03:27 AM
Still doesn't work, I made them 23x31, same error.No offense but LOL.

8-bit means they need to be 256 colors and use the JJ2 palette.

XxMoNsTeRXM
May 2, 2015, 03:32 AM
No offense but LOL.

8-bit means they need to be 256 colors and use the JJ2 palette.
AH ok. Thx
EDIT: Where can I get the jj2 palette?

Jelly Jam
May 2, 2015, 04:18 AM
if ya have jsd, that big area with color blocks is the 256 pallete which is used by jj2, or atleast that's what i think.

XxMoNsTeRXM
May 2, 2015, 04:46 AM
if ya have jsd, that big area with color blocks is the 256 pallete which is used by jj2, or atleast that's what i think.

Nvm... I found a jj2 palette in my jj2 folder. ;)
EDIT: Wait, there are more colors ;( (in one color, they've got noise)

Violet CLM
May 2, 2015, 10:24 AM
There's a .pal file included in the pyJ2A.zip that you downloaded. Use that.

XxMoNsTeRXM
May 3, 2015, 11:53 PM
There's a .pal file included in the pyJ2A.zip that you downloaded. Use that.

Ah ok, thanks!

XxMoNsTeRXM
May 13, 2015, 06:51 AM
Same error.

szmol96
May 24, 2015, 08:10 AM
Where can I get the jj2 palette?
It is included in the zip.

Also, the python files worked like a charm for me, but after importing a png file, the colors got messed up. I have no idea why, because I have loaded the included palette in Paint Shop Pro. Any help would be appreciated.

Violet CLM
May 24, 2015, 11:17 AM
Without seeing some combination of the png, the .j2a, or the code, it's difficult for me to say anything.

szmol96
May 25, 2015, 03:53 AM
Sorry, I was browsing from my phone when I wrote that reply. Anyway, here's the image.
http://i.imgur.com/FFXbC0D.png
You can see the original sprite on the left and the one that shows up in JazzSD on the right.

EDIT: Also, here's some additional information. After re-opening the image in Paint Shop Pro, it has the following palette.
http://i.imgur.com/ff9jxK6.png

Seren
May 25, 2015, 04:21 AM
Well that palette clearly isn't the JJ2 palette so the answer is fairly simple. You do need to retain correct palette indices.

szmol96
May 25, 2015, 04:42 AM
I can't do that. It keeps sorting out colors that aren't used.

Treylina
May 25, 2015, 08:11 AM
Well, graphicsgale doesn't do that unless you tell it to remove unused colours. The free version will do fine.

I'm guessing you can stop PSP from removing unused colours, but I don't use that program so I'm useless on that.

Violet CLM
May 25, 2015, 08:58 AM
In the Save dialog, click "Options" and then uncheck "Optimized palette." The flow/wording may be a bit different depending on your PSP version but it's probably similar.

szmol96
May 28, 2015, 06:39 AM
Thanks! I will check it out.

szmol96
Jul 24, 2015, 10:45 AM
What am I doing wrong when I get this error from JSD: "Run-time error '11': Division by zero"?

My animation contains only one frame which is 128x16 pixels large, has the palette loaded and an fps.10 file next to it and it is named 0,-125,-8,0,0,0,0.png.

I hope to have included enough info.

Violet CLM
Jul 24, 2015, 07:31 PM
JSD is not a reliable measure of whether your file was saved correctly. Only JJ2 can tell you that.

szmol96
Jul 25, 2015, 03:13 AM
"Tried to load an invalid animation..."
That's the error I get.

Seren
Aug 3, 2015, 05:38 AM
szmol96's picture triggered the following Python error, resulting in producing an invalid j2a file:
Traceback (most recent call last):
File "j2a-import.py", line 164, in &lt;module&gt;
main()
File "j2a-import.py", line 108, in main
data3 += chr(len(pixelstodraw) + 0x80)
ValueError: chr() arg not in range(256)
It can be reliably reproduced with use of a 128x2 picture filled with any non-0 palette entries.
The error can be walked around by appending columns of index 0 pixels on each side of the picture (presumably one side would suffice but I didn't want to check which one it has to be).

XxMoNsTeRXM
Sep 24, 2015, 06:02 AM
You'll probably still have trouble with plus.j2a, but the other two .j2a files in your folder should work fine. FawFul noticed earlier that plus.j2a was accidentally assembled in a way that JJ2+ accepts but j2a-extract doesn't :(
When extracting it I only get half of the images, but I want to do some edits and I need all of the images from plus.j2a :(

Violet CLM
Sep 27, 2015, 03:53 PM
<a href="http://shemitz.net/static/files/misc/plusj2a.zip">Does this work?</a> I haven't touched this stuff in a while.

XxMoNsTeRXM
Sep 28, 2015, 04:23 AM
<a href="http://shemitz.net/static/files/misc/plusj2a.zip">Does this work?</a> I haven't touched this stuff in a while.

Yes, it does.

InfamousStar
Oct 5, 2015, 04:02 PM
I'm getting this error.


$ python j2a-extract.py
Please type the filename of the .j2a file you wish to extract:
Anims.j2a
Traceback (most recent call last):
File "j2a-extract.py", line 40, in <module>
main()
File "j2a-extract.py", line 9, in main
j2a.read_header()
File "censored/j2a.py", line 54, in read_header
offset = struct.unpack("L", self.j2afile[self._headersize+(i*4):self._headersize+(i*4)+4])[0]
struct.error: unpack requires a string argument of length 8

Seren
Oct 5, 2015, 11:59 PM
I don't know Python, but as far as I can tell, the meaning of that line is implementation-defined, dependent on type size. It should work in almost all popular data models with the main exception of LP64. Are you on 64-bit Linux? Anyway, try modifying line 54 of j2a.py by changing "L" to "I".

InfamousStar
Oct 6, 2015, 06:48 AM
Yeah, I'm on 64-bit Linux. Changing "L" to "l" just switched it from unsigned to signed long, so that didn't work. But you were right about what was going wrong. My solution was to change it to "&lt;L" which locks it to 4-bytes little endian.

Seren
Oct 6, 2015, 07:24 AM
I said "I" as in capital "i", standing for "int", which is 4 bytes in LP64, not "l" as in lowercase "L", but glad you solved it.

InfamousStar
Oct 8, 2015, 05:44 AM
Oh. l hate sans serif fonts sometimes.

XxMoNsTeRXM
Feb 26, 2017, 03:28 AM
I have a problem while trying to draw a sprite from a custom j2a file, a 800x600 png image. I am converting the image from a different palette to the JJ2's Palette. After I convert it and I save it in the specified format (0,-1,-1,0,0,0,0.png), j2a-import.py manages to import it in a .j2a file, but when I try to load from it, it gives me an Access Violation saying that the j2a is corrupt. The error is probably from how it is converted to the jj2 palette. I used GIMP to convert it to the jj2 palette.

Violet CLM
Feb 26, 2017, 08:54 AM
I think the .py would have complained if the image weren't properly paletted. It may be an obscure issue with the image size... could you PM the image to me, maybe?

XxMoNsTeRXM
Feb 26, 2017, 09:02 AM
I think the .py would have complained if the image weren't properly paletted. It may be an obscure issue with the image size... could you PM the image to me, maybe?
The unconverted image or the converted image?

Violet CLM
Feb 26, 2017, 12:48 PM
void onLevelLoad() {
jjAnimSets[ANIM::CUSTOM[0]].load(0, "Camel.j2a");
}
void onDrawLayer8(jjPLAYER@, jjCANVAS@ screen) {
screen.drawSprite(1,1, ANIM::CUSTOM[0], 0, 0);
}
Works fine for me, no errors. Saved as the only file in folder "0" in folder "0" in folder "Camel-j2a".

XxMoNsTeRXM
Feb 27, 2017, 03:42 AM
I am using Linux btw, could that be the problem? I used Python 2.7. Does the python script use a Windows-based function?
Edit: It doesn't look that there's any file path problem.

Violet CLM
Feb 27, 2017, 06:56 AM
There's a windows-vs.-linux discussion a bit farther up this page... that was about the extract script, not the import, but you might have similar success looking for instances of <code>struct.pack</code> in the script and trying to force the size/endianness/whatever to work on your system.

XxMoNsTeRXM
Feb 27, 2017, 07:19 AM
<strike>So if I change every 'l' in struct.pack to 'I', it should probably work, right?
That didn't help.
It might have helped, now I don't get crashed. But the image doesn't show now.
I think I have to change to I some specific struct.pack s
How am I suppose to find out which of them to change?</strike>
Nvm... I figured it out!

Darkhog
Nov 30, 2017, 11:56 AM
Could you try using py2exe so one won't have to have Python to use the tool (py2exe AFAIK embeds Python interpreter and all used libraries in the exe)? Because Python changes much even in the minor versions or it can simply not work on someone's system, as it's case with me. I mean, the interpreter and IDLE runs for me, it's just that it's unable to find even the basic libs. And yes, I have my %PATH% set correctly. I guess Python's compatibility with Win8, at least for the 2.x branch is pretty dodgy.

Never had any issues with scripts that were ran through py2exe so if you'd do that, it should work.

Violet CLM
Dec 2, 2017, 09:02 PM
I just spent an hour or so fiddling with py2exe and cxfreeze, and neither of them produced working executables, and so I've lost interest.

Darkhog
Dec 3, 2017, 12:18 PM
Darn. Feels bad. Maybe someone else will have more luck?