How to decode a *.dref file?
I am trying to write a simple script to extract images of *.dref format and It turns out GARbro knows how to deal with it.
With the GUI, I can preview and extract images of *.dref format properly.
If I understand the code correctly, each psb:// location recorded in a *.dref file corresponds to an entry inside a *.dpak archive and meta data such as image offset information are also stored in order to properly overlay the images.
In GARbro, it is done in ArcFormats/Emote/ArcPSB.cs and ArcFormats/Emote/ImageDREF.cs.
However, after looking more into the code, I found something strange.
When PsbOpener.OpenArcFile is called, the program attempts to read entries from a *.dpak file by executing [PsbReader.GetTextures()]. If it fails, then [PsbReader.GetLayers()] and [PsbReader.GetChunks()] until it finally succeeds.
My observation is that when I open a *.dpak file, the first two always fail and only [PsbReader.GetChunks()] retrieves data.
However, the image offset variable (TexEntry.OffsetX and TexEntry.OffsetY) can only be stored using [PsbReader.GetLayers()] not [PsbReader.GetChunks()] and hence the final ArcFile instance has no information about image offsets.
How does GARbro give the right image overlay then? I am so confused. Did I understand the code wrong? Or do I read the wrong part of the code? Is this part of the code even used by the program to do the image overlay? Or the correct code is actually somewhere else?
Any comments and suggestions are appreciated.
[PsbReader.GetTextures()]: PsbReader.GetLayers()](/morkt/GARbro/blob/master/ArcFormats/Emote/ArcPSB.cs#L244 [PsbReader.GetLayers()]: /morkt/GARbro/blob/master/ArcFormats/Emote/ArcPSB.cs#L214 [PsbReader.GetChunks()]: /morkt/GARbro/blob/master/ArcFormats/Emote/ArcPSB.cs#L267