4 ssize_t
ARF_find_code_start(AF
* f
, size_t start
) {
5 if(!AF_set_pos(f
, start
)) return -1;
9 if(AF_read(f
, buf
, 1) != 1) break;;
12 if(*buf
== 'S') match
++;
16 if(*buf
== 'C') match
++;
20 if(*buf
== 'O') match
++;
24 if(*buf
== 'M') return AF_get_pos(f
) - 4;
34 static void roomfile_decrypt_text(char *s
, int len
) {
37 *s
+= "Avis Durgan"[i
% 11];
43 char *RoomFile_extract_source(AF
*f
, struct RoomFile
*r
, size_t *sizep
) {
45 off_t pos
= r
->blockpos
[BLOCKTYPE_SCRIPT
];
46 if(!pos
|| !AF_set_pos(f
, pos
)) return 0;
47 int scriptlen
= AF_read_int(f
);
48 assert(r
->blocklen
[BLOCKTYPE_SCRIPT
] == scriptlen
+ 4);
49 char* out
= malloc(scriptlen
+1);
51 if((size_t) -1 == AF_read(f
, out
, scriptlen
)) {
56 roomfile_decrypt_text(out
, scriptlen
);
62 int RoomFile_read(AF
*f
, struct RoomFile
*r
) {
63 if(!AF_set_pos(f
, 0)) return 0;
64 r
->version
= AF_read_short(f
);
66 unsigned char blocktype
;
67 if((size_t) -1 == AF_read(f
, &blocktype
, 1)) return 0;
68 if(blocktype
== BLOCKTYPE_EOF
) break;
69 if(blocktype
< BLOCKTYPE_MIN
|| blocktype
> BLOCKTYPE_MAX
) return 0;
70 int blocklen
= AF_read_int(f
);
71 off_t curr_pos
= AF_get_pos(f
), next_block
= curr_pos
+ blocklen
;
72 r
->blockpos
[blocktype
] = curr_pos
;
73 r
->blocklen
[blocktype
] = blocklen
;
75 case BLOCKTYPE_COMPSCRIPT3
:
79 assert(!memcmp(sig
, "SCOM", 4));
82 /* the older script types weren't supported by the released AGS sources ever */
86 if(!AF_set_pos(f
, next_block
)) return 0;