From 10d01c2ed9d885926d088200cf0ef88ca81f00d3 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Sat, 5 Oct 2024 03:19:18 +0100 Subject: [PATCH 1/3] Only send Set message for CurrentWorld when it changes --- worlds/kh2/Client.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/worlds/kh2/Client.py b/worlds/kh2/Client.py index e2d2338b7651..9f53d1670c43 100644 --- a/worlds/kh2/Client.py +++ b/worlds/kh2/Client.py @@ -110,6 +110,7 @@ def __init__(self, server_address, password): 18: TWTNW_Checks, # 255: {}, # starting screen } + self.last_world_int = -1 # 0x2A09C00+0x40 is the sve anchor. +1 is the last saved room # self.sveroom = 0x2A09C00 + 0x41 # 0 not in battle 1 in yellow battle 2 red battle #short @@ -408,13 +409,15 @@ def on_package(self, cmd: str, args: dict): async def checkWorldLocations(self): try: currentworldint = self.kh2_read_byte(self.Now) - await self.send_msgs([{ - "cmd": "Set", "key": "Slot: " + str(self.slot) + " :CurrentWorld", - "default": 0, "want_reply": True, "operations": [{ - "operation": "replace", - "value": currentworldint - }] - }]) + if self.last_world_int != currentworldint: + self.last_world_int = currentworldint + await self.send_msgs([{ + "cmd": "Set", "key": "Slot: " + str(self.slot) + " :CurrentWorld", + "default": 0, "want_reply": True, "operations": [{ + "operation": "replace", + "value": currentworldint + }] + }]) if currentworldint in self.worldid_to_locations: curworldid = self.worldid_to_locations[currentworldint] for location, data in curworldid.items(): From 3bcc396bf0229be30bf3002adda120436301fe5b Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Sat, 5 Oct 2024 03:20:34 +0100 Subject: [PATCH 2/3] Do not request a reply for Set messages The client does not have any special handling of the SetReply messages that would be received from the server in response to sending Set messages with want_reply=True. --- worlds/kh2/Client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/kh2/Client.py b/worlds/kh2/Client.py index 9f53d1670c43..ebcc86de0a56 100644 --- a/worlds/kh2/Client.py +++ b/worlds/kh2/Client.py @@ -413,7 +413,7 @@ async def checkWorldLocations(self): self.last_world_int = currentworldint await self.send_msgs([{ "cmd": "Set", "key": "Slot: " + str(self.slot) + " :CurrentWorld", - "default": 0, "want_reply": True, "operations": [{ + "default": 0, "want_reply": False, "operations": [{ "operation": "replace", "value": currentworldint }] From a1d899457fe62a1f09b7f3807f46e1c30d845749 Mon Sep 17 00:00:00 2001 From: Thomas Barlow Date: Sat, 5 Oct 2024 03:25:29 +0100 Subject: [PATCH 3/3] Only send LocationChecks when there are locations to send finishedGame() now reads ctx.sending directly instead of reading it from `message[0]["locations"]`. --- worlds/kh2/Client.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/worlds/kh2/Client.py b/worlds/kh2/Client.py index ebcc86de0a56..f33491f217a4 100644 --- a/worlds/kh2/Client.py +++ b/worlds/kh2/Client.py @@ -848,7 +848,7 @@ async def verifyItems(self): logger.info("line 840") -def finishedGame(ctx: KH2Context, message): +def finishedGame(ctx: KH2Context): if ctx.kh2slotdata['FinalXemnas'] == 1: if not ctx.final_xemnas and ctx.kh2_read_byte(ctx.Save + all_world_locations[LocationName.FinalXemnas].addrObtained) \ & 0x1 << all_world_locations[LocationName.FinalXemnas].bitIndex > 0: @@ -880,8 +880,9 @@ def finishedGame(ctx: KH2Context, message): elif ctx.kh2slotdata['Goal'] == 2: # for backwards compat if "hitlist" in ctx.kh2slotdata: + locations = ctx.sending for boss in ctx.kh2slotdata["hitlist"]: - if boss in message[0]["locations"]: + if boss in locations: ctx.hitlist_bounties += 1 if ctx.hitlist_bounties >= ctx.kh2slotdata["BountyRequired"] or ctx.kh2_seed_save_cache["AmountInvo"]["Amount"]["Bounty"] >= ctx.kh2slotdata["BountyRequired"]: if ctx.kh2_read_byte(ctx.Save + 0x36B3) < 1: @@ -922,11 +923,12 @@ async def kh2_watcher(ctx: KH2Context): await asyncio.create_task(ctx.verifyChests()) await asyncio.create_task(ctx.verifyItems()) await asyncio.create_task(ctx.verifyLevel()) - message = [{"cmd": 'LocationChecks', "locations": ctx.sending}] - if finishedGame(ctx, message) and not ctx.kh2_finished_game: + if finishedGame(ctx) and not ctx.kh2_finished_game: await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}]) ctx.kh2_finished_game = True - await ctx.send_msgs(message) + if ctx.sending: + message = [{"cmd": 'LocationChecks', "locations": ctx.sending}] + await ctx.send_msgs(message) elif not ctx.kh2connected and ctx.serverconneced: logger.info("Game Connection lost. waiting 15 seconds until trying to reconnect.") ctx.kh2 = None