Vankwysha
Squire
Australia
43 Posts |
Posted - May 04 2005 : 06:53:51 AM
|
hey again,
i'm using vb.net, directdraw and directx9 still, and i'm wondering if there is any way to keep a bitmap in memory before you load it as a sprite to go on a backbuffer. The subprogram to load the sprite takes a filename as an argument, but i do not wish to load my bitmaps from file. I am using an encrypted image format that i designed to stop users tampering with the game images, and as such my game has to decrypt the images on start-up. I was considering making temporary image files while the game was running, but i think that this would be tacky and slow.
is there any way for me to save my decrypted bitmaps in a class or variable and then load them as sprites?
thanks in advance. |
|
Lachlan87
Moderator
USA
160 Posts |
Posted - May 04 2005 : 08:29:32 AM
|
The new surface will accept a system.IO.Stream object, or a System.Drawing.Bitmap object instead of a file name. You should be able to load your bitmaps into either of these before you use them as a surface.
Lachlan
|
|
|
Vankwysha
Squire
Australia
43 Posts |
Posted - May 05 2005 : 04:55:30 AM
|
I can understand that, but I'm still presented with the problem of loading my graphics into the System.Drawing.Bitmap object. As it is, the bitmaps are decompressed when the program runs and the decompressed bitmaps are left in the form of a structure. How do I set the System.Drawing.Bitmap to equal my structure?
Also, if I use the System.IO.Stream object, how do I load the structure into that? As far as I can see they only use of a stream object is for reading and writing from files, not for holding values. |
Edited by - Vankwysha on May 05 2005 05:02:48 AM |
|
|
2dcoder
Knave
83 Posts |
Posted - May 05 2005 : 05:40:11 AM
|
"I am using an encrypted image format that i designed to stop users tampering with the game images.."
A total waste of your time and resources. Who cares if some freeware coders rip your graphics off, it's not like they can make any money from it. Seriously, research this subject and you'll find it's a total waste of brain power. |
|
|
Vankwysha
Squire
Australia
43 Posts |
Posted - May 05 2005 : 06:09:01 AM
|
quote: A total waste of your time and resources. Who cares if some freeware coders rip your graphics off, it's not like they can make any money from it. Seriously, research this subject and you'll find it's a total waste of brain power.
I disagree. While it may be easier to just store the images as bitmaps in an image folder somewhere, I think that this looks really sloppy as a finished product. Besides, the purpose of the encryption is not to stop people stealing my graphics (the game will be freeware anyway), but to stop people ruining or modding the game. |
|
|
2dcoder
Knave
83 Posts |
Posted - May 05 2005 : 08:32:41 AM
|
"but to stop people ruining or modding the game..." Wha?? Let me get this straight, you want to stop people interested in your game not to be able to further get into the project by "modding" your app? I'd LOVE for people to be that interested in my projects. I think you're worrying about this too much.
"I was considering making temporary image files while the game was running, but i think that this would be tacky and slow."
If you're already encrypting them, just pack them all together in one file, write them all out at runtime and erase them when the game is over. Lots of coders do this, no big deal. Im not using .net but if it supports embedded resource files like previous versions of VB does, why not place everything in a resource file and read/write the files out at run time. (And erase them again at program exit.)
"I think that this looks really sloppy as a finished product."
To WHO???? Do you REALLY think the end user cares? The average joe playing the game just wants to check out your game, not your file structure! If your game is any good, critics are not going to care about your file/folder structure. jeesh....
|
|
|
Vankwysha
Squire
Australia
43 Posts |
Posted - May 05 2005 : 4:23:24 PM
|
Believe me, I have thought about that option a lot. As far as I can see, unpacking them at runtime is the best option. However, what if the game crashes? Or if the user's computer has a blackout or something? Then the program wouldn't have a chance to erase the files and the user would be stuck with a bunch of images just left in the folder that shouldn't be there. This game isn't just a game, it's my project for the HSC SDD course. I want it to be efficient and error free as possible, and having left over images in the folder isn't going to help me.
Also, what the heck is an embedded resource file anyway? Is that just an encrypted file that stores all the images or what?
|
Edited by - Vankwysha on May 05 2005 4:26:28 PM |
|
|
2dcoder
Knave
83 Posts |
Posted - May 05 2005 : 5:38:44 PM
|
"However, what if the game crashes? Or if the user's computer has a blackout or something?"
Or there's a tornado, an earthquake, etc? :)
Seriously, unless your app is prone to crashing all the time this shouldn't even be an issue. Just erase the files when the program exits and don't worry about it.
"Also, what the heck is an embedded resource file anyway?"
Just a resource file embedded into the exe. Via the resource editor. VB6 allows this, I assume .Net does as well? |
|
|
Vankwysha
Squire
Australia
43 Posts |
Posted - May 05 2005 : 6:29:29 PM
|
Look, this isn't even the point, I just want to know how to load an image into memory at runtime, ok? This is just something I want to learn to do for future reference. The point isn't why I'm using my encrypted format, it's how the heck I use it at all. |
|
|
2dcoder
Knave
83 Posts |
Posted - May 05 2005 : 9:59:03 PM
|
uh... "I am using an encrypted image format that i designed to stop users tampering with the game images.."
I thought that was why you coded this in the first place? Hence my thoughts on the the subject of wasting your brain resources on trying to keep users from looking/modifying your graphics. Whatever... nevermind. ;)
Oh, and you'll have device restore/texture cache problems if you think textures can live in memory only and not have the original texture available on the hard drive. Research the subject and you'll find plenty of pros and cons on the subject, enough to possibly change your thinking. |
|
|
Crysstaafur
Squire
USA
37 Posts |
Posted - May 06 2005 : 01:00:14 AM
|
Rather than re-inventing the wheel, you are welcome to use some of the encryption and resource management classes in Dabooda Turbo. Since these dont' rely on .render, you can use whatever display method you want. The odd thing about doing this will make your program a hybrid DX8/DX9 app instead of a pure DX9 app. Also have you thought about using some bit operators against a mask only you know as an alternate form of encryption? Also something simple to try is to rename the file extension of your gfx to something that is not likely to be found in hkey.classes.root (file associations) in the registry.. then rename then as you load them in.. then rename them back before unloading/deleting them(depending on how you are handling them in the first place..) hope this helps... :) |
|
|
Vankwysha
Squire
Australia
43 Posts |
Posted - May 06 2005 : 03:42:20 AM
|
That... didn't exactly make a lot of sense. I'm just interested in any way in which to load a bitmap into a structure/variable/whatever and then load it as the sprite. I'm aware that there are other ways to accomplish the same thing, but this way has taken my interest and I want to see it through to fruition. |
|
|
Crysstaafur
Squire
USA
37 Posts |
Posted - May 06 2005 : 06:21:37 AM
|
Assume Byte type for the following: (8-bit):Make an array that has a size = (width * height)+2, Load into it the bytes that reflect the bitmap pattern itself, Make a separate array that has a size = 3*ofcolorsusedinpalette.(256 is standard) You will need to offset each element entry by an increment of 1 inside of a loop. i.e.
dim cpalette(3) colorsused = 128 redim cpalette(3*colorsused) pal = 1 count = 1 paloff = xxxx Do until pal = done bytepos = count get #1,bytepos+paloff,r get #1,bytepos+paloff+1,g get #1,bytepos+paloff+2,b cpalette(count) = r cpalette(count+1) = g cpalette(count+2) = b count = count + 3 if count = 128 then pal = 0 loop
To stash the pattern data itself is actually much simpler than the palette...(hint:no offsets, 1 stash element) Also please understand I didn't take into consideration of the header size in the 8-bit bitmap format. Also most 8-bit bitmap files are run-length compressed, I don't remember if the palette is compressed, but I know for certain that the pattern data definately is... Additonally the above code is probably quite slow. There are ways of speeding it up I am sure. (Pointers to the address of the array come to mind, particularly if they are used in conjunction with the virtual address of the surface you are wanting to write to.. downside would be that you'd have to lock and unlock the surface for each bitmap loaded in.. unless something changed in dx9.. not sure there.. never done any managed code.. just modular and recently semi-oo..)
http://www.wotsit.org This site has a ton of information of various file formats to the byte. This may prove useful in being able to caculate ahead of time the header length/offset, palette length/offset, and some insight into how the pattern data is compressed. Additionally, you may even be able to take advantage of the header information to get arrays and variables setup ahead of time before going to a loop, to shorten/unroll the loop slightly..
As far as getting a pointer address for hwnd, a surface, or even an array.. best of luck.. I have no clue in VB, only in others atm.. I hope this also helps a bit... |
|
|
2dcoder
Knave
83 Posts |
Posted - May 06 2005 : 08:25:21 AM
|
jeesh.... sometimes we code to impress ourselves more than the user playing our game. :) I've also used the extension renaming. It works and is usually enough to keep people from looking at your graphics from Explorer. |
|
|
Vankwysha
Squire
Australia
43 Posts |
Posted - May 06 2005 : 6:24:21 PM
|
Yeah, I'm starting to look that way too. However, I have managed to create my decryption function that should load the bitmap into a temporary varirable. However, I get a System.OutOfMemory exception. I can't understand why, the image is only about 10 KB. |
|
|
2dcoder
Knave
83 Posts |
Posted - May 06 2005 : 11:30:50 PM
|
"However, I have managed to create my decryption function ..." "However, I get a System.OutOfMemory exception..."
Doesn't look like you have it working yet. ;) Is your game already done by the way? Usually this kind of stuff is coded after the game is done. Going to give us a peek? :) |
|
|