I'm currently working on a video game project in C++ using Allegro 5 as my graphics library. I store my graphic and font assets in subfolders within the root folder of the .exe. To use them in the program, I have an initGraphics() function that loads all the required assets through al_load_bitmap(), and then later free up the memory with al_destroy_bitmap(). This means however that when I eventually distribute my game, it'll be super easy for anyone to go into the install folder and just edit the graphics to be whatever, and I'm having trouble finding any kind of help regarding how to prevent this. What I was thinking maybe is some kind of program that I'd run on my own computer before distribution that loads the appropriate graphical assets, and somehow converts them into a .txt file, then changing the main game executable's 'initGraphics()' function to load and use those instead of just the raw .png files, but I'm not sure if this is possible. Any information about this type of conversion would be hugely appreciated, or alternatively a more reliable tested method that achieves the same effect. Thank you very much in advance!
Asked
Active
Viewed 234 times
0
-
You can change the extensions of your files to *.txt and check for ex. _DEBUG macro. So if it set read from files with *.png, else from *.txt. However I would recommend some kind of zip library, then put your assets to archive and protect with password. – user2475983 Aug 04 '15 at 09:44
-
Thanks for the idea. I'm getting an assertion failure though on trying to load the file if I change it to .txt. Is there some extra step I need to take to make this possible? – CaptainTid Aug 05 '15 at 04:40
-
If you've changed the extension only, I belive it should make any difference if you changed your code also. However make sure you changed the extension for sure, not just the name (visible file extensions setting in windows). You can also post your error, I'll think about it in free time. – user2475983 Aug 05 '15 at 06:07
-
I've just checked the documentation of al_load_bitmap() and it states `Loads an image file into an ALLEGRO_BITMAP. The file type is determined by the extension.`. It may cause your assertion_error. Check if you can force the extension during function call or just code the extension somehow and replace during app runtime. – user2475983 Aug 05 '15 at 07:32
1 Answers
0
While researching the internet I've found interesting solution:
Allegro5 uses PhysicsFS library to handle file archives. It does not support password protected archives, but you can calculate md5 for your assets archive and hardcode it into your program and then compare it on runtime (source - see more here).
See this part of documentation of Allegro5.
Example explanation of md5 implementation is here

Community
- 1
- 1

user2475983
- 1,916
- 2
- 13
- 20