Ticket #8358: descummlib.diff
File descummlib.diff, 10.5 KB (added by , 19 years ago) |
---|
-
descumm-common.cpp
RCS file: /cvsroot/scummvm/tools/descumm-common.cpp,v retrieving revision 1.13 diff -u -r1.13 descumm-common.cpp
22 22 23 23 #include "descumm.h" 24 24 25 26 25 BlockStack *block_stack; 27 26 int num_block_stack; 28 27 … … 122 121 123 122 if (dontShowOpcode) { 124 123 if (dontShowOffsets) 125 p rintf("%s%s\n", s, buf);124 pt2Print("%s%s\n", s, buf); 126 125 else 127 p rintf("[%.4X] %s%s\n", curoffs, s, buf);126 pt2Print("[%.4X] %s%s\n", curoffs, s, buf); 128 127 } else { 129 128 char buf2[4]; 130 129 if (opcode != -1) … … 132 131 else 133 132 strcpy(buf2, "**"); 134 133 if (dontShowOffsets) 135 p rintf("(%s) %s%s\n", buf2, s, buf);134 pt2Print("(%s) %s%s\n", buf2, s, buf); 136 135 else 137 p rintf("[%.4X] (%s) %s%s\n", curoffs, buf2, s, buf);136 pt2Print("[%.4X] (%s) %s%s\n", curoffs, buf2, s, buf); 138 137 } 139 138 } 140 139 } … … 163 162 block_stack = (BlockStack *) malloc(256 * sizeof(BlockStack)); 164 163 165 164 if (num_block_stack >= 256) { 166 p rintf("block_stack full!\n");165 pt2Print("block_stack full!\n"); 167 166 exit(0); 168 167 } 169 168 return &block_stack[num_block_stack++]; -
descumm-tool.cpp
RCS file: /cvsroot/scummvm/tools/descumm-tool.cpp,v retrieving revision 1.9 diff -u -r1.9 descumm-tool.cpp
22 22 23 23 #include "descumm.h" 24 24 25 26 25 void ShowHelpAndExit() 27 26 { 28 27 printf("SCUMM Script decompiler\n" … … 53 52 exit(0); 54 53 } 55 54 56 int skipVerbHeader_V12(byte *p)57 {58 byte code;59 int offset = 15;60 int minOffset = 255;61 p += offset;62 63 printf("Events:\n");64 65 while ((code = *p++) != 0) {66 offset = *p++;67 printf(" %2X - %.4X\n", code, offset);68 if (minOffset > offset)69 minOffset = offset;70 }71 return minOffset;72 }73 74 int skipVerbHeader_V34(byte *p)75 {76 byte code;77 int offset = GF_UNBLOCKED ? 17 : 19;78 int minOffset = 255;79 p += offset;80 81 printf("Events:\n");82 83 while ((code = *p++) != 0) {84 offset = TO_LE_16(*(uint16 *)p);85 p += 2;86 printf(" %2X - %.4X\n", code, offset);87 if (minOffset > offset)88 minOffset = offset;89 }90 return minOffset;91 }92 93 int skipVerbHeader_V567(byte *p)94 {95 byte code;96 int offset = 8;97 int minOffset = 255;98 p += offset;99 100 printf("Events:\n");101 102 while ((code = *p++) != 0) {103 offset = TO_LE_16(*(uint16 *)p);104 p += 2;105 printf(" %2X - %.4X\n", code, offset);106 if (minOffset > offset)107 minOffset = offset;108 }109 return minOffset;110 }111 112 int skipVerbHeader_V8(byte *p)113 {114 uint32 *ptr;115 uint32 code;116 int offset;117 int minOffset = 255;118 119 ptr = (uint32 *)p;120 while ((code = TO_LE_32(*ptr++)) != 0) {121 offset = TO_LE_32(*ptr++);122 printf(" %2d - %.4X\n", code, offset);123 if (minOffset > offset)124 minOffset = offset;125 }126 return minOffset;127 }128 129 55 int main(int argc, char *argv[]) 130 56 { 131 57 FILE *in; 132 byte *mem , *memorg;58 byte *mem; 133 59 int len; 134 char *filename , *buf;60 char *filename; 135 61 int i; 136 62 char *s; 137 63 … … 150 76 151 77 case '1': 152 78 scriptVersion = 1; 153 g_jump_opcode = 0x18;154 GF_UNBLOCKED = true;155 79 break; 156 80 case '2': 157 81 scriptVersion = 2; 158 g_jump_opcode = 0x18;159 GF_UNBLOCKED = true;160 82 break; 161 83 case '3': 162 84 scriptVersion = 3; 163 g_jump_opcode = 0x18;164 85 break; 165 86 case '4': 166 87 scriptVersion = 4; 167 g_jump_opcode = 0x18;168 88 break; 169 89 case '5': 170 90 scriptVersion = 5; 171 g_jump_opcode = 0x18;172 91 break; 173 92 case 'n': 174 93 IndyFlag = 1; // Indy3 175 94 scriptVersion = 3; 176 g_jump_opcode = 0x18;177 95 break; 178 96 case 'z': 179 97 ZakFlag = 1; // Zak 180 98 scriptVersion = 3; 181 g_jump_opcode = 0x18;182 99 break; 183 100 case 'u': 184 101 GF_UNBLOCKED = true; … … 189 106 // Fall through 190 107 case '6': 191 108 scriptVersion = 6; 192 g_jump_opcode = 0x73;193 109 break; 194 110 case '7': 195 111 scriptVersion = 7; 196 g_jump_opcode = 0x73;197 112 break; 198 113 case '8': 199 114 scriptVersion = 8; 200 g_jump_opcode = 0x66;201 115 break; 202 116 203 117 case '9': 204 118 heVersion = 72; 205 119 scriptVersion = 6; 206 g_jump_opcode = 0x73;207 120 break; 208 121 209 122 case 'o': … … 254 167 return 1; 255 168 } 256 169 257 mem org = mem= (byte *)malloc(65536);170 mem = (byte *)malloc(65536); 258 171 len = fread(mem, 1, 65536, in); 259 172 fclose(in); 260 size_of_code = len;261 262 buf = (char *)malloc(8192);263 264 offs_of_line = 0;265 266 if (GF_UNBLOCKED) {267 if (size_of_code < 4) {268 printf("File too small to be a script\n");269 return 1;270 }271 // Hack to detect verb script: first 4 bytes should be file length272 if (TO_LE_32(*((uint32 *)mem)) == size_of_code) {273 if (scriptVersion <= 2)274 offs_of_line = skipVerbHeader_V12(mem);275 else276 offs_of_line = skipVerbHeader_V34(mem );277 } else {278 mem += 4;279 }280 } else if (scriptVersion >= 5) {281 if (size_of_code < (scriptVersion == 5 ? 8 : 10)) {282 printf("File too small to be a script\n");283 return 1;284 }285 286 switch (TO_BE_32(*((uint32 *)mem))) {287 case 'LSC2':288 printf("Script# %d\n", TO_LE_32(*((int32 *)(mem+8))));289 mem += 12;290 break; /* Local script */291 case 'LSCR':292 if (scriptVersion == 8) {293 printf("Script# %d\n", TO_LE_32(*((int32 *)(mem+8))));294 mem += 12;295 } else if (scriptVersion == 7) {296 printf("Script# %d\n", TO_LE_16(*((int16 *)(mem+8))));297 mem += 10;298 } else {299 printf("Script# %d\n", (byte)mem[8]);300 mem += 9;301 }302 break; /* Local script */303 case 'SCRP':304 mem += 8;305 break; /* Script */306 case 'ENCD':307 mem += 8;308 break; /* Entry code */309 case 'EXCD':310 mem += 8;311 break; /* Exit code */312 case 'VERB':313 if (scriptVersion == 8) {314 mem += 8;315 offs_of_line = skipVerbHeader_V8(mem);316 } else317 offs_of_line = skipVerbHeader_V567(mem);318 break; /* Verb */319 default:320 printf("Unknown script type!\n");321 return 1;322 }323 } else {324 if (size_of_code < 6) {325 printf("File too small to be a script\n");326 return 1;327 }328 switch (TO_LE_16(*((uint16 *)mem + 2))) {329 case MKID('LS'):330 printf("Script# %d\n", (byte)mem[6]);331 mem += 7;332 break; /* Local script */333 case MKID('SC'):334 mem += 6;335 break; /* Script */336 case MKID('EN'):337 mem += 6;338 break; /* Entry code */339 case MKID('EX'):340 mem += 6;341 break; /* Exit code */342 case MKID('OC'):343 offs_of_line = skipVerbHeader_V34(mem);344 break; /* Verb */345 default:346 printf("Unknown script type!\n");347 return 1;348 }349 }350 351 org_pos = mem;352 cur_pos = org_pos + offs_of_line;353 len -= mem - memorg;354 355 while (cur_pos < mem + len) {356 byte opcode = *cur_pos;357 int j = num_block_stack;358 buf[0] = 0;359 switch (scriptVersion) {360 case 1:361 case 2:362 next_line_V12(buf);363 break;364 case 3:365 case 4:366 case 5:367 next_line_V345(buf);368 break;369 case 6:370 if (heVersion)371 next_line_HE_V72(buf);372 else373 next_line_V67(buf);374 break;375 case 7:376 next_line_V67(buf);377 break;378 case 8:379 next_line_V8(buf);380 break;381 }382 if (buf[0]) {383 writePendingElse();384 if (haveElse) {385 haveElse = false;386 j--;387 }388 outputLine(buf, offs_of_line, opcode, j);389 offs_of_line = get_curoffs();390 }391 while (indentBlock(get_curoffs())) {392 outputLine("}", offs_of_line, -1, -1);393 offs_of_line = get_curoffs();394 }395 fflush(stdout);396 }397 398 printf("END\n");399 173 400 /* 401 if (scriptVersion >= 6 && num_stack != 0) { 402 printf("Stack count: %d\n", num_stack); 403 if (num_stack > 0) { 404 printf("Stack contents:\n"); 405 while (num_stack) { 406 buf[0] = 0; 407 se_astext(pop(), buf); 408 printf("%s\n", buf); 409 } 410 } 411 } 412 */ 413 free(memorg); 174 if (descummScript (mem, len, scriptVersion, &printf) != 0) 175 printf ("Error!\n"); 414 176 415 177 return 0; 416 178 } -
descumm.cpp
RCS file: /cvsroot/scummvm/tools/descumm.cpp,v retrieving revision 1.95 diff -u -r1.95 descumm.cpp
527 527 buf = get_var_or_word(buf, i & 0x80); 528 528 j++; 529 529 if (j > 16) { 530 p rintf("ERROR: too many variables in argument list!\n");530 pt2Print("ERROR: too many variables in argument list!\n"); 531 531 if (haltOnError) 532 532 exit(1); 533 533 break; … … 845 845 char *s; 846 846 847 847 if (NumInExprStack <= 0) { 848 p rintf("Expression stack is empty!\n");848 pt2Print("Expression stack is empty!\n"); 849 849 exit(0); 850 850 } 851 851 … … 917 917 break; 918 918 919 919 default: 920 p rintf("Warning, Invalid expression code %.2X\n", i);920 pt2Print("Warning, Invalid expression code %.2X\n", i); 921 921 } 922 922 923 923 } while (1); … … 1371 1371 break; 1372 1372 default: 1373 1373 // strcpy(buf, "Unknown??"); 1374 // p rintf("UGH, unknown room op %d\n", opcode & 0x1F);1374 // pt2Print("UGH, unknown room op %d\n", opcode & 0x1F); 1375 1375 // exit(1); 1376 1376 sprintf(buf, "UnknownRoomCommand%.2X", opcode & 0x1F); 1377 1377 } -
descumm.h
RCS file: /cvsroot/scummvm/tools/descumm.h,v retrieving revision 1.14 diff -u -r1.14 descumm.h
85 85 extern uint size_of_code; 86 86 87 87 // 88 //used output funktion 89 // 90 extern int (*pt2Print)(const char *format, ...); 91 92 // 88 93 // Common 89 94 // 90 95 … … 102 107 extern bool maybeAddBreak(uint cur, uint to); 103 108 extern void writePendingElse(); 104 109 110 extern int descummScript (byte *mem, int len, int scriptVersion, int (*pt2OutFunc)(const char *format, ...)); 111 105 112 // 106 113 // Entry points for the descumming 107 114 // -
descumm6.cpp
RCS file: /cvsroot/scummvm/tools/descumm6.cpp,v retrieving revision 1.183 diff -u -r1.183 descumm6.cpp
961 961 StackEnt *pop() 962 962 { 963 963 if (num_stack == 0) { 964 p rintf("ERROR: No items on stack to pop!\n");964 pt2Print("ERROR: No items on stack to pop!\n"); 965 965 966 966 if (!haltOnError) 967 967 return se_complex("**** INVALID DATA ****");