Created
January 12, 2021 19:01
-
-
Save amPerl/b29ea264297253e2d37d4476a8c4b653 to your computer and use it in GitHub Desktop.
Extract Fatal Frame ContentFile.scc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import pathlib | |
def fatal(msg): | |
print(msg) | |
from sys import exit | |
exit(2) | |
def read_str(f): | |
str_length, *_ = struct.unpack("B", f.read(1)) | |
return f.read(str_length).decode() | |
with open("ContentFile.scc", "rb") as f: | |
header_str = read_str(f) | |
print("Header:", header_str) | |
if header_str != "scc": | |
fatal("oops wrong file?") | |
*_, entry_count = struct.unpack("<HI", f.read(6)) | |
print("Entries", entry_count) | |
entry_headers = [] | |
dirs_seen = set() | |
for entry_idx in range(entry_count): | |
entry_file_path = read_str(f) | |
content_str = read_str(f) | |
entry_length, *_ = struct.unpack("<II", f.read(8)) | |
print(entry_file_path, content_str, entry_length) | |
entry_headers.append((entry_file_path, content_str, entry_length)) | |
for entry_file_path, content_str, entry_length in entry_headers: | |
print("Entry Data:", entry_file_path, content_str) | |
something = struct.unpack("<I", f.read(4))[0] | |
file_buf = f.read(entry_length) | |
file_dir = "/".join(entry_file_path.split("/")[:-1]) | |
out_dir = "out" | |
file_out_dir = "{}/{}".format(out_dir, file_dir) | |
file_out_path = "{}/{}.xnb".format(out_dir, entry_file_path) | |
if file_out_dir not in dirs_seen: | |
print("Creating directory (if not exists):", file_out_dir) | |
pathlib.Path(file_out_dir).mkdir(parents=True, exist_ok=True) | |
dirs_seen.add(file_out_dir) | |
with open(file_out_path, "wb") as fout: | |
fout.write(file_buf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment