|
19 | 19 | *
|
20 | 20 | */
|
21 | 21 | #include "common/file.h"
|
| 22 | +#include "common/memstream.h" |
22 | 23 |
|
23 | 24 | #include "freescape/freescape.h"
|
24 | 25 | #include "freescape/language/8bitDetokeniser.h"
|
25 | 26 |
|
26 | 27 | namespace Freescape {
|
27 | 28 |
|
28 |
| -void DrillerEngine::loadAssetsAtariFullGame() { |
| 29 | +Common::SeekableReadStream *DrillerEngine::decryptFileAtari(const Common::String filename) { |
29 | 30 | Common::File file;
|
30 |
| - file.open("x.prg"); |
31 |
| - |
| 31 | + file.open(filename); |
32 | 32 | if (!file.isOpen())
|
33 |
| - error("Failed to open 'x.prg' executable for AtariST"); |
34 |
| - |
35 |
| - _border = loadAndConvertNeoImage(&file, 0x1371a); |
36 |
| - byte *palette = (byte *)malloc(16 * 3); |
37 |
| - for (int i = 0; i < 16; i++) { // gray scale palette |
38 |
| - palette[i * 3 + 0] = i * (255 / 16); |
39 |
| - palette[i * 3 + 1] = i * (255 / 16); |
40 |
| - palette[i * 3 + 2] = i * (255 / 16); |
| 33 | + error("Failed to open %s", filename.c_str()); |
| 34 | + |
| 35 | + int size = file.size(); |
| 36 | + byte *encryptedBuffer = (byte *)malloc(size); |
| 37 | + file.read(encryptedBuffer, size); |
| 38 | + file.close(); |
| 39 | + |
| 40 | + byte *a6 = encryptedBuffer + 0x118; |
| 41 | + byte *a5 = encryptedBuffer + size - 4; |
| 42 | + uint64 key = 0xb9f11bce; |
| 43 | + |
| 44 | + while (a6 <= a5) { |
| 45 | + uint64 d0 = (a6[0] << 24) | (a6[1] << 16) | (a6[2] << 8) | a6[3]; |
| 46 | + d0 += key; |
| 47 | + d0 = uint32(d0); |
| 48 | + |
| 49 | + a6[0] = byte((d0 >> 24) & 0xFF); |
| 50 | + a6[1] = byte((d0 >> 16) & 0xFF); |
| 51 | + a6[2] = byte((d0 >> 8) & 0xFF); |
| 52 | + a6[3] = byte(d0 & 0xFF); |
| 53 | + |
| 54 | + key += 0x51684624; |
| 55 | + key = uint32(key); |
| 56 | + a6 += 4; |
| 57 | + } |
| 58 | + |
| 59 | + return (new Common::MemoryReadStream(encryptedBuffer, size)); |
| 60 | +} |
| 61 | + |
| 62 | +void DrillerEngine::loadAssetsAtariFullGame() { |
| 63 | + |
| 64 | + if (_variant & GF_ATARI_RETAIL) { |
| 65 | + Common::SeekableReadStream *stream = decryptFileAtari("x.prg"); |
| 66 | + |
| 67 | + _border = loadAndConvertNeoImage(stream, 0x14b96); |
| 68 | + _title = loadAndConvertNeoImage(stream, 0x1c916); |
| 69 | + |
| 70 | + loadFonts(stream, 0x8a92); |
| 71 | + loadMessagesFixedSize(stream, 0xda22, 14, 20); |
| 72 | + loadGlobalObjects(stream, 0xd116, 8); |
| 73 | + load8bitBinary(stream, 0x2afb8, 16); |
| 74 | + loadPalettes(stream, 0x2ab76); |
| 75 | + //loadSoundsFx(&file, 0x30da6, 25); |
| 76 | + } else if (_variant & GF_ATARI_BUDGET) { |
| 77 | + Common::File file; |
| 78 | + file.open("x.prg"); |
| 79 | + |
| 80 | + if (!file.isOpen()) |
| 81 | + error("Failed to open 'x.prg' executable for AtariST"); |
| 82 | + |
| 83 | + _border = loadAndConvertNeoImage(&file, 0x1371a); |
| 84 | + byte *palette = (byte *)malloc(16 * 3); |
| 85 | + for (int i = 0; i < 16; i++) { // gray scale palette |
| 86 | + palette[i * 3 + 0] = i * (255 / 16); |
| 87 | + palette[i * 3 + 1] = i * (255 / 16); |
| 88 | + palette[i * 3 + 2] = i * (255 / 16); |
| 89 | + } |
| 90 | + _title = loadAndConvertNeoImage(&file, 0x10, palette); |
| 91 | + |
| 92 | + loadFonts(&file, 0x8a32); |
| 93 | + loadMessagesFixedSize(&file, 0xc5d8, 14, 20); |
| 94 | + loadGlobalObjects(&file, 0xbccc, 8); |
| 95 | + load8bitBinary(&file, 0x29b3c, 16); |
| 96 | + loadPalettes(&file, 0x296fa); |
| 97 | + loadSoundsFx(&file, 0x30da6, 25); |
41 | 98 | }
|
42 |
| - _title = loadAndConvertNeoImage(&file, 0x10, palette); |
43 |
| - |
44 |
| - loadFonts(&file, 0x8a32); |
45 |
| - loadMessagesFixedSize(&file, 0xc5d8, 14, 20); |
46 |
| - loadGlobalObjects(&file, 0xbccc, 8); |
47 |
| - load8bitBinary(&file, 0x29b3c, 16); |
48 |
| - loadPalettes(&file, 0x296fa); |
49 |
| - loadSoundsFx(&file, 0x30da6, 25); |
50 | 99 | }
|
51 | 100 |
|
52 | 101 | void DrillerEngine::loadAssetsAtariDemo() {
|
|
0 commit comments