Pathoschild / StardewXnbHack

A simple one-way XNB unpacker for Stardew Valley.
MIT License
135 stars 11 forks source link

[Linux] Some unpacked PNGs are corrupted #9

Closed Laulajatar closed 3 years ago

Laulajatar commented 3 years ago

I just tried using this to unpack game files on Manjaro Linux, using StardewXnbHack 1.0.3. It looks successful, but some of the PNGs can't be opened, especially larger ones. For example, all furniture tilesheets are corrupt, all Cursors except for Cursors.ru-RU.png, all JunimoNotes, also all *_island_tilesheet_1.

Loading game instance...
Please use SDL 2.0.5 or higher.
NoFpsCap: This feature is not available
setGameMode( 'titleScreenGameMode (0)' )
loadPreferences(); begin - languageCode=en
savePreferences(); async=False, languageCode=en
loadPreferences(); begin - languageCode=en
savePreferences(); async=False, languageCode=en
Window_ClientSizeChanged(); Window.ClientBounds={X:560 Y:300 Width:1280 Height:720}

Unpacking files...
Effects/BloomCombine.xnb => Effect isn't a supported asset type.                
Effects/BloomExtract.xnb => Effect isn't a supported asset type.                
Effects/BrightWhite.xnb => Effect isn't a supported asset type.                 
Effects/GaussianBlur.xnb => Effect isn't a supported asset type.                
Effects/ShadowRemove.xnb => Effect isn't a supported asset type.                

Done! Unpacked 3277 files in 1 minute 28 seconds.
Unpacked into /home/laula/Games/stardew-valley/game/Content (unpacked).

Press any key to exit.

Tried opening the files in Krita, qview and gpicview but they seem broken. [SMAPI] SMAPI 3.8.0 with Stardew Valley 1.5.0 on Unix 5.8.18.1

Pathoschild commented 3 years ago

Hi! I can reproduce that on Linux:

But Windows can preview and open that exact file (copied from Linux) just fine:

I'm not very familiar with Linux, but the image file created by Mono's Texture2D.SaveAsPng method might be slightly invalid in a way that Linux can't handle but Windows can?

gwenynnefydd commented 3 years ago

It's also replicate-able on my Ubuntu system, however the file CAN be opened via Glimpse/GIMP image editor. PNGCheck at least marks Cursors.jpg as a valid file. Got an interesting error when recompressing the file with OptiPNG though:

When running optipng Cursors.png:

** Processing: Cursors.png
Warning: Not enough image data
704x2256 pixels, 4x8 bits/pixel, RGB+alpha
Recoverable errors found in input. Rerun OptiPNG with -fix enabled.
Error: Previous error(s) not fixed

** Status report
1 file(s) have been processed.
1 error(s) have been encountered.

When running optipng Cursors.png -fix:


** Processing: Cursors.png
Warning: Not enough image data
704x2256 pixels, 4x8 bits/pixel, RGB+alpha
Recoverable errors found in input. Fixing...
Input IDAT size = 491520 bytes
Input file size = 491573 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 333154

Selecting parameters:
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 333154

Output IDAT size = 333154 bytes (158366 bytes decrease)
Output file size = 333211 bytes (158362 bytes = 32.22% decrease)

** Status report
1 file(s) have been processed.
1 error(s) have been encountered.
1 erroneous file(s) have been fixed.

The file produced by optipng Cursors.png -fix can be opened as expected.

So it may be an error with how the file is being built/compressed in Linux?

There's a similar error here that indicates the issue may be with the adler-32 value, which would cause issues with zlib compression: https://stackoverflow.com/questions/36070759/a-palette-base-png-with-idat-that-has-btype-00-for-no-compression-now-with-adle

Laulajatar commented 3 years ago

Unfortunately I don't have much knowledge about Linux myself, I just play games and try not to break too much.

In GIMP, I noticed that the images open, but they have all the same error:

The last line repeats a previous line of pixels. When run through optipng *.png -fix, this line is instead empty. Since I can open the russian cursors, which isn't broken, I can see how it should look like.

Image

Top image is Russian one, which is correct. Middle image is broken one opened in GIMP, which repeats pixels from a previous line. Bottom one is broken one, run through optipng.

I tried opening the corrupted images in my Windows 7 VM. The windows image preview and paint are able to open it, but are also missing the bottom line of the image. My (very old) Photoshop version isn't able to open it.

Looks to me like the image is just literally missing data, and some programs just show what's there, while others refuse to try.

Pathoschild commented 3 years ago

A MacOS user on Discord reported the same problem. They were able to open a file exported on Windows fine, so it does seem like an issue with the export itself through Mono.

These files were affected for them:

Laulajatar commented 3 years ago

These files are affected for me, which is mostly the same ones:

I dug out some old version of XNB node now and extracted the ones I needed in a Windows 7 VM.

Pathoschild commented 3 years ago

This seems to be the MonoGame bug discussed here and fixed in MonoGame 3.8, which is newer than the version used by the game. The workaround is to use a separate library like StbImageWriteSharp for saving images (on Linux/MacOS only).

feanne commented 3 years ago

Hello! Just reporting that I'm experiencing the same issue on MacOS. I haven't checked all the PNGs, but these are the ones I noticed were corrupted for me:

Pathoschild commented 3 years ago

Fixed in StardewXnbHack 1.0.5 with the migration to MonoGame 3.8 and .NET 5. Thanks for reporting it!