collinsmith / riiablo

Diablo II remade using Java and LibGDX
http://riiablo.com
Apache License 2.0
884 stars 101 forks source link

patch_d2.mpq error reading data\global\sfx\item\gem.wav #9

Closed collinsmith closed 5 years ago

collinsmith commented 5 years ago

patch_d2.mpq version of data\global\sfx\item\gem.wav is failing to load due to bad data. Flags are marked as IMPLODE|EXISTS, but this doesn't seem to be the case (it looks like it's encrypted or compressed still like in d2sfx.mpq). d2exp.mpq also contains data\global\sfx\item\gem.wav, but it's a different sound. Since the sound in d2sfx.mpq sounds the same as patch_d2.mpq, I'm going to manually override it and circumvent d2exp.mpq as a workaround.

I'm not sure if this is an error with the MPQ or an error with my decoder, however my inclination is that this is an error with the MPQ since I've yet to see any other files produce such an error (although other MPQ readers are able to extract it). If any more pop up, I'll have this issue to reference.

[MPQ] Reading data\global\sfx\item\gem.wav...
[MPQInputStream] Populating sector offsets table
[MPQInputStream] sector offsets = [36, 4132, 8032, 11939, 15789, 19373, 22970, 26503, 28401]
[MPQInputStream] Reading sector 1 / 8 IMPLODE|EXISTS
[MPQInputStream] Exploding sector...
CSize=4096
FSize=4096
sector(first 32 bytes)=[52, 49, 46, 46, 82, 7A, 00, 00, 57, 41, 56, 45, 66, 6D, 74, 20, 10, 00, 00, 00, 01, 00, 01, 00, 22, 56, 00, 00, 44, AC, 00, 00]
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Unable to read file: data\global\sfx\item\gem.wav
    at com.riiablo.mpq.MPQInputStream.readBytes(MPQInputStream.java:398)
    at com.riiablo.mpq.MPQ.readBytes(MPQ.java:106)
    at com.riiablo.mpq.MPQ.readBytes(MPQ.java:90)
    at com.riiablo.mpq.MPQFileHandle.readBytes(MPQFileHandle.java:28)
    at gdx.diablo.tester.rempq.REMPQTest.create(REMPQTest.java:68)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Caused by: java.lang.IllegalArgumentException: PK_ERR_BAD_DATA: Invalid LitSize: 82
    at com.riiablo.mpq.util.Exploder.pkexplode(Exploder.java:167)
    at com.riiablo.mpq.MPQInputStream.readBytes(MPQInputStream.java:369)
    ... 6 more

FYI: Output from decoding d2sfx

[MPQ] Reading data\global\sfx\item\gem.wav...
[MPQInputStream] Populating sector offsets table
[MPQInputStream] Decrypting sector offsets table
[MPQInputStream] sector offsets = [36, 4132, 5631, 7128, 8622, 10112, 11600, 13091, 14972]
[MPQInputStream] Reading sector 1 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 2 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 3 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 4 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 5 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 6 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 7 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 4096 bytes
[MPQInputStream] Reading sector 8 / 8 COMPRESSED|ENCRYPTED|FIX_KEY|EXISTS
[MPQInputStream] Decrypting sector...
[MPQInputStream] Decompressing sector...
[MPQInputStream] Decompressed 2698 bytes
collinsmith commented 5 years ago

After a bit more research, this looks like a bug with my pkexplode implementation or the data requires some extra work before being passed to it. I double checked the actual patch_d2.mpq data and my table matches the entry/sectors.

[MPQ] Reading data\global\sfx\item\gem.wav...
[MPQ] entry = com.riiablo.mpq.MPQ$HashTable$Entry@6a79ddf6[key=0x92063ef62aa83903,locale=Neutral / English (American),platform=DEFAULT,blockIndex=130]
[MPQ] block = com.riiablo.mpq.MPQ$BlockTable$Block@3c528972[filePos=0x7e48b2,CSize=28401,FSize=31370,flags=IMPLODE|EXISTS]
collinsmith commented 5 years ago

Resolved issue by checking if compressed sector size is the same as the sector size, in which case the sector isn't compressed at all and is the raw data, so copy it. Tested fix on affected sound file.