|
44 | 44 | from DK64R.randomizer.Lists.Location import PreGivenLocations |
45 | 45 | from worlds.LauncherComponents import Component, components, Type, icon_paths, local_path, launch as launch_component |
46 | 46 | import DK64R.randomizer.ShuffleExits as ShuffleExits |
| 47 | + from Utils import open_filename |
| 48 | + import shutil |
| 49 | + import zlib |
| 50 | + |
| 51 | + def crc32_of_file(file_path): |
| 52 | + """Compute CRC32 checksum of a file.""" |
| 53 | + crc_value = 0 |
| 54 | + with open(file_path, "rb") as f: |
| 55 | + for chunk in iter(lambda: f.read(4096), b""): |
| 56 | + crc_value = zlib.crc32(chunk, crc_value) |
| 57 | + return f"{crc_value & 0xFFFFFFFF:08X}" # Convert to 8-character hex |
47 | 58 |
|
48 | 59 | def launch_client(): |
49 | 60 | from .DK64Client import launch |
@@ -87,6 +98,32 @@ class DK64World(World): |
87 | 98 |
|
88 | 99 |
|
89 | 100 | def __init__(self, multiworld: MultiWorld, player: int): |
| 101 | + # Check if dk64.z64 exists, if it doesn't prompt the user to provide it |
| 102 | + # ANd then we will copy it to the root directory |
| 103 | + crc_values = ["D44B4FC6", "AA0A5979", "96972D67"] |
| 104 | + rom_file = "dk64.z64" |
| 105 | + if not os.path.exists(rom_file): |
| 106 | + print("Please provide a DK64 ROM file.") |
| 107 | + file = open_filename("Select DK64 ROM", (("N64 ROM", (".z64", ".n64")),)) |
| 108 | + if not file: |
| 109 | + raise FileNotFoundError("No ROM file selected.") |
| 110 | + crc = crc32_of_file(file) |
| 111 | + print(f"CRC32: {crc}") |
| 112 | + if crc not in crc_values: |
| 113 | + print("Invalid DK64 ROM file, please make sure your ROM is big endian.") |
| 114 | + raise FileNotFoundError("Invalid DK64 ROM file, please make sure your ROM is a vanilla DK64 file in big endian.") |
| 115 | + # Copy the file to the root directory |
| 116 | + try: |
| 117 | + shutil.copy(file, rom_file) |
| 118 | + except Exception as e: |
| 119 | + raise FileNotFoundError(f"Failed to copy ROM file, this may be a permissions issue: {e}") |
| 120 | + else: |
| 121 | + crc = crc32_of_file(rom_file) |
| 122 | + print(f"CRC32: {crc}") |
| 123 | + if crc not in crc_values: |
| 124 | + print("Invalid DK64 ROM file, please make sure your ROM is big endian.") |
| 125 | + raise FileNotFoundError("Invalid DK64 ROM file, please make sure your ROM is a vanilla DK64 file in big endian.") |
| 126 | + |
90 | 127 | self.rom_name_available_event = threading.Event() |
91 | 128 | super().__init__(multiworld, player) |
92 | 129 | # V1 LIMITATION: We are restricting settings pretty heavily. This string serves as the base for all seeds, with AP options overriding some options |
|
0 commit comments