-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextract.py
executable file
·276 lines (251 loc) · 8.86 KB
/
extract.py
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
#!/usr/bin/env python
# coding: utf-8
# Helps you to run the Steam LucasArts Adventure Pack in ScummVM
# Licence: GPL
import zlib
import os
import sys
import struct
pc = {
'atlantis': {
'name': 'Indiana Jones and the Fate of Atlantis',
'source_binary': 'Indiana Jones and the Fate of Atlantis.exe',
'source_dir': 'indiana jones and the fate of atlantis',
'destination_file': 'ATLANTIS.000',
'destination_dir': 'ATLANTIS',
'checksum': '60e9988f',
'offset': 224336,
'size': 12035
},
'indy3': {
'name': 'Indiana Jones and the Last Crusade',
'source_binary': 'Indiana Jones and the Last Crusade.exe',
'source_dir': 'indiana jones and the last crusade',
'destination_file': '00.LFL',
'destination_dir': 'INDY3',
'checksum': '4f179478',
'offset': 162056,
'size': 6295
},
'loom': {
'name': 'Loom',
'source_binary': 'Loom.exe',
'source_dir': 'loom',
'destination_file': '000.LFL',
'destination_dir': 'LOOM',
'checksum': '3ef3e225',
'offset': 187248,
'size': 8307
},
'loom_audio': {
'name': 'Loom Audio',
'source_binary': 'CDDA.SOU',
'source_dir': 'loom\loom',
'destination_file': 'Track1.wav',
'destination_dir': 'LOOM',
'checksum': 'a3362c72',
'offset': 800,
'size': 289808002
},
'thedig': {
'name': 'The Dig',
'source_binary': 'The Dig.exe',
'source_dir': 'the dig',
'destination_file': 'DIG.LA0',
'destination_dir': 'DIG',
'checksum': '95af95ad',
'offset': 340632,
'size': 16304
}
}
mac = {
'atlantis': {
'name': 'Indiana Jones and the Fate of Atlantis',
'source_binary': 'The Fate of Atlantis',
'source_dir': 'indiana jones and the fate of atlantis/The Fate of Atlantis.app/Contents/MacOS',
'destination_file': 'ATLANTIS.000',
'destination_dir': 'ATLANTIS',
'checksum': '60e9988f',
'offset': 260224,
'size': 12035
},
'indy3': {
'name': 'Indiana Jones and the Last Crusade',
'source_binary': 'The Last Crusade',
'source_dir': 'indiana jones and the last crusade/The Last Crusade.app/Contents/MacOS',
'destination_file': '00.LFL',
'destination_dir': 'INDY3',
'checksum': '4f179478',
'offset': 150368,
'size': 6295
},
'loom': {
'name': 'Loom',
'source_binary': 'Loom',
'source_dir': 'loom/Loom.app/Contents/MacOS',
'destination_file': '000.LFL',
'destination_dir': 'LOOM',
'checksum': '3ef3e225',
'offset': 170464,
'size': 8307
},
'loom_audio': {
'name': 'Loom Audio',
'source_binary': 'CDDA.SOU',
'source_dir': 'loom/Loom.app/Contents/Resources',
'destination_file': 'Track1.wav',
'destination_dir': 'LOOM',
'checksum': 'a3362c72',
'offset': 800,
'size': 289808002
},
'thedig': {
'name': 'The Dig',
'source_binary': 'The Dig',
'source_dir': 'the dig/The Dig.app/Contents/MacOS',
'destination_file': 'DIG.LA0',
'destination_dir': 'DIG',
'checksum': '95af95ad',
'offset': 339744,
'size': 16304
}
}
def extract_game_data(extract_information, steam_path, destination_directory):
game_binary = "%s/%s/%s" % (steam_path,
extract_information['source_dir'],
extract_information['source_binary'])
if not os.path.isfile(game_binary):
print ("\033[91m✘\033[0m %s Does not appear to be installed"
% (extract_information['name']))
return False
f = open(game_binary, "rb")
f.seek(extract_information['offset'])
extract = f.read(extract_information['size'])
extract_checksum = zlib.crc32(extract) & 0xffffffff
f.close()
if "%x" % extract_checksum != extract_information['checksum']:
print (
"\033[91m✘\033[0m Failed to extract %s (%s) - checksum mismatch" %
(extract_information['name'], extract_information['destination_file']))
return False
if not os.path.exists(
destination_directory +
'/' +
extract_information['destination_dir']):
os.mkdir(
destination_directory +
'/' +
extract_information['destination_dir'])
target = destination_directory + '/' + \
extract_information['destination_dir'] + '/' + extract_information['destination_file']
r = open(target, "wb")
if extract_information['name'] == 'Loom Audio':
print 'Extracting Loom audio, process takes several minutes...'
extract = extract_loom_audio(extract)
# TODO: check datafile. should have crc32 e9dee869
r.write(extract)
r.close()
print ("\033[92m✔\033[0m Extracted %s"
% (extract_information['name']))
def extract_loom_audio(extract):
new_extract = ""
new_extract += struct.pack('BBBB', 0x52, 0x49, 0x46, 0x46)
new_extract += struct.pack('I', 579123588)
new_extract += struct.pack('BBBB', 0x57, 0x41, 0x56, 0x45)
new_extract += struct.pack('BBBB', 0x66, 0x6D, 0x74, 0x20)
new_extract += struct.pack('BBBB', 16, 0, 0, 0)
new_extract += struct.pack('BB', 1, 0)
new_extract += struct.pack('BB', 2, 0)
new_extract += struct.pack('I', 44100)
new_extract += struct.pack('I', 176400)
new_extract += struct.pack('BB', 4, 0)
new_extract += struct.pack('BB', 16, 0)
new_extract += struct.pack('BBBB', 0x64, 0x61, 0x74, 0x61)
new_extract += struct.pack('I', 579123552)
frame = 0
for byte in enumerate(extract):
if not (byte[0] % 1177):
frame += 1
bits = (ord(b) for b in byte[1])
for b in bits:
lshift = b >> 4
bits = (ord(b) for b in byte[1])
for b in bits:
rshift = b & 0x0F
else:
if (byte[0] %
2 == 0 and frame %
2 == 0) or (byte[0] %
2 == 1 and frame %
2 == 1):
shift_by = lshift
else:
shift_by = rshift
new_byte = struct.unpack('b', byte[1])[0]
new_byte = new_byte << shift_by
if(new_byte & 0x8):
new_byte = -0x0 + new_byte
new_extract += struct.pack('<h', new_byte)
if frame % 2000 == 0:
sys.stdout.write(
"%s %s %s\r" %
("Frame", frame, "of 246227."))
sys.stdout.flush()
sys.stdout.write("\n")
sys.stdout.flush()
return new_extract
def get_banner():
return """ ___ ___ __ __ ___
| /\ /\ |__ \_/ | |__) /\ / ` |
|___ /~~\ /~~\ |___ / \ | | \ /~~\ \__, |
"""
if __name__ == "__main__":
print get_banner()
if sys.platform == "darwin" or sys.platform.startswith("linux"):
home_dir = os.path.expanduser("~")
if len(sys.argv) > 1:
print "Using steam directory: %s" % sys.argv[1]
source = sys.argv[1]
elif sys.platform == "darwin":
source = home_dir + \
"/Library/Application Support/Steam/SteamApps/common"
else:
print "Usage: %s <path>" % sys.argv[0]
print "Where <path> is your SteamApps/common folder"
exit(1)
if not os.path.exists(source):
print "ERROR: Could not find your steam app folder at %s" % source
exit(1)
destination = home_dir + "/LAAextract"
if not os.path.exists(destination):
os.mkdir(destination)
print "The game files will be extracted to: " + destination + '\n'
if sys.platform == "darwin":
for game in mac:
extract_game_data(mac[game], source, destination)
else:
for game in pc:
extract_game_data(pc[game], source, destination)
print "\nDon't forget to convert the Loom Track1.wav to flac, ogg, or mp3!"
elif sys.platform == "win32" or sys.platform == "cygwin":
import win32gui
from win32com.shell import shell, shellcon
desktop_pidl = shell.SHGetFolderLocation(
0,
shellcon.CSIDL_DESKTOP,
0,
0)
pidl, display_name, image_list = shell.SHBrowseForFolder(
win32gui.GetDesktopWindow(),
desktop_pidl,
"Select your Steam Apps/common folder",
0,
None,
None
)
for game in pc:
extract_game_data(
pc[game],
shell.SHGetPathFromIDList(pidl),
shell.SHGetPathFromIDList(pidl))
raw_input("Press Enter to continue...")