Garhoogin / NitroPaint

General Purpose DS Sprite, BG, and Texture Editor
BSD 2-Clause "Simplified" License
58 stars 5 forks source link

Broken NSBTX Recompression #10

Closed Natsu235 closed 11 months ago

Natsu235 commented 11 months ago

Hi,

I just wanted to point out that saving a NSBTX file doesn't seems to work properly. I've tried several times to replace existing textures from a game (Pokémon Black & White) but it has always resulted with sprites corruption. Even if I don't replace anything in the file (by only loading and saving it in NitroPaint), it does the same.

Here is an overview of the issue:

Pokemon - Version Blanche (France) (NDSi Enhanced)__21137

Garhoogin commented 11 months ago

Hey,

This does seem like a strange issue indeed. Does NitroPaint view the NSBTX after reopening after saving, or does this only happen in-game? Also, could you name the NSBTX file so that I can try to reproduce the problem on my end? Thank you for finding the program useful though.

Natsu235 commented 11 months ago

Thank you for your reply,

To answer your question, it does load fine in NitroPaint after saving but not in-game which is why I'm confused. The NSBTX file I'm using is actually from a NSBMD file which combine NSBMD + NSBTX. I'm using MKDS Course Modifier first to separate both files and edit the NSBTX one in NitroPaint. Then, I simply do the opposite to put it back into the game.

The file I'm currently trying to edit is inside the a/1/7/0 NARC file. If you open it with Tinke, it should be named something like "0_025.bmd". I can send you the file if you can't find it though.

Garhoogin commented 11 months ago

Ah, interesting then. I have a guess in my mind that the issue is possibly related to palettes when the NSBTX is read. When you saved the NSBTX, did its file size decrease any?

Also, NitroPaint can open an NSBMD containing textures in the same way that it can open an NSBTX, just for the convenience.

Natsu235 commented 11 months ago

I don't know if it really matters, but the file size has only decreased by a few bytes. I've uploaded the untouched file if you want to see for yourself: https://www.mediafire.com/file/vt5c0quorkfejpo/0_025.nsbtx

Garhoogin commented 11 months ago

Ah I see then, it does seem to reduce the file size a little. It appears that it cuts out some of the padding between 4-color palettes in the file. I'll have to look further into why it would result in a corruption like this, but my guess is that TEXPLTT_BASE is not being set correctly somehow. Do all the textures in this NSBTX show up incorrectly in-game? Or is it just some?

Natsu235 commented 11 months ago

At first I thought it was all the textures that were corrupted, but after looking at the image I showed in my first post, the blue/pink background seems to be correct although it is in the same file. This might make sense, since the blue/pink background is the first texture in this file.

Garhoogin commented 11 months ago

Being the first texture and first palette, I'd sure hope those came out correctly :P

Palette4 textures continue to be the bane of my existence, and I'm suspecting that that's the culprit. Since TEXPLTT_BASE is interpreted slightly differently. NitroPaint only puts padding afte a palette4 palette if the current palette position isn't a multiple of 16 bytes, but the file you sent puts padding after every single palette regardless of its alignment. In theory I think that is unnecessary, but I'll have to look more into that.

Natsu235 commented 11 months ago

I hope you'll be able to solve this problem. I know Pokémon games seem to like to do things differently from others, which could be really annoying sometimes...

Also, I really like that NitroPaint doesn't change the palettes color order when editing NSBTX file, it's something I've been looking for a while.

Garhoogin commented 11 months ago

With my latest commit, the alignment of palettes around consecutive palette4 palettes should be fixed. This fix will be included in the next release. Thank for the heads-up on this!

Will mark as closed for now, but if you have any problems with it in the future, feel free to reopen.