Skip to content

Commit f925981

Browse files
committed
WINTERMUTE: Improve script decompiler
1 parent 425ed7a commit f925981

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

engines/wintermute/decompile_script.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
import sys
4040
import traceback
4141

42+
def safe_decode(b):
43+
for enc in ("cp1252", "latin-1", "utf-8"):
44+
try:
45+
return b.decode(enc)
46+
except UnicodeDecodeError:
47+
continue
48+
return b.decode("latin-1", errors="replace")
49+
4250
if len(sys.argv) == 1 or len(sys.argv) > 3:
4351
print("Usage: %s <path-to-compiled-script> [<path-to-inc-folder>]")
4452
sys.exit(-1)
@@ -157,7 +165,7 @@ def read_string(self):
157165
return result
158166

159167
def read_header(self):
160-
self.fname = self.data[32:self.offsets[2]].strip().decode("utf-8")
168+
self.fname = safe_decode(self.data[32:self.offsets[2]].strip())
161169
self.tables = {}
162170
self.externals = []
163171
for i,title in enumerate(self.table_names):

0 commit comments

Comments
 (0)