1 /* ScummVM Tools 2 * 3 * ScummVM Tools is the legal property of its developers, whose 4 * names are too numerous to list here. Please refer to the 5 * COPYRIGHT file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 /* GobEngine Script disassembler */ 23 24 #ifndef DEGOB_SCRIPT_H 25 #define DEGOB_SCRIPT_H 26 27 #include <string> 28 #include <list> 29 30 #include "common/scummsys.h" 31 32 #define _OPCODET(ver, x) TYPE_TEXTDESC, 0, #x 33 #define _OPCODEF(ver, x) TYPE_FUNCDESC, &ver::x, #x 34 #define _OPCODEB(ver, x) TYPE_BOTHDESC, &ver::x, #x 35 36 class ExtTable { 37 public: 38 ExtTable(byte *data, uint32 size, byte *dataCom = 0, uint32 sizeCom = 0); 39 ~ExtTable(); 40 41 byte *getItem(uint16 i, uint32 &size) const; 42 43 private: 44 struct Item { 45 int32 offset; 46 uint32 size; 47 uint32 width; 48 uint32 height; 49 bool isPacked; 50 }; 51 52 byte *_data; 53 uint32 _size; 54 byte *_dataCom; 55 uint32 _sizeCom; 56 57 uint16 _itemsCount; 58 Item *_items; 59 60 void init(); 61 byte *unpack(const byte *packedData, uint32 &size) const; 62 }; 63 64 class Script { 65 public: 66 Script(byte *totData, uint32 totSize, ExtTable *extTable = 0); 67 virtual ~Script(); 68 69 uint32 getPos() const; 70 void skip(uint32 off); 71 void seek(uint32 off, int whence = SEEK_SET); 72 73 // Properties getter 74 uint16 getStart() const; 75 uint16 getTextCenter() const; 76 uint16 getVarsCount() const; 77 uint32 getTotTextCount() const; 78 uint32 getTotResOffset() const; 79 uint16 getTotResCount() const; 80 uint16 getAnimDataSize() const; 81 uint8 getVerScript() const; 82 uint8 getVerIMEX() const; 83 uint8 getSuffixIM() const; 84 uint8 getSuffixEX() const; 85 86 void deGob(int32 offset = -1); 87 88 protected: 89 enum FuncType { 90 TYPE_NONE = 0, // No description 91 TYPE_TEXTDESC, // Description by a string 92 TYPE_FUNCDESC, // Description by a function 93 TYPE_BOTHDESC // Description by both 94 }; 95 enum Param { 96 PARAM_NONE = 0, // No parameters / Last parameter 97 PARAM_UINT8, // Immediate uint8 98 PARAM_UINT16, // Immediate uint16 99 PARAM_UINT32, // Immediate uint32 100 PARAM_INT8, // Immediate int8 101 PARAM_INT16, // Immediate int16 102 PARAM_INT32, // Immediate int32 103 PARAM_STR, // Immediate string 104 PARAM_EXPR, // Expression 105 PARAM_VARINDEX, // Variable index 106 PARAM_GOB // Special GobFunc params 107 }; 108 struct FuncParams { 109 const char *desc; 110 byte cmdCount; 111 byte counter; 112 int16 retFlag; 113 int16 extraData; 114 int16 objIndex; 115 }; 116 117 uint32 _indent; 118 119 virtual void setupOpcodes() = 0; 120 virtual void drawOpcode(byte i, FuncParams ¶ms) = 0; 121 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms) = 0; 122 virtual void goblinOpcode(int i, FuncParams ¶ms) = 0; 123 124 // Helper function for printing 125 void putString(const char *s) const; 126 void print(const char *s, ...) const; 127 void printIndent() const; 128 void printLine(const char *s) const; 129 std::string printStr(const char *s, ...) const; 130 131 void incIndent(); 132 void decIndent(); 133 134 uint8 readUint8(); 135 uint16 readUint16(); 136 uint32 readUint32(); 137 const char *readString(); 138 139 uint8 peekUint8() const; 140 uint16 peekUint16() const; 141 uint32 peekUint32() const; 142 const char *peekString() const; 143 144 void skipExpr(char stopToken = 99); 145 std::string readExpr(char stopToken = 99); 146 std::string readVarIndex(uint16 *arg_0 = 0, uint16 *arg_4 = 0); 147 148 uint16 getBlockSize() const; 149 150 void evaluateParams(const Param *params); 151 void printFuncDesc(const FuncParams &fParams, const Param *params); 152 void printFuncDesc(const FuncParams &fParams) const; 153 154 void startFunc(const FuncParams &fParams) const; 155 void endFunc() const; 156 157 void loadProperties(byte *data); 158 159 void funcBlock(int16 retFlag); 160 161 void addStartingOffsets(); 162 163 void addFuncOffset(uint32 offset); 164 void deGobFunction(); 165 166 private: 167 byte *_totData, *_ptr; 168 uint32 _totSize; 169 170 protected: 171 ExtTable *_extTable; 172 173 std::list<uint32> _funcOffsets; 174 175 // Script properties 176 uint16 _start, _textCenter; 177 uint16 _varsCount; 178 uint32 _totTextCount; 179 uint32 _totResOffset; 180 uint16 _totResCount; 181 uint16 _animDataSize; 182 uint8 _verScript, _verIMEX; 183 // If > 0, script loads stuff out of commun.exN and commun.imN, where N is this suffix 184 uint8 _suffixIM, _suffixEX; 185 }; 186 187 class Script_v1 : public Script { 188 public: 189 Script_v1(byte *totData, uint32 totSize, ExtTable *extTable = 0); 190 virtual ~Script_v1(); 191 192 protected: 193 typedef void (Script_v1::*OpcodeDrawProcV1)(FuncParams &); 194 typedef void (Script_v1::*OpcodeFuncProcV1)(FuncParams &); 195 typedef void (Script_v1::*OpcodeGoblinProcV1)(FuncParams &); 196 struct OpcodeDrawEntryV1 { 197 FuncType type; 198 OpcodeDrawProcV1 proc; 199 const char *desc; 200 const Param params[16]; 201 }; 202 struct OpcodeFuncEntryV1 { 203 FuncType type; 204 OpcodeFuncProcV1 proc; 205 const char *desc; 206 const Param params[16]; 207 }; 208 struct OpcodeGoblinEntryV1 { 209 FuncType type; 210 OpcodeGoblinProcV1 proc; 211 const char *desc; 212 const Param params[16]; 213 }; 214 const OpcodeDrawEntryV1 *_opcodesDrawV1; 215 const OpcodeFuncEntryV1 *_opcodesFuncV1; 216 const OpcodeGoblinEntryV1 *_opcodesGoblinV1; 217 static const int _goblinFuncLookUp[][2]; 218 219 virtual void setupOpcodes(); 220 virtual void drawOpcode(byte i, FuncParams ¶ms); 221 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 222 virtual void goblinOpcode(int i, FuncParams ¶ms); 223 224 // Extended opcode functions 225 void o1_drawOperations(FuncParams ¶ms); 226 void o1_goblinFunc(FuncParams ¶ms); 227 228 // Control functions 229 void o1_callSub(FuncParams ¶ms); 230 void o1_switch(FuncParams ¶ms); 231 void o1_repeatUntil(FuncParams ¶ms); 232 void o1_whileDo(FuncParams ¶ms); 233 void o1_if(FuncParams ¶ms); 234 void o1_return(FuncParams ¶ms); 235 void o1_returnTo(FuncParams ¶ms); 236 void o1_setcmdCount(FuncParams ¶ms); 237 void o1_assign(FuncParams ¶ms); 238 239 void o1_palLoad(FuncParams ¶ms); 240 void o1_loadSpriteToPos(FuncParams ¶ms); 241 void o1_printText(FuncParams ¶ms); 242 void o1_loadTot(FuncParams ¶ms); 243 void o1_loadSound(FuncParams ¶ms); 244 245 void o1_loadMult(FuncParams ¶ms); 246 void o1_loadAnim(FuncParams ¶ms); 247 void o1_loadStatic(FuncParams ¶ms); 248 void o1_loadMultObject(FuncParams ¶ms); 249 250 void o1_dummy(FuncParams ¶ms); 251 }; 252 253 class Script_v2 : public Script_v1 { 254 public: 255 Script_v2(byte *totData, uint32 totSize, ExtTable *extTable = 0); 256 virtual ~Script_v2(); 257 258 protected: 259 typedef void (Script_v2::*OpcodeDrawProcV2)(FuncParams &); 260 typedef void (Script_v2::*OpcodeFuncProcV2)(FuncParams &); 261 typedef void (Script_v2::*OpcodeGoblinProcV2)(FuncParams &); 262 struct OpcodeDrawEntryV2 { 263 FuncType type; 264 OpcodeDrawProcV2 proc; 265 const char *desc; 266 const Param params[16]; 267 }; 268 struct OpcodeFuncEntryV2 { 269 FuncType type; 270 OpcodeFuncProcV2 proc; 271 const char *desc; 272 const Param params[16]; 273 }; 274 struct OpcodeGoblinEntryV2 { 275 FuncType type; 276 OpcodeGoblinProcV2 proc; 277 const char *desc; 278 const Param params[16]; 279 }; 280 const OpcodeDrawEntryV2 *_opcodesDrawV2; 281 const OpcodeFuncEntryV2 *_opcodesFuncV2; 282 const OpcodeGoblinEntryV2 *_opcodesGoblinV2; 283 static const int _goblinFuncLookUp[][2]; 284 285 virtual void setupOpcodes(); 286 virtual void drawOpcode(byte i, FuncParams ¶ms); 287 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 288 virtual void goblinOpcode(int i, FuncParams ¶ms); 289 290 void o2_goblinFunc(FuncParams ¶ms); 291 292 void o2_totSub(FuncParams ¶ms); 293 void o2_assign(FuncParams ¶ms); 294 void o2_pushVars(FuncParams ¶ms); 295 void o2_popVars(FuncParams ¶ms); 296 297 void o2_loadSound(FuncParams ¶ms); 298 299 void o2_loadMult(FuncParams ¶ms); 300 void o2_loadMultObject(FuncParams ¶ms); 301 void o2_loadMapObjects(FuncParams ¶ms); 302 303 void o2_playMult(FuncParams ¶ms); 304 void o2_printText(FuncParams ¶ms); 305 306 void o2_loadInfogramesIns(FuncParams ¶ms); 307 void o2_playInfogrames(FuncParams ¶ms); 308 void o2_handleGoblins(FuncParams ¶ms); 309 }; 310 311 class Script_Geisha : public Script_v1 { 312 public: 313 Script_Geisha(byte *totData, uint32 totSize, ExtTable *extTable = 0); 314 virtual ~Script_Geisha(); 315 316 protected: 317 typedef void (Script_Geisha::*OpcodeDrawProcGeisha)(FuncParams &); 318 typedef void (Script_Geisha::*OpcodeFuncProcGeisha)(FuncParams &); 319 typedef void (Script_Geisha::*OpcodeGoblinProcGeisha)(FuncParams &); 320 struct OpcodeDrawEntryGeisha { 321 FuncType type; 322 OpcodeDrawProcGeisha proc; 323 const char *desc; 324 const Param params[16]; 325 }; 326 struct OpcodeFuncEntryGeisha { 327 FuncType type; 328 OpcodeFuncProcGeisha proc; 329 const char *desc; 330 const Param params[16]; 331 }; 332 struct OpcodeGoblinEntryGeisha { 333 FuncType type; 334 OpcodeGoblinProcGeisha proc; 335 const char *desc; 336 const Param params[16]; 337 }; 338 const OpcodeDrawEntryGeisha *_opcodesDrawGeisha; 339 const OpcodeFuncEntryGeisha *_opcodesFuncGeisha; 340 const OpcodeGoblinEntryGeisha *_opcodesGoblinGeisha; 341 static const int _goblinFuncLookUp[][2]; 342 343 virtual void setupOpcodes(); 344 virtual void drawOpcode(byte i, FuncParams ¶ms); 345 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 346 virtual void goblinOpcode(int i, FuncParams ¶ms); 347 348 void oGeisha_goblinFunc(FuncParams ¶ms); 349 }; 350 351 class Script_Bargon : public Script_v2 { 352 public: 353 Script_Bargon(byte *totData, uint32 totSize, ExtTable *extTable = 0); 354 virtual ~Script_Bargon(); 355 356 protected: 357 typedef void (Script_Bargon::*OpcodeDrawProcBargon)(FuncParams &); 358 typedef void (Script_Bargon::*OpcodeFuncProcBargon)(FuncParams &); 359 typedef void (Script_Bargon::*OpcodeGoblinProcBargon)(FuncParams &); 360 struct OpcodeDrawEntryBargon { 361 FuncType type; 362 OpcodeDrawProcBargon proc; 363 const char *desc; 364 const Param params[16]; 365 }; 366 struct OpcodeFuncEntryBargon { 367 FuncType type; 368 OpcodeFuncProcBargon proc; 369 const char *desc; 370 const Param params[16]; 371 }; 372 struct OpcodeGoblinEntryBargon { 373 FuncType type; 374 OpcodeGoblinProcBargon proc; 375 const char *desc; 376 const Param params[16]; 377 }; 378 const OpcodeDrawEntryBargon *_opcodesDrawBargon; 379 const OpcodeFuncEntryBargon *_opcodesFuncBargon; 380 const OpcodeGoblinEntryBargon *_opcodesGoblinBargon; 381 static const int _goblinFuncLookUp[][2]; 382 383 virtual void setupOpcodes(); 384 virtual void drawOpcode(byte i, FuncParams ¶ms); 385 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 386 virtual void goblinOpcode(int i, FuncParams ¶ms); 387 }; 388 389 class Script_Fascin : public Script_v2 { 390 public: 391 Script_Fascin(byte *totData, uint32 totSize, ExtTable *extTable = 0); 392 virtual ~Script_Fascin(); 393 394 protected: 395 typedef void (Script_Fascin::*OpcodeDrawProcFascin)(FuncParams &); 396 typedef void (Script_Fascin::*OpcodeFuncProcFascin)(FuncParams &); 397 typedef void (Script_Fascin::*OpcodeGoblinProcFascin)(FuncParams &); 398 struct OpcodeDrawEntryFascin { 399 FuncType type; 400 OpcodeDrawProcFascin proc; 401 const char *desc; 402 const Param params[16]; 403 }; 404 struct OpcodeFuncEntryFascin { 405 FuncType type; 406 OpcodeFuncProcFascin proc; 407 const char *desc; 408 const Param params[16]; 409 }; 410 struct OpcodeGoblinEntryFascin { 411 FuncType type; 412 OpcodeGoblinProcFascin proc; 413 const char *desc; 414 const Param params[16]; 415 }; 416 const OpcodeDrawEntryFascin *_opcodesDrawFascin; 417 const OpcodeFuncEntryFascin *_opcodesFuncFascin; 418 const OpcodeGoblinEntryFascin *_opcodesGoblinFascin; 419 static const int _goblinFuncLookUp[][2]; 420 421 virtual void setupOpcodes(); 422 virtual void drawOpcode(byte i, FuncParams ¶ms); 423 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 424 virtual void goblinOpcode(int i, FuncParams ¶ms); 425 }; 426 427 class Script_LittleRed : public Script_v2 { 428 public: 429 Script_LittleRed(byte *totData, uint32 totSize, ExtTable *extTable = 0); 430 virtual ~Script_LittleRed(); 431 432 protected: 433 typedef void (Script_LittleRed::*OpcodeDrawProcLittleRed)(FuncParams &); 434 typedef void (Script_LittleRed::*OpcodeFuncProcLittleRed)(FuncParams &); 435 typedef void (Script_LittleRed::*OpcodeGoblinProcLittleRed)(FuncParams &); 436 struct OpcodeDrawEntryLittleRed { 437 FuncType type; 438 OpcodeDrawProcLittleRed proc; 439 const char *desc; 440 const Param params[16]; 441 }; 442 struct OpcodeFuncEntryLittleRed { 443 FuncType type; 444 OpcodeFuncProcLittleRed proc; 445 const char *desc; 446 const Param params[16]; 447 }; 448 struct OpcodeGoblinEntryLittleRed { 449 FuncType type; 450 OpcodeGoblinProcLittleRed proc; 451 const char *desc; 452 const Param params[16]; 453 }; 454 const OpcodeDrawEntryLittleRed *_opcodesDrawLittleRed; 455 const OpcodeFuncEntryLittleRed *_opcodesFuncLittleRed; 456 const OpcodeGoblinEntryLittleRed *_opcodesGoblinLittleRed; 457 static const int _goblinFuncLookUp[][2]; 458 459 virtual void setupOpcodes(); 460 virtual void drawOpcode(byte i, FuncParams ¶ms); 461 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 462 virtual void goblinOpcode(int i, FuncParams ¶ms); 463 }; 464 465 class Script_v3 : public Script_v2 { 466 public: 467 Script_v3(byte *totData, uint32 totSize, ExtTable *extTable = 0); 468 virtual ~Script_v3(); 469 470 protected: 471 typedef void (Script_v3::*OpcodeDrawProcV3)(FuncParams &); 472 typedef void (Script_v3::*OpcodeFuncProcV3)(FuncParams &); 473 typedef void (Script_v3::*OpcodeGoblinProcV3)(FuncParams &); 474 struct OpcodeDrawEntryV3 { 475 FuncType type; 476 OpcodeDrawProcV3 proc; 477 const char *desc; 478 const Param params[16]; 479 }; 480 struct OpcodeFuncEntryV3 { 481 FuncType type; 482 OpcodeFuncProcV3 proc; 483 const char *desc; 484 const Param params[16]; 485 }; 486 struct OpcodeGoblinEntryV3 { 487 FuncType type; 488 OpcodeGoblinProcV3 proc; 489 const char *desc; 490 const Param params[16]; 491 }; 492 const OpcodeDrawEntryV3 *_opcodesDrawV3; 493 const OpcodeFuncEntryV3 *_opcodesFuncV3; 494 const OpcodeGoblinEntryV3 *_opcodesGoblinV3; 495 static const int _goblinFuncLookUp[][2]; 496 497 virtual void setupOpcodes(); 498 virtual void drawOpcode(byte i, FuncParams ¶ms); 499 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 500 virtual void goblinOpcode(int i, FuncParams ¶ms); 501 }; 502 503 class Script_v4 : public Script_v3 { 504 public: 505 Script_v4(byte *totData, uint32 totSize, ExtTable *extTable = 0); 506 virtual ~Script_v4(); 507 508 protected: 509 typedef void (Script_v4::*OpcodeDrawProcV4)(FuncParams &); 510 typedef void (Script_v4::*OpcodeFuncProcV4)(FuncParams &); 511 typedef void (Script_v4::*OpcodeGoblinProcV4)(FuncParams &); 512 struct OpcodeDrawEntryV4 { 513 FuncType type; 514 OpcodeDrawProcV4 proc; 515 const char *desc; 516 const Param params[16]; 517 }; 518 struct OpcodeFuncEntryV4 { 519 FuncType type; 520 OpcodeFuncProcV4 proc; 521 const char *desc; 522 const Param params[16]; 523 }; 524 struct OpcodeGoblinEntryV4 { 525 FuncType type; 526 OpcodeGoblinProcV4 proc; 527 const char *desc; 528 const Param params[16]; 529 }; 530 const OpcodeDrawEntryV4 *_opcodesDrawV4; 531 const OpcodeFuncEntryV4 *_opcodesFuncV4; 532 const OpcodeGoblinEntryV4 *_opcodesGoblinV4; 533 static const int _goblinFuncLookUp[][2]; 534 535 virtual void setupOpcodes(); 536 virtual void drawOpcode(byte i, FuncParams ¶ms); 537 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 538 virtual void goblinOpcode(int i, FuncParams ¶ms); 539 }; 540 541 class Script_v5 : public Script_v4 { 542 public: 543 Script_v5(byte *totData, uint32 totSize, ExtTable *extTable = 0); 544 virtual ~Script_v5(); 545 546 protected: 547 typedef void (Script_v5::*OpcodeDrawProcV5)(FuncParams &); 548 typedef void (Script_v5::*OpcodeFuncProcV5)(FuncParams &); 549 typedef void (Script_v5::*OpcodeGoblinProcV5)(FuncParams &); 550 struct OpcodeDrawEntryV5 { 551 FuncType type; 552 OpcodeDrawProcV5 proc; 553 const char *desc; 554 const Param params[16]; 555 }; 556 struct OpcodeFuncEntryV5 { 557 FuncType type; 558 OpcodeFuncProcV5 proc; 559 const char *desc; 560 const Param params[16]; 561 }; 562 struct OpcodeGoblinEntryV5 { 563 FuncType type; 564 OpcodeGoblinProcV5 proc; 565 const char *desc; 566 const Param params[16]; 567 }; 568 const OpcodeDrawEntryV5 *_opcodesDrawV5; 569 const OpcodeFuncEntryV5 *_opcodesFuncV5; 570 const OpcodeGoblinEntryV5 *_opcodesGoblinV5; 571 static const int _goblinFuncLookUp[][2]; 572 573 virtual void setupOpcodes(); 574 virtual void drawOpcode(byte i, FuncParams ¶ms); 575 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 576 virtual void goblinOpcode(int i, FuncParams ¶ms); 577 578 void o5_spaceShooter(FuncParams ¶ms); 579 580 void o5_istrlen(FuncParams ¶ms); 581 }; 582 583 class Script_v6 : public Script_v5 { 584 public: 585 Script_v6(byte *totData, uint32 totSize, ExtTable *extTable = 0); 586 virtual ~Script_v6(); 587 588 protected: 589 typedef void (Script_v6::*OpcodeDrawProcV6)(FuncParams &); 590 typedef void (Script_v6::*OpcodeFuncProcV6)(FuncParams &); 591 typedef void (Script_v6::*OpcodeGoblinProcV6)(FuncParams &); 592 struct OpcodeDrawEntryV6 { 593 FuncType type; 594 OpcodeDrawProcV6 proc; 595 const char *desc; 596 const Param params[16]; 597 }; 598 struct OpcodeFuncEntryV6 { 599 FuncType type; 600 OpcodeFuncProcV6 proc; 601 const char *desc; 602 const Param params[16]; 603 }; 604 struct OpcodeGoblinEntryV6 { 605 FuncType type; 606 OpcodeGoblinProcV6 proc; 607 const char *desc; 608 const Param params[16]; 609 }; 610 const OpcodeDrawEntryV6 *_opcodesDrawV6; 611 const OpcodeFuncEntryV6 *_opcodesFuncV6; 612 const OpcodeGoblinEntryV6 *_opcodesGoblinV6; 613 static const int _goblinFuncLookUp[][2]; 614 615 virtual void setupOpcodes(); 616 virtual void drawOpcode(byte i, FuncParams ¶ms); 617 virtual void funcOpcode(byte i, byte j, FuncParams ¶ms); 618 virtual void goblinOpcode(int i, FuncParams ¶ms); 619 620 void o6_loadCursor(FuncParams ¶ms); 621 void o6_assign(FuncParams ¶ms); 622 void o6_createSprite(FuncParams ¶ms); 623 }; 624 625 #endif // DEGOB_SCRIPT_H 626