1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
|
/* ScummVM Tools
*
* ScummVM Tools is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* GobEngine Script disassembler */
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "degob_script.h"
#include "common/endian.h"
#include "common/util.h"
ExtTable::ExtTable(byte *data, uint32 size, byte *dataCom, uint32 sizeCom) :
_data(data), _size(size), _dataCom(dataCom), _sizeCom(sizeCom) {
assert(data && (size >= 3));
init();
}
ExtTable::~ExtTable() {
delete[] _items;
}
void ExtTable::init() {
byte *data = _data;
_itemsCount = READ_LE_UINT16(data);
_items = _itemsCount ? new Item[_itemsCount] : 0;
data += 3;
assert(_size >= (uint32) (3 + _itemsCount * 10));
for (uint16 i = 0; i < _itemsCount; i++, data += 10) {
_items[i].offset = READ_LE_UINT32(data);
_items[i].size = READ_LE_UINT16(data + 4);
_items[i].width = READ_LE_UINT16(data + 6);
_items[i].height = READ_LE_UINT16(data + 8);
_items[i].isPacked = (_items[i].width & 0x8000) != 0;
_items[i].width &= 0x7FFF;
if (_items[i].width & 0x4000)
_items[i].size += 1 << 16;
if (_items[i].width & 0x2000)
_items[i].size += 2 << 16;
if (_items[i].width & 0x1000)
_items[i].size += 4 << 16;
if (_items[i].height == 0)
_items[i].size += _items[i].width << 16;
_items[i].width &= 0xFFF;
}
}
byte *ExtTable::getItem(uint16 i, uint32 &size) const {
assert(i < _itemsCount);
Item &item = _items[i];
int32 offset = item.offset;
byte *data, *dataBuf;
if (offset < 0) {
offset = -(offset + 1);
if (!_dataCom)
error("commun.exN needed");
assert(((uint32) offset) < _sizeCom);
data = _dataCom;
} else {
assert(((uint32) offset) < _size);
data = _data + (3 + _itemsCount * 10);
}
size = item.size;
if (item.isPacked)
dataBuf = new byte[size + 2];
else
dataBuf = new byte[size];
memcpy(dataBuf, data + offset, size);
if (item.isPacked) {
byte *packedBuf = dataBuf;
dataBuf = unpack(packedBuf, size);
delete[] packedBuf;
}
return dataBuf;
}
// Some LZ77-variant
byte *ExtTable::unpack(const byte *packedData, uint32 &size) const {
byte *dataBuf, *tmpBuf, *dest;
uint32 counter;
uint16 tmpIndex;
uint16 cmd;
int16 off;
byte len;
counter = size = READ_LE_UINT32(packedData);
dataBuf = new byte[size];
tmpBuf = new byte[4114];
for (int i = 0; i < 4078; i++)
tmpBuf[i] = 0x20;
tmpIndex = 4078;
packedData += 4;
dest = dataBuf;
cmd = 0;
while (1) {
cmd >>= 1;
if ((cmd & 0x0100) == 0) {
cmd = *packedData | 0xFF00;
packedData++;
}
if ((cmd & 1) != 0) { /* copy */
*dest++ = *packedData;
tmpBuf[tmpIndex] = *packedData;
packedData++;
tmpIndex++;
tmpIndex %= 4096;
counter--;
if (counter == 0)
break;
} else { /* copy string */
off = *packedData++;
off |= (*packedData & 0xF0) << 4;
len = (*packedData & 0x0F) + 3;
packedData++;
for (int i = 0; i < len; i++) {
*dest++ = tmpBuf[(off + i) % 4096];
counter--;
if (counter == 0) {
delete[] tmpBuf;
return dataBuf;
}
tmpBuf[tmpIndex] = tmpBuf[(off + i) % 4096];
tmpIndex++;
tmpIndex %= 4096;
}
}
}
delete[] tmpBuf;
return dataBuf;
}
Script::Script(byte *totData, uint32 totSize, ExtTable *extTable) :
_totData(totData), _ptr(totData), _totSize(totSize), _extTable(extTable) {
assert(totData && (totSize > 128));
_indent = 0;
loadProperties(totData);
}
Script::~Script() {}
uint16 Script::getStart() const { return _start; }
uint16 Script::getTextCenter() const { return _textCenter; }
uint16 Script::getVarsCount() const { return _varsCount; }
uint32 Script::getTotTextCount() const { return _totTextCount; }
uint32 Script::getTotResOffset() const { return _totResOffset; }
uint16 Script::getTotResCount() const { return _totResCount; }
uint16 Script::getAnimDataSize() const { return _animDataSize; }
uint8 Script::getVerScript() const { return _verScript; }
uint8 Script::getVerIMEX() const { return _verIMEX; }
uint8 Script::getSuffixIM() const { return _suffixIM; }
uint8 Script::getSuffixEX() const { return _suffixEX; }
uint32 Script::getFuncNamesCount() const { return _funcOffsetsNames.size(); }
void Script::putString(const char *s) const {
printf("%s", s);
}
void Script::print(const char *s, ...) const {
char buf[1024];
va_list va;
va_start(va, s);
vsnprintf(buf, 1024, s, va);
va_end(va);
putString(buf);
}
void Script::printIndent() const {
print("%08d:", lastOffsetPos());
for (uint32 i = 0; i < _indent; i++)
putString(" ");
}
void Script::printLine(const char *str) const {
printIndent(); putString(str); putString("\n");
}
std::string Script::printStr(const char *s, ...) const {
char buf[1024];
va_list va;
va_start(va, s);
vsnprintf(buf, 1024, s, va);
va_end(va);
return buf;
}
void Script::incIndent() { _indent++; }
void Script::decIndent() { _indent--; }
uint32 Script::getPos() const { return _ptr - _totData; }
uint32 Script::lastOffsetPos() const { return _lastOffsetPos - _totData; }
void Script::updateOffsetPos(uint32 pos) { _lastOffsetPos = _totData + pos; }
void Script::skip(uint32 off) { seek(off, SEEK_CUR); }
void Script::skipBlock() {seek(peekUint16(2) + 2, SEEK_CUR);}
void Script::seek(uint32 off, int whence) {
switch (whence) {
case SEEK_END:
off = _totSize - off;
// fall through
case SEEK_SET:
_ptr = _totData + off;
break;
case SEEK_CUR:
_ptr += (int32) off;
break;
}
}
uint8 Script::peekUint8(int32 offset) const { return *(_ptr + offset); }
uint16 Script::peekUint16(int32 offset) const { return READ_LE_UINT16(_ptr + offset); }
uint32 Script::peekUint32(int32 offset) const { return READ_LE_UINT32(_ptr + offset); }
uint8 Script::readUint8() { uint8 i = peekUint8(); _ptr += 1; return i; }
uint16 Script::readUint16() { uint16 i = peekUint16(); _ptr += 2; return i; }
uint32 Script::readUint32() { uint32 i = peekUint32(); _ptr += 4; return i; }
const char *Script::peekString(int32 offset) const { return (char *) _ptr + offset; }
const char *Script::readString() { const char *i = peekString(); _ptr += strlen(i) + 1; return i; }
void Script::skipExpr(char stopToken) {
int16 dimCount;
byte operation;
int16 num;
int16 dim;
num = 0;
while (1) {
operation = readUint8();
if ((operation >= 14) && (operation <= 29)) {
switch (operation) {
case 14:
skip(4);
if (peekUint8() == 97)
skip(1);
break;
case 17:
case 18:
case 20:
case 23:
case 24:
skip(2);
break;
case 19:
skip(4);
break;
case 21:
skip(1);
break;
case 22:
skip(strlen((char *) _ptr) + 1);
break;
case 25:
skip(2);
if (peekUint8() == 13) {
skip(1);
skipExpr(12);
}
break;
case 15:
skip(2);
// fall through
case 16:
case 26:
case 27:
case 28:
dimCount = _ptr[2];
// skip header and dimensions
skip(3 + dimCount);
// skip indices
for (dim = 0; dim < dimCount; dim++)
skipExpr(12);
if ((operation == 28) && (peekUint8() == 13)) {
skip(1);
skipExpr(12);
}
break;
case 29:
skip(1);
skipExpr(10);
}
continue;
} // if ((operation >= 14) && (operation <= 29))
if (operation == 9) {
num++;
continue;
}
if ((operation == 11) || ((operation >= 1) && (operation <= 8)))
continue;
if ((operation >= 30) && (operation <= 37))
continue;
if (operation == 10)
num--;
if (operation != stopToken)
continue;
if ((stopToken != 10) || (num < 0))
return;
}
}
std::string Script::readExpr(char stopToken) {
std::string expr;
int16 dimCount;
byte operation;
int16 num;
int16 dim;
byte *arrDesc;
byte func;
num = 0;
while (1) {
operation = readUint8();
while ((operation == 14) || (operation == 15)) {
if (operation == 14) {
// Add a direct offset
expr += printStr("#%d#", readUint16() * 4);
skip(2);
if (peekUint8() == 97)
skip(1);
} else if (operation == 15) {
// Add an offset from an array
expr += printStr("#%d->", readUint16() * 4);
skip(2);
dimCount = readUint8();
skip(dimCount);
for (int i = 0; i < dimCount; i++)
expr += readExpr(12) + "->";
expr += "#";
if (peekUint8() == 97)
skip(1);
}
operation = readUint8();
}
if ((operation >= 16) && (operation <= 29)) {
// operands
switch (operation) {
case 17: // uint16 variable load
expr += printStr("var16_%d", readUint16() * 2);
break;
case 18: // uint8 variable load:
expr += printStr("var8_%d", readUint16());
break;
case 19: // int32/uint32 immediate
expr += printStr("%d", readUint32());
break;
case 20: // int16 immediate
expr += printStr("%d", (int16) readUint16());
break;
case 21: // int8 immediate
expr += printStr("%d", (int8) readUint8());
break;
case 22: // string immediate
expr += printStr("\"%s\"", readString());
break;
case 23: // uint32 variable load
case 24: // uint32 variable load as uint16
expr += printStr("var32_%d", readUint16() * 4);
break;
case 25: // string variable load
expr += printStr("(&var8_%d)", readUint16() * 4);
if (peekUint8() == 13) {
skip(1);
expr += "+{*";
expr += readExpr(12); // this also prints the closing }
}
break;
case 16: // uint8 array access
case 26: // uint32 array access
case 27: // uint16 array access
case 28: // string array access
if (operation == 16)
expr += printStr("var8_%d[", readUint16());
else if (operation == 26)
expr += printStr("var32_%d[", readUint16() * 4);
else if (operation == 27)
expr += printStr("var16_%d[", readUint16() * 2);
else if (operation == 28)
expr += printStr("(&var8_%d[", readUint16() * 4);
dimCount = readUint8();
arrDesc = _ptr;
skip(dimCount);
for (dim = 0; dim < dimCount; dim++) {
expr += readExpr(12) + printStr(" of %d", (int16) arrDesc[dim]);
if (dim != dimCount - 1)
expr += "][";
}
expr += "]";
if (operation == 28)
expr += ")";
if ((operation == 28) && (peekUint8() == 13)) {
skip(1);
expr += "+{*" + readExpr(12);
}
break;
case 29: // function
func = readUint8();
if (func == 5)
expr += "sqr(";
else if (func == 10)
expr += "rand(";
else if (func == 7)
expr += "abs(";
else if ((func == 0) || (func == 1) || (func == 6))
expr += "sqrt(";
else
expr += "id(";
expr += readExpr(10);
break;
}
continue;
} // if ((operation >= 16) && (operation <= 29))
// operators
switch (operation) {
case 9:
expr += "(";
break;
case 11:
expr += "!";
break;
case 10:
expr += ")";
break;
case 1:
expr += "-";
break;
case 2:
expr += "+";
break;
case 3:
expr += "-";
break;
case 4:
expr += "|";
break;
case 5:
expr += "*";
break;
case 6:
expr += "/";
break;
case 7:
expr += "%";
break;
case 8:
expr += "&";
break;
case 30:
expr += " || ";
break;
case 31:
expr += " && ";
break;
case 32:
expr += "<";
break;
case 33:
expr += "<=";
break;
case 34:
expr += ">";
break;
case 35:
expr += ">=";
break;
case 36:
expr += "==";
break;
case 37:
expr += "!=";
break;
case 99:
// expr += "\n";
break;
case 12:
expr += "}";
if (stopToken != 12)
warning("Closing paren without opening?");
break;
default:
// Unknown token -- don't know how to handle this, so just
// skip over everything until we reach the stopToken.
while (((char) readUint8()) != stopToken) {}
return printStr("Invalid operator in expression: <%d>", (int16) operation);
break;
}
if (operation == 9) {
num++;
continue;
}
if ((operation == 11) || ((operation >= 1) && (operation <= 8)))
continue;
if ((operation >= 30) && (operation <= 37))
continue;
if (operation == 10)
num--;
if (operation == stopToken) {
if ((stopToken != 10) || (num < 0)) {
return expr;
}
}
}
}
std::string Script::readVarIndex(uint16 *arg_0, uint16 *arg_4) {
std::string expr, pref;
byte *arrDesc;
int16 dim;
int16 dimCount;
int16 operation;
uint16 temp;
operation = readUint8();
while ((operation == 14) || (operation == 15)) {
if (operation == 14) {
pref += printStr("#%d#", readUint16() * 4);
if (arg_0)
*arg_0 = peekUint16();
if (arg_4)
*arg_4 = 14;
skip(2);
if (peekUint8() != 97)
return pref;
skip(1);
} else if (operation == 15) {
pref += printStr("#%d->", readUint16() * 4);
if (arg_0)
*arg_0 = peekUint16();
if (arg_4)
*arg_4 = 14;
skip(2);
uint8 var_A = readUint8();
skip(var_A);
for (int i = 0; i < var_A; i++)
pref += readExpr(12) + "->";
pref += "#";
if (peekUint8() != 97)
return pref;
skip(1);
}
operation = readUint8();
}
if (arg_0)
*arg_0 = 0;
if (arg_4)
*arg_4 = operation;
if ((operation == 16) || (operation == 18) || (operation == 25) || (operation == 28))
expr = "var8_";
else if ((operation == 17) || (operation == 24) || (operation == 27))
expr = "var16_";
else if ((operation == 23) || (operation == 26))
expr = "var32_";
expr += pref;
switch (operation) {
case 23:
case 24:
case 25:
temp = readUint16() * 4;
expr += printStr("%d", temp);
if ((operation == 25) && (peekUint8() == 13)) {
skip(1);
expr += "+{*";
expr += readExpr(12);
}
break;
case 17:
expr += printStr("%d", readUint16() * 2);
break;
case 18:
expr += printStr("%d", readUint16());
break;
case 16:
case 26:
case 27:
case 28:
if (operation == 16)
expr += printStr("%d[", readUint16());
else if (operation == 26)
expr += printStr("%d[", readUint16() * 4);
else if (operation == 27)
expr += printStr("%d[", readUint16() * 2);
else if (operation == 28)
expr += printStr("%d[", readUint16() * 4);
dimCount = readUint8();
arrDesc = _ptr;
skip(dimCount);
for (dim = 0; dim < dimCount; dim++) {
expr += readExpr(12);
expr += printStr(" of %d", (int16) arrDesc[dim]);
if (dim != dimCount - 1)
expr += "][";
}
expr += "]";
if ((operation == 28) && (peekUint8() == 13)) {
skip(1);
expr += "+{*";
expr += readExpr(12);
}
break;
default:
expr += "var_0";
break;
}
return expr;
}
uint16 Script::getBlockSize() const {
return READ_LE_UINT16(_ptr + 2) + 2;
}
void Script::evaluateParams(const Param *params) {
bool first = true;
while (*params != PARAM_NONE) {
if (!first)
print(", ");
else
first = false;
switch (*params++) {
case PARAM_UINT8:
print("%u", readUint8());
break;
case PARAM_UINT16:
print("%u", readUint16());
break;
case PARAM_UINT32:
print("%u", readUint32());
break;
case PARAM_INT8:
print("%d", (int8) readUint8());
break;
case PARAM_INT16:
print("%d", (int16) readUint16());
break;
case PARAM_INT32:
print("%d", (int32) readUint32());
break;
case PARAM_STR:
print("\"%s\"", readString());
break;
case PARAM_EXPR:
print("%s", readExpr().c_str());
break;
case PARAM_VARINDEX:
print("%s", readVarIndex().c_str());
break;
default:
error("Unknown parameter type");
break;
}
}
}
void Script::printFuncDesc(const FuncParams &fParams, const Param *params) {
if (!fParams.desc)
return;
printIndent();
putString(fParams.desc);
putString("(");
if (params)
evaluateParams(params);
putString(");\n");
}
void Script::printFuncDesc(const FuncParams &fParams) const {
if (!fParams.desc)
return;
printIndent();
putString(fParams.desc);
putString("(");
print("%d, %d", fParams.objIndex, fParams.extraData);
putString(");\n");
}
void Script::startFunc(const FuncParams &fParams) const {
printIndent();
print("%s(", fParams.desc);
}
void Script::endFunc() const {
print(");\n");
}
void Script::loadProperties(byte *data) {
_start = READ_LE_UINT16(data + 0x64);
//assert(_start >= 128) -> pure "library" files may have no defined entry point (_start = 0)
_varsCount = READ_LE_UINT16(data + 0x2C);
_totTextCount = READ_LE_UINT32(data + 0x30);
_totResOffset = READ_LE_UINT32(data + 0x34);
_totResCount = (_totResOffset == 0xFFFFFFFF) ? 0 : READ_LE_UINT16(data + _totResOffset);
_verScript = data[0x29];
_verIMEX = data[0x3D];
_suffixIM = data[0x3B];
_suffixEX = data[0x3C];
_animDataSize = READ_LE_UINT16(data + 0x38);
_textCenter = READ_LE_UINT16(data + 0x7E);
}
void Script::loadIDE(const byte *ideData) {
const byte *ptr = ideData;
char buffer[17];
uint16 count = *(const uint16 *)ptr;
ptr += 2;
for (uint32 i = 0; i < count; i++) {
// skip function type
byte functionType = *ptr;
++ptr;
memcpy(buffer, ptr, 17);
buffer[16] = '\0';
ptr += 17;
// skip unknown word
ptr += 2;
// Read offset
uint16 offset = *(const uint16 *)ptr;
ptr += 2;
// skip unknown word
ptr += 2;
if ((functionType != 0x47) && (functionType != 0x67))
continue;
_funcOffsetsNames[offset] = buffer;
}
}
void Script::funcBlock(int16 retFlag) {
FuncParams params;
byte cmd;
byte cmd2;
params.retFlag = retFlag;
skip(1);
params.cmdCount = readUint8();
skip(2);
if (params.cmdCount == 0)
return;
params.counter = 0;
do {
cmd = readUint8();
if ((cmd >> 4) >= 12) {
cmd2 = 16 - (cmd >> 4);
cmd &= 0xF;
} else
cmd2 = 0;
params.counter++;
if (cmd2 == 0)
cmd >>= 4;
updateOffsetPos(getPos());
funcOpcode(cmd2, cmd, params);
updateOffsetPos(getPos());
} while (params.counter != params.cmdCount);
}
void Script::addStartingOffsets() {
for (int i = 100; i < 128; i += 2) {
uint16 offset = READ_LE_UINT16(_totData + i);
if ((offset >= 128) && (offset != ((uint16) -1)))
addFuncOffset(offset);
}
}
void Script::addFuncOffset(uint32 offset) {
for (std::list<uint32>::iterator it = _funcOffsets.begin(); it != _funcOffsets.end(); ++it)
if (*it == offset)
return;
_funcOffsets.push_back(offset);
}
void Script::deGob(int32 offset, bool isLib) {
_funcOffsets.clear();
if (isLib) {
// Use functions from IDE file as entry points
for (auto it = _funcOffsetsNames.begin(); it != _funcOffsetsNames.end(); ++it)
addFuncOffset(it->first);
} else {
if (offset < 0)
addStartingOffsets();
else
_funcOffsets.push_back(offset);
}
for (std::list<uint32>::iterator it = _funcOffsets.begin(); it != _funcOffsets.end(); ++it) {
seek(*it);
deGobFunction();
print("\n");
}
}
void Script::deGobFunction() {
if (!_funcOffsetsNames.empty()) {
auto it = _funcOffsetsNames.find(getPos());
if (it != _funcOffsetsNames.end()) {
print("--- %s ---\n", it->second.c_str());
}
}
updateOffsetPos(getPos());
printIndent();
print("sub_%d {\n", getPos());
incIndent();
funcBlock(2);
decIndent();
printIndent();
print("}\n");
}
|