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;
37 BLOCKTYPE_COMPSCRIPT
= 3,
38 BLOCKTYPE_COMPSCRIPT2
= 4,
39 BLOCKTYPE_OBJECTNAMES
= 5,
40 BLOCKTYPE_ANIMBKGRND
= 6,
41 BLOCKTYPE_COMPSCRIPT3
= 7, /* only bytecode script type supported by released engine code */
42 BLOCKTYPE_PROPERTIES
= 8,
43 BLOCKTYPE_OBJECTSCRIPTNAMES
= 9,
47 static void roomfile_decrypt_text(char *s
, int len
) {
50 *s
+= "Avis Durgan"[i
% 11];
57 int RoomFile_read(AF
*f
, struct RoomFile
*r
, int flags
) {
58 if(!AF_set_pos(f
, 0)) return 0;
59 r
->version
= AF_read_short(f
);
61 unsigned char blocktype
;
62 if((size_t) -1 == AF_read(f
, &blocktype
, 1)) return 0;
63 if(blocktype
== BLOCKTYPE_EOF
) break;
64 int blocklen
= AF_read_int(f
);
65 off_t curr_pos
= AF_get_pos(f
), next_block
= curr_pos
+ blocklen
;
67 case BLOCKTYPE_SCRIPT
:
68 if(flags
& RF_FLAGS_EXTRACT_CODE
) {
69 int scriptlen
= AF_read_int(f
);
70 r
->sourcecode
= malloc(scriptlen
+1);
71 if((size_t) -1 == AF_read(f
, r
->sourcecode
, scriptlen
)) return 0;
72 roomfile_decrypt_text(r
->sourcecode
, scriptlen
);
73 r
->sourcecode
[scriptlen
] = 0;
74 r
->sourcecode_len
= scriptlen
;
77 case BLOCKTYPE_COMPSCRIPT3
:
81 assert(!memcmp(sig
, "SCOM", 4));
82 r
->scriptpos
= curr_pos
;
85 /* the older script types weren't supported by the released AGS sources ever */
89 if(!AF_set_pos(f
, next_block
)) return 0;