Esempio n. 1
0
def draw_maps_main():
    global monster_bin_pack_file, monster_md
    os.makedirs(output_dir, exist_ok=True)

    rom = NintendoDSRom.fromFile(os.path.join(base_dir,
                                              'skyworkcopy_edit.nds'))
    monster_bin_pack_file = FileType.BIN_PACK.deserialize(
        rom.getFileByName('MONSTER/monster.bin'))
    monster_md = FileType.MD.deserialize(
        rom.getFileByName('BALANCE/monster.md'))

    script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))

    map_bg_entry_level_list = FileType.BG_LIST_DAT.deserialize(
        rom.getFileByName('MAP_BG/bg_list.dat')).level

    for script_map in script_info['maps'].values():
        # Map BGs are NOT *actually* mapped 1:1 to scripts. They are loaded via Opcode. However it turns out, using the BPL name
        # is an easy way to map them.
        map_bg_entry = next(x for x in map_bg_entry_level_list
                            if x.bpl_name == script_map['name'])
        if script_map['enter_sse'] is not None:
            process(
                rom, map_bg_entry, script_map['name'], SCRIPT_DIR + '/' +
                script_map['name'] + '/' + script_map['enter_sse'])
        for ssa, _ in script_map['ssas']:
            process(rom, map_bg_entry, script_map['name'],
                    SCRIPT_DIR + '/' + script_map['name'] + '/' + ssa)
        for sss in script_map['subscripts'].keys():
            process(rom, map_bg_entry, script_map['name'],
                    SCRIPT_DIR + '/' + script_map['name'] + '/' + sss)
async def main(executor):
    output_dir = os.path.join(os.path.dirname(__file__), 'dbg_output')
    base_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..',
                            '..')
    os.makedirs(output_dir, exist_ok=True)

    rom = NintendoDSRom.fromFile(
        os.path.join(base_dir, 'skyworkcopy_us_unpatched.nds'))

    script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))

    # total, opening. decompiling, parsing, compiling, serializing
    times: List[Tuple[float, float, float, float, float, float]] = []

    static_data = Pmd2XmlReader.load_default(for_version='EoS_NA')
    awaitables = []
    for i, file_name in enumerate(get_files_from_rom_with_extension(
            rom, 'ssb')):
        # TODO: Those scripts fail for JP.
        if file_name in [
                'SCRIPT/D42P21A/enter23.ssb', 'SCRIPT/D73P11A/us0303.ssb',
                'SCRIPT/D73P11A/us0305.ssb', 'SCRIPT/D73P11A/us2003.ssb',
                'SCRIPT/D73P11A/us2005.ssb', 'SCRIPT/D73P11A/us2103.ssb',
                'SCRIPT/D73P11A/us2105.ssb', 'SCRIPT/D73P11A/us2203.ssb',
                'SCRIPT/D73P11A/us2205.ssb', 'SCRIPT/D73P11A/us2303.ssb',
                'SCRIPT/D73P11A/us2305.ssb'
        ]:
            continue
        # Run multiple in parallel with asyncio executors.
        awaitables.append(
            loop.run_in_executor(executor, process_single, file_name, times,
                                 static_data, output_dir, rom))

    pending = awaitables
    while len(pending) > 0:
        done, pending = await asyncio.wait(pending,
                                           return_when=asyncio.FIRST_COMPLETED)
        # to raise exceptions of tasks back to main loop:
        for fut in done:
            try:
                fut.result()
            except Exception:
                loop.stop()
                with poison_lock:
                    poison_container[0] = True
                raise

    times_structured = list(zip(*times))

    print_table_row("", "TOTAL", "OPENING", "DECOMPILING", "PARSING",
                    "COMPILING", "SERIALIZING")
    print_table_row(*(["==========="] * 7))
    print_table_row("TOTAL:", *[round(sum(t), 2) for t in times_structured])
    print_table_row("AVG:",
                    *[round(sum(t) / len(t), 2) for t in times_structured])
    print_table_row("MAX:", *[round(max(t), 2) for t in times_structured])
    print_table_row("MIN:", *[round(min(t), 2) for t in times_structured])
def main():
    os.makedirs(output_dir, exist_ok=True)

    rom = NintendoDSRom.fromFile(os.path.join(base_dir, 'skyworkcopy.nds'))

    script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))

    for script_map in script_info['maps'].values():
        if script_map['enter_sse'] is not None:
            process(rom, SCRIPT_DIR + '/' + script_map['name'] + '/', script_map['enter_sse'], script_map['enter_ssbs'])
        for ssa, ssb in script_map['ssas']:
            process(rom, SCRIPT_DIR + '/' + script_map['name'] + '/', ssa, [ssb])
        for sss, ssb in script_map['subscripts'].items():
            process(rom, SCRIPT_DIR + '/' + script_map['name'] + '/', sss, ssb)
Esempio n. 4
0
def main():
    os.makedirs(output_dir, exist_ok=True)

    rom = NintendoDSRom.fromFile(os.path.join(base_dir, 'skyworkcopy.nds'))

    script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))

    for script_map in script_info['maps'].values():
        # Map BGs are NOT *actually* mapped 1:1 to scripts. They are loaded via Opcode. However it turns out, using the BPL name
        # is an easy way to map them.
        if script_map['enter_sse'] is not None:
            process(
                rom, script_map['name'], SCRIPT_DIR + '/' +
                script_map['name'] + '/' + script_map['enter_sse'])
        for ssa, _ in script_map['ssas']:
            process(rom, script_map['name'],
                    SCRIPT_DIR + '/' + script_map['name'] + '/' + ssa)
        for sss in script_map['subscripts'].keys():
            process(rom, script_map['name'],
                    SCRIPT_DIR + '/' + script_map['name'] + '/' + sss)
Esempio n. 5
0
def draw_maps(rom: NintendoDSRom, map_dir, scriptdata: Pmd2ScriptData):
    script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))
    count = len(script_info['maps'])
    for i, script_map in enumerate(script_info['maps'].values()):
        if script_map['enter_sse'] is not None:
            draw_scenes_for(rom, i, count,
                            os.path.join(map_dir, script_map['name'], script_map['enter_sse']),
                            script_map['name'], script_map['enter_sse'],
                            SCRIPT_DIR + '/' + script_map['name'] + '/' + script_map['enter_sse'],
                            scriptdata)
        for ssa, _ in script_map['ssas']:
            draw_scenes_for(rom, i, count,
                            os.path.join(map_dir, script_map['name'], ssa),
                            script_map['name'], ssa,
                            SCRIPT_DIR + '/' + script_map['name'] + '/' + ssa,
                            scriptdata)
        for sss in script_map['subscripts'].keys():
            draw_scenes_for(rom, i, count,
                            os.path.join(map_dir, script_map['name'], sss),
                            script_map['name'], sss,
                            SCRIPT_DIR + '/' + script_map['name'] + '/' + sss,
                            scriptdata)
Esempio n. 6
0
 def load_script_files(self) -> ScriptFiles:
     return load_script_files(get_rom_folder(self._rom,
                                             SCRIPT_DIR))  # type: ignore
Esempio n. 7
0
#
#  You should have received a copy of the GNU General Public License
#  along with SkyTemple.  If not, see <https://www.gnu.org/licenses/>.
# mypy: ignore-errors
import os

from ndspy.rom import NintendoDSRom

from skytemple_files.common.script_util import load_script_files, SCRIPT_DIR
from skytemple_files.common.util import get_rom_folder
from skytemple_files.script.lsd.handler import LsdHandler

base_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..',
                        '..')

rom = NintendoDSRom.fromFile(os.path.join(base_dir, 'skyworkcopy.nds'))

script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))

for map_name, map in script_info['maps'].items():
    if map['lsd'] is not None:
        lsd_name = SCRIPT_DIR + '/' + map_name + '/' + map['lsd']

        bin_before = rom.getFileByName(lsd_name)
        lsd = LsdHandler.deserialize(bin_before)

        print(f"{lsd_name}: {lsd.entries}")

        bin_after = LsdHandler.serialize(lsd)
        assert bin_before == bin_after
Esempio n. 8
0
 def get_rom_folder(self, path):
     return get_rom_folder(self._rom, path)
def main():
    output_dir = os.path.join(os.path.dirname(__file__), 'dbg_output')
    base_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..',
                            '..')
    os.makedirs(output_dir, exist_ok=True)

    rom = NintendoDSRom.fromFile(os.path.join(base_dir, 'skyworkcopy.nds'))

    script_info = load_script_files(get_rom_folder(rom, SCRIPT_DIR))

    # total, opening. decompiling, parsing, compiling, serializing
    times: List[Tuple[float, float, float, float, float, float]] = []

    for i, file_name in enumerate(get_files_from_rom_with_extension(
            rom, 'ssb')):
        print(file_name)

        out_file_name = os.path.join(output_dir,
                                     file_name.replace('/', '_') + '.ssbs')

        time_before = time.time()
        bin_before = rom.getFileByName(file_name)
        time_opening = time.time()
        ssb_before = SsbHandler.deserialize(bin_before)
        ssb_script, source_map_before = ssb_before.to_ssb_script()
        time_decompiling = time.time()

        for pos_mark in source_map_before.get_position_marks__direct():
            print(pos_mark)

        with open(out_file_name, 'w') as f:
            f.write(ssb_script)

        # Test the compiling and writing, by compiling the model, writing it to binary, and then loading it again,
        # and checking the generated ssb script.
        compiler = ScriptCompiler(Pmd2XmlReader.load_default())
        time_parsing = 0

        def callback_after_parsing():
            nonlocal time_parsing
            time_parsing = time.time()

        ssb_after, source_map_after = compiler.compile_ssbscript(
            ssb_script, callback_after_parsing)
        time_compiling = time.time()

        bin_after = SsbHandler.serialize(ssb_after)
        time_serializing = time.time()
        ssb_after_after = SsbHandler.deserialize(bin_after)
        ssb_script_after = ssb_after_after.to_ssb_script()[0]

        with open('/tmp/diff1.ssb', 'w') as f:
            f.write(ssb_script)

        with open('/tmp/diff2.ssb', 'w') as f:
            f.write(ssb_script_after)

        assert (ssb_script == ssb_script_after)
        assert (source_map_before == source_map_after)

        times.append((
            time_serializing - time_before,  # total
            time_opening - time_before,  # opening.
            time_decompiling - time_opening,  # decompiling,
            time_parsing - time_decompiling,  # parsing,
            time_compiling - time_parsing,  # compiling,
            time_serializing - time_compiling,  # serializing
        ))

    times_structured = list(zip(*times))

    print_table_row("", "TOTAL", "OPENING", "DECOMPILING", "PARSING",
                    "COMPILING", "SERIALIZING")
    print_table_row(*(["==========="] * 7))
    print_table_row("TOTAL:", *[round(sum(t), 2) for t in times_structured])
    print_table_row("AVG:",
                    *[round(sum(t) / len(t), 2) for t in times_structured])
    print_table_row("MAX:", *[round(max(t), 2) for t in times_structured])
    print_table_row("MIN:", *[round(min(t), 2) for t in times_structured])