Skip to content

Commit 5f5d4ec

Browse files
committed
Add APWorld version check prior to patching
1 parent 5a88641 commit 5f5d4ec

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Patch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
ModuleUpdate.update()
1010

1111
from worlds.Files import AutoPatchRegister, APAutoPatchInterface
12+
from worlds.AutoWorld import AutoWorldRegister
13+
from Utils import messagebox
1214

1315

1416
class RomMeta(TypedDict):
@@ -21,6 +23,14 @@ def create_rom_file(patch_file: str) -> Tuple[RomMeta, str]:
2123
auto_handler = AutoPatchRegister.get_handler(patch_file)
2224
if auto_handler:
2325
handler: APAutoPatchInterface = auto_handler(patch_file)
26+
handler.read()
27+
game_version = AutoWorldRegister.world_types[handler.game].world_version
28+
if handler.world_version and game_version != handler.world_version:
29+
info_msg = "This patch was generated with " \
30+
f"{handler.game} version {handler.world_version.as_simple_string()}, " \
31+
f"but its currently installed version is {game_version.as_simple_string()}. " \
32+
"You may encounter errors while patching or connecting."
33+
messagebox("APWorld version mismatch", info_msg, False)
2434
target = os.path.splitext(patch_file)[0]+handler.result_file_ending
2535
handler.patch(target)
2636
return {"server": handler.server,

worlds/Files.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def get_manifest(self) -> Dict[str, Any]:
221221
class APPlayerContainer(APContainer):
222222
"""A zipfile containing at least archipelago.json meant for a player"""
223223
game: ClassVar[Optional[str]] = None
224+
world_version: "Version | None" = None
224225
patch_file_ending: str = ""
225226

226227
player: Optional[int]
@@ -235,10 +236,13 @@ def __init__(self, path: Optional[str] = None, player: Optional[int] = None,
235236
self.server = server
236237

237238
def read_contents(self, opened_zipfile: zipfile.ZipFile) -> Dict[str, Any]:
239+
from Utils import tuplize_version
238240
manifest = super().read_contents(opened_zipfile)
239241
self.player = manifest["player"]
240242
self.server = manifest["server"]
241243
self.player_name = manifest["player_name"]
244+
if "world_version" in manifest:
245+
self.world_version = tuplize_version(manifest["world_version"])
242246
return manifest
243247

244248
def get_manifest(self) -> Dict[str, Any]:
@@ -250,6 +254,9 @@ def get_manifest(self) -> Dict[str, Any]:
250254
"game": self.game,
251255
"patch_file_ending": self.patch_file_ending,
252256
})
257+
if self.game:
258+
from .AutoWorld import AutoWorldRegister
259+
manifest["world_version"] = AutoWorldRegister.world_types[self.game].world_version.as_simple_string()
253260
return manifest
254261

255262

@@ -343,7 +350,6 @@ def write_file(self, file_name: str, file: bytes) -> None:
343350
self.files[file_name] = file
344351

345352
def patch(self, target: str) -> None:
346-
self.read()
347353
base_data = self.get_source_data_with_cache()
348354
patch_extender = AutoPatchExtensionRegister.get_handler(self.game)
349355
assert not isinstance(self.procedure, str), f"{type(self)} must define procedures"

0 commit comments

Comments
 (0)