7 #define ADS ":::AGSalphahack " VERSION " by rofl0r:::"
9 static int usage(char *argv0
) {
10 dprintf(2, ADS
"\nusage:\n%s [-s spriteno] DIR\n"
11 "removes alphachannel flag from specified sprite in game file.\n"
12 "if spriteno is -1 (default), all flags are removed.\n"
13 "gamefile is typically ac2game.dta or game28.dta inside DIR.\n"
14 "this is useful when sprites have been hacked/converted to 16bit.\n"
15 "you should make a backup of the file before doing this.\n"
20 #define SPF_ALPHACHANNEL 0x10
22 int main(int argc
, char**argv
) {
23 int c
, flags
= 0, spriteno
= -1;
24 while ((c
= getopt(argc
, argv
, "s:")) != EOF
) switch(c
) {
25 case 's': spriteno
= atoi(optarg
); break;
26 default: return usage(argv
[0]);
28 if(!argv
[optind
]) return usage(argv
[0]);
29 char *dir
= argv
[optind
];
33 if(!ADF_find_datafile(dir
, fnbuf
, sizeof(fnbuf
)))
35 if(!ADF_open(a
, fnbuf
)) return 1;
37 off_t off
= ADF_get_spriteflagsstart(a
);
38 unsigned nsprites
= ADF_get_spritecount(a
);
41 printf("removing alpha of %u out of %u spriteflags.\n", spriteno
==-1?nsprites
:1, nsprites
);
43 FILE *f
= fopen(fnbuf
, "r+b");
45 fseeko(f
, off
, SEEK_SET
);
46 unsigned char *buf
= malloc(nsprites
);
47 fread(buf
, 1, nsprites
, f
);
50 for(i
=0;i
<nsprites
;++i
) {
51 if(spriteno
== -1 || spriteno
== i
)
52 buf
[i
] = buf
[i
] & (~SPF_ALPHACHANNEL
);
54 fseeko(f
, off
, SEEK_SET
);
55 fwrite(buf
, 1, nsprites
, f
);