| 731 | |
| 732 | // SCI1 and SCI1.1 maps consist of a fixed 3-byte header, a directory list (3-bytes each) that has one entry |
| 733 | // of id FFh and points to EOF. The actual entries have 6-bytes on SCI1 and 5-bytes on SCI1.1 |
| 734 | byte directoryType = 0; |
| 735 | uint16 directoryOffset = 0; |
| 736 | uint16 lastDirectoryOffset = 0; |
| 737 | uint16 directorySize = 0; |
| 738 | int mapDetected = 0; |
| 739 | file.seek(0, SEEK_SET); |
| 740 | while (!file.eos()) { |
| 741 | directoryType = file.readByte(); |
| 742 | directoryOffset = file.readUint16LE(); |
| 743 | if ((directoryType<0x80) || ((directoryType>0xA0) && (directoryType!=0xFF))) |
| 744 | break; |
| 745 | // Offset is above file size? -> definitely not SCI1/SCI1.1 |
| 746 | if (directoryOffset>file.size()) |
| 747 | break; |
| 748 | if (lastDirectoryOffset) { |
| 749 | directorySize = directoryOffset - lastDirectoryOffset; |
| 750 | if ((directorySize % 5) && (directorySize % 6 == 0)) |
| 751 | mapDetected = SCI_VERSION_1; |
| 752 | if ((directorySize % 5 == 0) && (directorySize % 6)) |
| 753 | mapDetected = SCI_VERSION_1_1; |
| 754 | } |
| 755 | if (directoryType==0xFF) { |
| 756 | // FFh entry needs to point to EOF |
| 757 | if (directoryOffset!=file.size()) |
| 758 | break; |
| 759 | if (mapDetected) return mapDetected; |
| 760 | return SCI_VERSION_1; |
| 761 | } |
| 762 | lastDirectoryOffset = directoryOffset; |
| 763 | } |
734 | | file.seek(1, SEEK_SET); |
735 | | uint16 off1, off = file.readUint16LE(); |
736 | | uint16 nEntries = off / 3; |
737 | | file.seek(1, SEEK_CUR); |
738 | | file.seek(off - 3, SEEK_SET); |
739 | | if (file.readByte() == 0xFF && file.readUint16LE() == file.size()) { |
740 | | file.seek(3, SEEK_SET); |
741 | | for (int i = 0; i < nEntries; i++) { |
742 | | file.seek(1, SEEK_CUR); |
743 | | off1 = file.readUint16LE(); |
744 | | if ((off1 - off) % 5 && (off1 - off) % 6 == 0) |
745 | | return SCI_VERSION_1; |
746 | | if ((off1 - off) % 5 == 0 && (off1 - off) % 6) |
747 | | return SCI_VERSION_1_1; |
748 | | off = off1; |
749 | | } |
750 | | return SCI_VERSION_1; |
751 | | } |
| 767 | // file.seek(1, SEEK_SET); |
| 768 | // uint16 off1, off = file.readUint16LE(); |
| 769 | // uint16 nEntries = off / 3; |
| 770 | // file.seek(1, SEEK_CUR); |
| 771 | // file.seek(off - 3, SEEK_SET); |
| 772 | // |
| 773 | // if (file.readByte() == 0xFF && file.readUint16LE() == file.size()) { |
| 774 | // file.seek(3, SEEK_SET); |
| 775 | // for (int i = 0; i < nEntries; i++) { |
| 776 | // file.seek(1, SEEK_CUR); |
| 777 | // off1 = file.readUint16LE(); |
| 778 | // if ((off1 - off) % 5 && (off1 - off) % 6 == 0) |
| 779 | // return SCI_VERSION_1; |
| 780 | // if ((off1 - off) % 5 == 0 && (off1 - off) % 6) |
| 781 | // return SCI_VERSION_1_1; |
| 782 | // off = off1; |
| 783 | // } |
| 784 | // return SCI_VERSION_1; |
| 785 | // } |