Created
August 9, 2018 22:15
-
-
Save taotao54321/e916c9960b0d0b82974a94396b0a5594 to your computer and use it in GitHub Desktop.
ドクターマリオ (FC) 専用 bk2 -> fm2 変換
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """bk2 -> fm2 変換 (ドクターマリオ (FC) 専用) | |
| """ | |
| import io | |
| import re | |
| import sys | |
| import uuid | |
| import zipfile | |
| def from_bk2_input(s): | |
| # RLDUTSBA | |
| return [ | |
| s[3] != ".", | |
| s[2] != ".", | |
| s[1] != ".", | |
| s[0] != ".", | |
| s[4] != ".", | |
| s[5] != ".", | |
| s[6] != ".", | |
| s[7] != ".", | |
| ] | |
| def read_bk2(path): | |
| RE_INPUT = re.compile(r"^\|([^\|]{2})\|([^\|]{8})\|([^\|]{8})\|$") | |
| movie = [] | |
| with zipfile.ZipFile(path, "r") as bk2: | |
| with bk2.open("Input Log.txt", "r") as in_: | |
| for line in io.TextIOWrapper(in_): | |
| line = line.rstrip() | |
| match = RE_INPUT.search(line) | |
| if not match: continue | |
| movie.append([ | |
| match.group(1)[0] == "r", | |
| from_bk2_input(match.group(2)), | |
| from_bk2_input(match.group(3)), | |
| ]) | |
| return movie | |
| def to_fm2_keys(keys): | |
| return "".join([ | |
| "R" if keys[0] else ".", | |
| "L" if keys[1] else ".", | |
| "D" if keys[2] else ".", | |
| "U" if keys[3] else ".", | |
| "T" if keys[4] else ".", | |
| "S" if keys[5] else ".", | |
| "B" if keys[6] else ".", | |
| "A" if keys[7] else ".", | |
| ]) | |
| def to_fm2_line(inp): | |
| cmd = "1" if inp[0] else "0" | |
| keys1 = to_fm2_keys(inp[1]) | |
| keys2 = to_fm2_keys(inp[2]) | |
| return f"|{cmd}|{keys1}|{keys2}||\n" | |
| def write_fm2(path, movie): | |
| uuid_str = str(uuid.uuid4()).upper() | |
| with open(path, "w") as out: | |
| out.write(f"""\ | |
| version 3 | |
| emuVersion 22020 | |
| rerecordCount 0 | |
| palFlag 0 | |
| romFilename DrMario | |
| romChecksum base64:W0AfTKfhsSrz8p2Px1jdLw== | |
| guid {uuid_str} | |
| fourscore 0 | |
| microphone 0 | |
| port0 1 | |
| port1 1 | |
| port2 0 | |
| FDS 0 | |
| NewPPU 0 | |
| """) | |
| for inp in movie: | |
| out.write(to_fm2_line(inp)) | |
| def blank_input(): | |
| return [ False, [False]*8, [False]*8 ] | |
| def conv_movie(movie): | |
| res = [] | |
| for _ in range(2): | |
| res.append(blank_input()) | |
| for inp in movie: | |
| res.append(inp) | |
| if inp[0]: | |
| for i in range(2): | |
| res.append(blank_input()) | |
| return res | |
| def usage(): | |
| sys.exit("Usage: bk2tofm2 <bk2> <fm2>") | |
| def main(): | |
| if len(sys.argv) != 3: usage() | |
| path_in = sys.argv[1] | |
| path_out = sys.argv[2] | |
| movie = read_bk2(path_in) | |
| movie = conv_movie(movie) | |
| write_fm2(path_out, movie) | |
| if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment