|
Loading bitmap from exe (resource file) |
Aleksa
Member #14,874
January 2013
|
I want to load bitmap like resource file but it crashes every time when it comes to this line: ALLEGRO_BITMAP *pozadina = al_load_bitmap(LoadCustomResource(100, hInstance)); I attached files where you can see how LoadCustomResource function works. EDIT: I made it not crash at bitmap loading but now it crashes when i try to draw it
|
SiegeLord
Member #7,827
October 2006
|
Need to use the memfile addon. Something along these lines: HGLOBAL hMemory = LoadResource(hModule, hResource); DWORD dwSize = SizeofResource(hModule, hResource); LPVOID lpAddress = LockResource(hMemory); ALLEGRO_FILE* f = al_open_memfile(lpAddress, dwSize, "r"); // Make sure to specify the right extension here ALLEGRO_BITMAP* bmp = al_load_bitmap_f(f, ".png"); al_destroy_file(f);
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Aleksa
Member #14,874
January 2013
|
Thanks! But that is just too much for my level of programming |
SiegeLord
Member #7,827
October 2006
|
Aleksa said: I will just stick to grabber and .dat file I wonder how you will do that if there's no grabber or .dat files for A5 . "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
beoran
Member #12,636
March 2011
|
Well there are no .dat files anymore in Allegro5 but you can use the physfs add-on to get a similar result. You can then just put your game resources in a zip file. |
LennyLen
Member #5,313
December 2004
|
Using physfs is also cross-platform, unlike using Windows only methods.
|
Aleksa
Member #14,874
January 2013
|
Yea I realized that few minutes after posting that This supposed to be my first A5 project but I think now I am going back to A4 |
beoran
Member #12,636
March 2011
|
Allegro4 .dat files are also easy to open. If you worry about people using your art resources, you'll have to properly encrypt the data. Maybe with this: http://code.google.com/p/openaes/. Then even if the data isn't wrapped, no one is able to use it. However, you could simply rename the .zip file to a .bla file and chance is 80% of the users won't know what to do with it, at least not for a while. <rant> |
Aleksa
Member #14,874
January 2013
|
I think that for this project I will go for a4 and later I will try a5 again. I am not high level programmer so a4 will do the job for me |
Thomas Fjellstrom
Member #476
June 2000
|
Just renaming a zip to .dat is probably enough to stop the users you are woried about the more determined ones will be able to access your data even if you encrypted it, so meh. -- |
Aleksa
Member #14,874
January 2013
|
I will just continue with a4 for now. There is plenty of time for a5 as I am still young enough to learn it |
Neil Roy
Member #2,229
April 2002
|
I renamed the data for my A5 game to .pak and one person who loved my game and played around with it A LOT (he created over 500 levels! ) did not know it was a ZIP file until I told him. I used to be worried about that, like you, but honestly, I just don't see it as much of a problem as I used to anymore, especially when the users you're worried about won't realize how to access it. Allegro 4 .DAT files on the other hand = easy. Just download grabber and presto, you can open it. I have even opened up other people's encrypted Allegro 4 DAT files, and it wasn't much work to do it. A determined person will. Just throw up the usual copyrights and rename it as suggested. Allegro 5 is FAR superior and not that difficult to use once you take some time to get used to it. --- |
m c
Member #5,337
December 2004
|
I forget which, but some game use a zip file but they mess the header up somehow (like a XOR pattern on first 20 bytes or something I don't remember details) and then their game just transparently undid the mess up, but winzip or WinRAR had trouble recognizing the file as a not valid file. Rename the extension is easier. Everyone says who cares about trying hard and I agree. I wonder if any program has done this: Store .zip file as a different extension, possibly split up into 2 files or more as well, with every unsigned byte stored + 47. When the game starts, it reads this file, subtracts 47 from every unsigned byte, and writes the result to a temporary single file with a different extension but is now a valid original zip file. Then it opens that with the normal function. And then deletes it when it closes the file and doesn't need it anymore. I think that take about 1 minute to code. And a command line utility that take the 1st arg as a original file, and write the messed up files into same directory, then it is just drag and drop of new version of your zip file onto that program in windows and you have the new corrupted files for the game to read. Because that sounds a little bit sneaky and also easy in terms of complication I bet someone has done that before for a less than 50 megabyte game anyway. I did something similar for a library that was difficult to use/build, I instead use the pre-compiled binary, and instead of calling library function I wrote data to file, executed the binary (which was inside the program folder) on the file with results to another file, and then read that other file back in, and then deleted everything, and to a normal user they didn't know the difference and it took me like 15 minutes instead of days. (\ /) |
Arthur Kalliokoski
Second in Command
February 2005
|
What's the problem with users accessing the data? Do you think they'll use the assets in their own game? Will they alter them to cheat? If it's not a multiplayer game, what's the harm? BTW, id Software renamed zip files to have a pk4 extension without any extra encryption whatever. They all watch too much MSNBC... they get ideas. |
Aleksa
Member #14,874
January 2013
|
Its not that important that files cant be opened. Its just that from angle of user my program looks more pro if he cant open it (I'm talking about 99% of users, other 1% will open it anyway) |
Thomas Fjellstrom
Member #476
June 2000
|
What are the basics to using zip files? -- |
m c
Member #5,337
December 2004
|
Well, your program source code will have to be changed. (\ /) |
Neil Roy
Member #2,229
April 2002
|
Ummm... zip files are infinitely easier to use! There's nothing really to learn. You code your program to... well, here, it will take less text for me to show you the code than to explain it! It's just that easy... PHYSFS_init(NULL); if(!PHYSFS_mount("MyDataFile.dat", "/", 1)) { // On error, do something here } al_set_physfs_file_interface(); With the above code, you can now load your bitmap files etc... (even from folders inside the zip) normally, the same way you load them straight from your hard drive! Except Allegro 5 grabs them from inside the zip. If you need to access your hard drive, it's a simple one line command to switch back to the hard drive, and then when you need to access the zip again, you use al_set_physfs_file_interface(); again. For example, I needed to check for user made levels in my game folder, so I done the following... // switch to loading from the game folder al_set_standard_file_interface(); // Load user made levels from hard drive here // switch back to the zip file... al_set_physfs_file_interface(); That's it! Nothing to it. I was like you when Allegro 5 came out. Learning it seemed a little daunting, but once I gave it a chance and started to use it, I was really impressed with it. I use 7Zip and while my data file will not open up automatically, so nobody will know it's a zip by accident, all one needs to do, at least with 7zip is select to OPEN it from the 7Zip right click menu and presto, it's open like any other zip, then just drag and drop your files in, organize them as you would normally (no grabber program needed, which is a lot nicer as well). --- |
Aleksa
Member #14,874
January 2013
|
Ok you convinced me to give it another shot |
Gideon Weems
Member #3,925
October 2003
|
Arthur Kalliokoski said: Do you think they'll use the assets in their own game? Is this a legitimate concern? I hear people talk about this possibility, but I've yet to hear of it actually happening. One thing's for sure: It would suck to spend time making original resources, only to have someone render them unoriginal by ripping them off. |
Audric
Member #907
January 2001
|
Is file search case-sensitive in a ZIP archive ? |
Neil Roy
Member #2,229
April 2002
|
Aleksa said: Ok you convinced me to give it another shot Awesome! Stick with it, it's well worth it. And people here are very helpful in that regard. Audric said: Is file search case-sensitive in a ZIP archive ? I think a zip archive is basically the same as filenames on your hard drive. I don't think it is. For my own game though, I came up with some basic naming rules which actually make things easier for me. I have all my file names start with a capital letter, followed by small letters, if they consist of multiple words in the name that the words are separated by an underscore. So something like a background image might be named "Background_Image.png". I also have a rule that all extensions (like "png") are lowercase. I have similar rules for naming my variables, all lower case separated by underscores etc... etc... I found this has really helped me. When programming I can spot an error in a name quickly because I know my rules, I can also remember the name of it and how I saved it on disk easy without looking because of these, so I suggest you come up with some of your own naming rules you're comfortable with and then stick with them. Helps in spotting bugs and makes things look cleaner and more professional. --- |
|