[center]For some reason saving a screenshot after using packfile_password[/center]
seems to be causing the saved bmp to formatted in a way that can't be read by
ms paint. Here is some source code
| 1 | #include "allegro.h" |
| 2 | #include "game.h" |
| 3 | |
| 4 | DATAFILE *datafile; |
| 5 | BITMAP *buffer; |
| 6 | BITMAP *bmp; |
| 7 | PALETTE pal; |
| 8 | char buf[256]; |
| 9 | |
| 10 | int main(int argc, char *argv[]) |
| 11 | { |
| 12 | allegro_init(); |
| 13 | install_keyboard(); |
| 14 | set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); |
| 15 | |
| 16 | packfile_password("123456"); |
| 17 | replace_filename(buf, argv[0], "game.dat", sizeof(buf)); |
| 18 | datafile = load_datafile(buf); |
| 19 | buffer = create_bitmap(640, 480); |
| 20 | bmp = create_bitmap(640, 480); |
| 21 | set_pallete(datafile[color].dat); |
| 22 | clear(buffer); |
| 23 | |
| 24 | blit(datafile[bitmap].dat, buffer, 0, 0, 0, 0, 640, 480); |
| 25 | blit(buffer, screen, 0, 0, 0, 0, 640, 480); |
| 26 | |
| 27 | readkey(); |
| 28 | |
| 29 | get_palette(pal); |
| 30 | bmp = create_sub_bitmap(screen, 0, 0, 640, 480); |
| 31 | save_bmp("saved.bmp", bmp, pal); |
| 32 | unload_datafile(datafile); |
| 33 | allegro_exit(); |
| 34 | return 0; |
| 35 | } |
| 36 | END_OF_MAIN() |
Note #2: as explained above, the password is used for all read/write operations on files, including for several functions of the library that operate on files without explicitly using packfiles (e.g. load_bitmap()). The unencrypted mode is mandatory in order for those functions to work. Therefore remember to call packfile_password(NULL) before using them if you previously changed the password. As a rule of thumb, always call packfile_password(NULL) when you are done with operations on packfiles. The only exception to this is custom packfiles created with pack_fopen_vtable().
Thanks Matthew
Ralph