How to load a bitmap stored in custom encrypted archive

● ARCHIVED · READ-ONLY
Started by Tsukihime 6 posts View original ↗
  1. Bitmap.new(path) loads the file and creates a bitmap out of it.


    It knows how to load from the encrypted archive as well.


    If I give it a path to a custom encrypted archive, how could I load that?


    Would I need to write the actual bitmap loading code myself? I can give it a bytestring containing the image file data (png, jpg, tga, bmp, etc.), but it doesn't know how to load raw data.


    Actually this reminds me of the audio loading problem, though not quite the same.
  2. I think you'd need to write your own, I also tried giving it the raw data from an encrypted image file but yeah, it won't load it. It still needs it to be a valid image file.

    Creating the image before loading seems to work though, and you can also even just recreate them all using the same file name so that only the last loaded image will have an actual file.

    so like

    def self.create_temp(filename) content = get_packed(filename) temp = File.open("Data.png","wb") content.each {|x| temp.write(x)} temp.close return "Data.png" end def self.try @spr = Sprite.new @spr.bitmap = Bitmap.new(create_temp("Attack1.data")) @spr.z = 9999 @spr2 = Sprite.new @spr2.y = 300 @spr2.z = 9998 @spr2.bitmap = Bitmap.new(create_temp("Attack2.data")) endhere, create_temp creates an image file from the supplied encrypted file... And every call of it will just overwrite the old file so only 1 file exists. get_packed is a custom method that returns the raw data from the encrypted file.It's not really optimal but at the very least it works and just keeps 1 extracted file instead of having everything extracted and available...

    PS: I think we could call a delete file afterwards to remove the temp file...

    But of course if we can find a not so cumbersome method that removes he need for a temp file, that would be nice.
  3. Given that the Bitmap format is known, we could potentially build the bitmap ourselves.


    Using libraries such as libpng, libjpg, and other libraries we could use them to load the images and then construct the bitmaps.


    We could then even take it further and add support for other image formats.
  4. Yeah we could do that too. My method above is just one for those who don't know how to load the bitmaps manually (like me) XD
  5. Building the bitmap with code is a known bottleneck unless the bitmaps are sufficiently small, or the number creations are sufficiently rare.

    When it actually does become too much requires actual measurements. Doing it for all graphics in a normal game will cause significant slowdowns and lag.

    Assuming it is indeed too slow building the bitmaps in RGSS3 I have the following three suggestions

    1. Created physical files with the decrypted bitmap. PNG compressed might be preferable. (Be vary of potential file permission issues)
    2. Create a bitmap of appropriate size and then send the pointer of the bitmap to custom DLL, which then fills in the bitmap directly.
    3. Leave the bitmaps in their unencrypted form as physical files. No decryption needed, no custom scripting needed, fastest option.
    Remember that for custom encryption the likely attack will be to simply decrypt the standard encrypted archive and then let use your scripts for decrypting the custom encryption.

    *hugs*

     - Zeriab
  6. You could also modify the way the cache loads unchached bitmaps to use the method I posted above, so that once a bitmap is loaded, it still stays in the cache... as far as my tests are concerned, after creation of the bitmap, you can safely delete the temporary image file.