Author Topic: (Explorations in Danmakufu ph3) "Extracting" images from a dat file.  (Read 4385 times)

Chronojet ⚙ Dragon

  • The Oddity
  • 今コソ輝ケ、我ガ未来、ソノ可能性!!
This afternoon, Kirbio had brought up his plans to "extract" resources from a .dat file, more specifically, the files used in ごれ's Phantasmagoria of Imagine Breaker. Upon asking him, it was revealed that this was to be done through a script in the language of Danmakufu itself.

Special thanks to Kirbio for the support while I was making this script.
This script was developed independently of him, who were also trying to do this very same thing. So um... I'm sorry. This script may differ slightly from their version, if they ever plan to release it.



So how is this to be done? What is contained in the zip:

The actual scripts
Well, this is what we will run.
I used a Stage script, which for the time being will do basically nothing after rendering the files.
The script has been converted into a package script that automatically exits after the entire process is finished.
I also have two additional files, which are the high level shader language files that must be used by the main script.

Render target
The dimensions of the render target will become that of the window, rounded up to the nearest power of 2.
For example, if you had a 640 by 480 window (this is the default) then a render target will have the dimensions 1024 by 512 pixels.

The dat file
Well, of course. Where else would you extract your images from?



A brief explanation before I start...

If my memory is correct, which is likely not the case, it is impossible to save a render target with transparency, as the colours are slightly altered if this is done. Instead, I have opted to save two versions of the image.
1) how the image would look if all pixels in the image were 100% opaque, and
2) an image which shows the luminosity of each pixel, where black is completely transparent, and white is opaque. In other words, this second image will act as an alpha mask that can be re-applied in an external program after it is exported.



How do you find the source images in the .dat file?

To my knowledge, there is no way to show the list of files that are found within a .dat file.
When using GetFilePathList on the folder in which the .dat file is located, only the path to the .dat file itself is returned. How unfortunate.

If you wanted to extract the files in a script, you would have to look within the files of the script itself to determine what the names of the image files are.

Of course, if you are the creator of the .dat file, you would probably already know what the names of the files are.

In my example, I have compiled some of the bullet image files that are found in Touhou 11 -- etama, etama2, etama7a, and etama7b -- all of them are PNG files.



The actual rendering of the file, and exporting it

I am using two HLSL files - one of them removes transparency, and the other converts all colour in the image to pure white.

Before we start, we will create our render target (I named it "canvas for export", since that's what its ultimate purpose is) and allow Danmakufu to index the resources found in our .dat file, using AddArchiveFile.

(EDIT) I noticed that sometimes, the loading of images fails if they aren't properly loaded beforehand. I had edited the script so that the images are loaded with LoadTextureInLoadThread before we start the more important part of the script.

First, I will draw a dummy sprite with no texture loaded. Actually, the texture being loaded is completely irrelevant. The size of the texture will be the width and height of the texture itself. As well, the render priority is anything outside of the range of the playing field's priorities. I simply chose 100 because it was a convenient number to use. If run immediately, it would look like a white square at the very top left of the window.

I will then apply the transparency-removing shader to the object sprite.
I would like to point out that I have passed multiple pieces of information to the shader. One of them being the path to the image we would like to render. It will draw the colour from the image's pixels and draw them onto the blank canvas at full opacity. The other pieces of information are the width and height of the image. I will have to pass this as well, since not all images are the same size. Some are 256x256, others are 512x512, etc.

Running the script now, we can see that our shader has worked. We will then render the texture to our render target using RenderToTextureB1 (object to target), and save the texture with the bounds of the original image, which can be obtained with GetTextureWidth and GetTextureHeight functions. In my script, I have stored these into their own variables since they are referenced multiple times.

Now that we are done with the first render, we can clear the shader, using ObjShader_ResetShader.
Finally, we repeat our process, using the other shader -- indicating the alpha of the pixels using luminosity. As before, we will apply the shader, render to texture, and export the image.

Note that in my script, the file names of the images exported are different. We wouldn't want to overwrite one file with the other, now, would we?



Remember in Drake's rips of EoSD, each ripped image comes with its own alpha mask image? This is exactly the same thing.

You can then load up the exported images into some image editing program like Photoshop or GIMP or Paint.net, and apply alpha masks from there.

Awesome.

And with that, this is the file.

http://www.bulletforge.org/u/miransu-uwabami/p/rendering-images-from-a-dat-file/



So how do you rip sounds?

Well... I guess you could record what's playing from your speakers using Audacity or something, but I'm not sure if there is any quality drop if we use that approach. I'll investigate that at a later date, if someone hasn't beaten me to it before then.



(I'll probably have to edit this post as I make some adjustments, or if someone corrects me on things.)
« Last Edit: January 16, 2015, 12:46:46 AM by Miransu Uwabami »

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: (Explorations in Danmakufu ph3) "Extracting" images from a dat file.
« Reply #1 on: January 15, 2015, 11:01:01 PM »
Kirbio's version is currently in the LOCAA Github, but it has to be manually changed to include specific files from within the archive.

Chronojet ⚙ Dragon

  • The Oddity
  • 今コソ輝ケ、我ガ未来、ソノ可能性!!
Re: (Explorations in Danmakufu ph3) "Extracting" images from a dat file.
« Reply #2 on: January 15, 2015, 11:06:19 PM »
Kirbio's version is currently in the LOCAA Github, but it has to be manually changed to include specific files from within the archive.

I will take a look at it when I get home from university. I haven't seen it before so... yeah.
As I said before, this was developed completely independently, so I'm a bit curious to see what his approach is.
I mean, mine must be changed manually, too, since GetFilePathList doesn't list images from an archive.

kirbio

  • Leader of Team αlternative Σnding
  • Or is it...?
Re: (Explorations in Danmakufu ph3) "Extracting" images from a dat file.
« Reply #3 on: January 16, 2015, 02:37:00 AM »
This afternoon, Kirbio had brought up his plans to "extract" resources from a .dat file, more specifically, the files used in ごれ's Phantasmagoria of Imagine Breaker. Upon asking him, it was revealed that this was to be done through a script in the language of Danmakufu itself.
To be clear,I wasn't gonna using anything from PoIB though,that was just a test tubject if I can come up with DAT Extractor tool which helps developer recover file from .dat in case they lose original file! XD

Chronojet ⚙ Dragon

  • The Oddity
  • 今コソ輝ケ、我ガ未来、ソノ可能性!!
Re: (Explorations in Danmakufu ph3) "Extracting" images from a dat file.
« Reply #4 on: January 16, 2015, 02:50:09 AM »
To be clear,I wasn't gonna using anything from PoIB though,that was just a test tubject if I can come up with DAT Extractor tool which helps developer recover file from .dat in case they lose original file! XD

Oh. I see. XD
I remember ごれ saying that he doesn't want people to use his resources, so I was a bit curious about that... I see what your goal was now! If you want to improve this, go ahead~