Example #1
0
    def from_readable(self, readable):
        parser = formats.dcc.DCCParser()
        try:
            parser.parse(readable)
        except Exception as e:
            return False, str(e)

        required_paths = ["pzd.title", "pzd.type", "pzd.number", "pzd.text",  "pzd.correct_answer",
                          "pzd.incorrect_answer", "pzd.hint1", "pzd.hint2", "pzd.hint3", "pzd.tutorial_id",
                          "pzd.reward_id", "pzd.bg_btm_id", "pzd.bg_top_id", "pzd.judge_char", "pzd.flag_bit2",
                          "pzd.flag_bit5", "pzd.location_id", "pzd.picarat_decay", "pzd.bg_lang", "pzd.ans_bg_lang",
                          "pzs"]

        for req_path in required_paths:
            if not parser.exists(req_path):
                return False, f"Missing {req_path}"

        self.title = parser["pzd.title"]
        self.type = parser["pzd.type"]
        self.number = parser["pzd.number"]
        self.text = subs.convert_substitutions(parser["pzd.text"], puzzle=True)
        self.correct_answer = subs.convert_substitutions(parser["pzd.correct_answer"],
                                                         puzzle=True)
        self.incorrect_answer = subs.convert_substitutions(parser["pzd.incorrect_answer"], puzzle=True)
        self.hint1 = subs.convert_substitutions(parser["pzd.hint1"], puzzle=True)
        self.hint2 = subs.convert_substitutions(parser["pzd.hint2"], puzzle=True)
        self.hint3 = subs.convert_substitutions(parser["pzd.hint3"], puzzle=True)

        self.tutorial_id = parser["pzd.tutorial_id"]
        self.reward_id = parser["pzd.reward_id"]
        self.bg_btm_id = parser["pzd.bg_btm_id"]
        self.bg_top_id = parser["pzd.bg_top_id"]
        self.judge_char = parser["pzd.judge_char"]
        self.flag_bit2 = parser["pzd.flag_bit2"]
        self.flag_bit5 = parser["pzd.flag_bit5"]
        self.location_id = parser["pzd.location_id"]
        self.picarat_decay = []
        for picarat in parser["pzd.picarat_decay::unnamed"]:
            self.picarat_decay.append(picarat)

        self.bg_lang = parser["pzd.bg_lang"]
        self.ans_bg_lang = parser["pzd.ans_bg_lang"]
        self.gds.commands = []
        gds_parser = self.get_gds_parser()
        for command_call in parser["pzs::calls"]:
            try:
                self.gds.commands.append(formats.gds.GDSCommand(
                    command=gds_parser.reverse_command_name(command_call["func"]),
                    params=command_call["parameters"]
                ))
            except Exception as e:
                return False, str(e)
        return True, ""
Example #2
0
    def revert_command_(func, params, ev=None):
        command = formats.gds.GDSCommand(0)
        params = params.copy()
        if func == "fade" or func == Event.func_names["fade"]:
            if params[0] is True:  # [0x2, 0x32, 0x80, 0x88]
                if params[1] == 2:  # [0x2, 0x80]
                    if params[2] is None or params[2] == -1:  # [0x2]
                        command.command = 0x2
                    else:  # [0x80]
                        command.command = 0x80
                elif params[1] == 0:  # [0x32]
                    command.command = 0x32
                elif params[1] == 1:  # [0x88]
                    command.command = 0x88
                    if params[2] is None or params[2] == -1:
                        params[2] = 42
            else:  # [0x3, 0x33, 0x72, 0x87]
                if params[1] == 2:  # [0x3, 0x72]
                    if params[2] is None or params[2] == -1:  # [0x3]
                        command.command = 0x3
                    else:  # [0x72]
                        command.command = 0x72
                elif params[1] == 0:  # [0x33]
                    command.command = 0x33
                elif params[1] == 1:  # [0x87]
                    command.command = 0x87
                    if params[2] is None or params[2] == -1:
                        params[2] = 42
            if command.command in [0x72, 0x80, 0x87, 0x88]:
                command.params = params[2:]
        elif func == "set_room" or func == Event.func_names["set_room"]:
            command.command = 0x5
            command.params = params
        elif func == "set_mode" or func == Event.func_names["set_mode"]:
            command.command = 0x6
            command.params = params
        elif func == "set_next_mode" or func == Event.func_names[
                "set_next_mode"]:
            command.command = 0x7
            command.params = params
        elif func == "set_movie" or func == Event.func_names["set_movie"]:
            command.command = 0x8
            command.params = params
        elif func == "set_event" or func == Event.func_names["set_event"]:
            command.command = 0x9
            command.params = params
        elif func == "set_puzzle" or func == Event.func_names["set_puzzle"]:
            command.command = 0xb
            command.params = params
        elif func == "bg_load" or func == Event.func_names["bg_load"]:
            command.command = 0x21 if params[-1] == 0 else 0x22
            command.params = [params[0], 3]
        elif func == "chr_show" or func == Event.func_names["chr_show"]:
            command.command = 0x2a
            command.params = params
        elif func == "chr_hide" or func == Event.func_names["chr_hide"]:
            command.command = 0x2b
            command.params = params
        elif func == "chr_visibility" or func == Event.func_names[
                "chr_visibility"]:
            command.command = 0x2c
            params[1] = 2.0 if params[1] else -2.0
            command.params = params
        elif func == "show_chapter" or func == Event.func_names["show_chapter"]:
            command.command = 0x2d
            command.params = params
        elif func == "chr_slot" or func == Event.func_names["chr_slot"]:
            command.command = 0x30
            command.params = params
        elif func == "wait" or func == Event.func_names["wait"]:
            command.command = 0x31
            command.params = params
        elif func == "bg_opacity" or func == Event.func_names["bg_opacity"]:
            command.command = 0x37
            command.params = params
        elif func == "chr_anim" or func == Event.func_names["chr_anim"]:
            command.command = 0x3f
            command.params = params
        elif func == "set_voice" or func == Event.func_names["set_voice"]:
            command.command = 0x5c
            command.params = params
        elif func == "sfx_sad" or func == Event.func_names["sfx_sad"]:
            command.command = 0x5d
            command.params = params
        elif func == "sfx_sed" or func == Event.func_names["sfx_sed"]:
            command.command = 0x5e
            command.params = params
        elif func == "bg_music" or func == Event.func_names["bg_music"]:
            command.command = 0x62
            command.params = params
        elif func == "wait_tap" or func == Event.func_names["wait_tap"]:
            command.command = 0x69
            command.params = params
        elif func == "bg_shake" or func == Event.func_names["bg_shake"]:
            command.command = 0x6a
            command.params = params
        elif func == "bgm_fade_out" or func == Event.func_names["bgm_fade_out"]:
            command.command = 0x8a
            command.params = params
        elif func == "bgm_fade_in" or func == Event.func_names["bgm_fade_in"]:
            command.command = 0x8b
            command.params = params
        elif func == "dialogue_sfx" or func == Event.func_names["dialogue_sfx"]:
            command.command = 0x99
            command.params = params
        elif func == "dial" or func == Event.func_names["dial"]:
            command.command = 0x4
            command.params = [params[0]]

            dial_gds = formats.gds.GDS()
            dial_gds.params = params[1:]
            dial_gds.params[4] = subs.convert_substitutions(dial_gds.params[4])

            if ev:
                ev.texts[params[0]] = dial_gds
        elif func.startswith("gds_"):
            command.command = int(func[4:], 16)
            command.params = params
        else:
            return False, f"Function {repr(func)} not found"
        return command
Example #3
0
    def from_readable(self, readable):
        parser = dcc.Parser()
        try:
            parser.parse(readable)
        except Exception as e:
            return False, str(e)

        required_paths = ["evdat.map_top_id", "evdat.map_btm_id", "evs"]
        for i in range(8):
            required_paths.extend([f"evdat.char{i}.char", f"evdat.char{i}.pos", f"evdat.char{i}.shown",
                                   f"evdat.char{i}.anim"])

        for req_path in required_paths:
            if not parser.exists(req_path):
                return False, f"Missing {req_path}"

        self.map_top_id = parser["evdat.map_top_id"]
        self.map_bottom_id = parser["evdat.map_btm_id"]

        for i in range(8):
            self.characters[i] = parser[f"evdat.char{i}.char"]
            self.characters_pos[i] = parser[f"evdat.char{i}.pos"]
            self.characters_shown[i] = parser[f"evdat.char{i}.shown"]
            self.characters_anim_index[i] = parser[f"evdat.char{i}.anim"]

        dial_files = self.event_texts.filenames
        prefix, postfix, complete = self.resolve_event_id()
        for filename in dial_files:
            if filename.startswith(f"e{prefix}_{postfix}"):
                self.event_texts.remove_file(filename)

        self.event_gds.commands = []
        for call in parser["evs::calls"]:
            func = call["func"]
            params = call["parameters"]
            command = formats.gds.GDSCommand(0)
            if func == "fade":
                if params[0] is True:  # [0x2, 0x32, 0x80, 0x88]
                    if params[1] == 2:  # [0x2, 0x80]
                        if params[2] is None:  # [0x2]
                            command.command = 0x2
                        else:  # [0x80]
                            command.command = 0x80
                    elif params[1] == 0:  # [0x32]
                        command.command = 0x32
                    elif params[1] == 1:  # [0x88]
                        command.command = 0x88
                else:  # [0x3, 0x33, 0x72, 0x87]
                    if params[1] == 2:  # [0x3, 0x72]
                        if params[2] is None:  # [0x3]
                            command.command = 0x3
                        else:  # [0x72]
                            command.command = 0x72
                    elif params[1] == 0:  # [0x33]
                        command.command = 0x33
                    elif params[1] == 1:  # [0x87]
                        command.command = 0x87
                if command.command in [0x72, 0x80, 0x87, 0x88]:
                    command.params = params[2:]
            elif func == "set_room":
                command.command = 0x5
                command.params = params
            elif func == "set_mode":
                command.command = 0x6
                command.params = params
            elif func == "set_next_mode":
                command.command = 0x7
                command.params = params
            elif func == "set_movie":
                command.command = 0x8
                command.params = params
            elif func == "set_event":
                command.command = 0x9
                command.params = params
            elif func == "set_puzzle":
                command.command = 0xb
                command.params = params
            elif func == "bg_load":
                command.command = 0x21 if params[-1] == 0 else 0x22
                command.params = [params[0], 3]
            elif func == "chr_show":
                command.command = 0x2a
                command.params = params
            elif func == "chr_hide":
                command.command = 0x2b
                command.params = params
            elif func == "chr_visibility":
                command.command = 0x2c
                params[1] = 2.0 if params[1] else -2.0
                command.params = params
            elif func == "show_chapter":
                command.command = 0x2d
                command.params = params
            elif func == "chr_slot":
                command.command = 0x30
                command.params = params
            elif func == "wait":
                command.command = 0x31
                command.params = params
            elif func == "bg_opacity":
                command.command = 0x37
                command.params = params
            elif func == "chr_anim":
                command.command = 0x3f
                command.params = params
            elif func == "set_voice":
                command.command = 0x5c
                command.params = params
            elif func == "sfx_sad":
                command.command = 0x5d
                command.params = params
            elif func == "bg_music":
                command.command = 0x62
                command.params = params
            elif func == "bg_shake":
                command.command = 0x6a
                command.params = params
            elif func == "dial":
                command.command = 0x4
                command.params = [params[0]]

                dial_gds = formats.gds.GDS()
                dial_gds.params = params[1:]
                dial_gds.params[4] = subs.convert_substitutions(dial_gds.params[4])

                prefix, postfix, complete = self.resolve_event_id()
                dial_gds_file = self.event_texts.open(f"t{prefix}_{postfix}_{params[0]}.gds", "wb+")
                dial_gds.write_stream(dial_gds_file)
                dial_gds_file.close()
            elif func.startswith("gds_"):
                command.command = int(func[4:], 16)
                command.params = params
            else:
                return False, f"Function {repr(func)} not found"
            self.event_gds.commands.append(command)
        return True, ""