KH2: fixed bugs of rc1 (#1565)

KH2Client:
- Now checks if the world id is in the list of checks. This fixed sending out stuff on the movie
- Cleaned up unused inports
- Not getting starting invo if the game is not open when you connect to the server

__init__:
-Cleaned up print statements
- Fixed the spoiler log not outputting the right amount of mcguffins after fixing them in the case of the player messing up their settings

Openkh:
-Fixed putting the correct dummy item on levels
This commit is contained in:
JaredWeakStrike 2023-03-22 10:21:41 -04:00 committed by GitHub
parent 0c6b1827fe
commit 206f8cf5ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 29 deletions

View File

@ -1,11 +1,10 @@
import os import os
import asyncio import asyncio
import ModuleUpdate import ModuleUpdate
import typing
import json import json
import Utils import Utils
from pymem import pymem from pymem import pymem
from worlds.kh2.Items import DonaldAbility_Table, GoofyAbility_Table, exclusionItem_table, CheckDupingItems from worlds.kh2.Items import exclusionItem_table, CheckDupingItems
from worlds.kh2 import all_locations, item_dictionary_table, exclusion_table from worlds.kh2 import all_locations, item_dictionary_table, exclusion_table
from worlds.kh2.WorldLocations import * from worlds.kh2.WorldLocations import *
@ -89,6 +88,7 @@ class KH2Context(CommonContext):
"StatIncrease": {}, "StatIncrease": {},
"Boost": {}, "Boost": {},
}}, }},
# 1,3,255 are in this list in case the player gets locations in those "worlds" and I need to still have them checked
"worldIdChecks": { "worldIdChecks": {
"1": [], # world of darkness (story cutscenes) "1": [], # world of darkness (story cutscenes)
"2": [], "2": [],
@ -136,9 +136,9 @@ class KH2Context(CommonContext):
self.game_connected = False self.game_connected = False
self.finalxemnas = False self.finalxemnas = False
self.worldid = { self.worldid = {
1: TWTNW_Checks, # world of darkness (story cutscenes) # 1: {}, # world of darkness (story cutscenes)
2: TT_Checks, 2: TT_Checks,
3: TT_Checks, # destiny island doesn't have checks to ima put tt checks here # 3: {}, # destiny island doesn't have checks to ima put tt checks here
4: HB_Checks, 4: HB_Checks,
5: BC_Checks, 5: BC_Checks,
6: Oc_Checks, 6: Oc_Checks,
@ -154,7 +154,7 @@ class KH2Context(CommonContext):
16: PR_Checks, 16: PR_Checks,
17: SP_Checks, 17: SP_Checks,
18: TWTNW_Checks, 18: TWTNW_Checks,
255: HB_Checks, # starting screen # 255: {}, # starting screen
} }
# 0x2A09C00+0x40 is the sve anchor. +1 is the last saved room # 0x2A09C00+0x40 is the sve anchor. +1 is the last saved room
self.sveroom = 0x2A09C00 + 0x41 self.sveroom = 0x2A09C00 + 0x41
@ -304,22 +304,22 @@ class KH2Context(CommonContext):
if item.location not in self.kh2seedsave["checked_locations"][str(item.player)] \ if item.location not in self.kh2seedsave["checked_locations"][str(item.player)] \
and item.location not in {-1, -2}: and item.location not in {-1, -2}:
self.kh2seedsave["checked_locations"][str(item.player)].append(item.location) self.kh2seedsave["checked_locations"][str(item.player)].append(item.location)
if not self.kh2seedsave["starting_inventory"] and self.kh2connected: if not self.kh2seedsave["starting_inventory"]:
self.kh2seedsave["starting_inventory"] = True self.kh2seedsave["starting_inventory"] = True
if cmd in {"RoomUpdate"}: if cmd in {"RoomUpdate"}:
if "checked_locations" in args: if "checked_locations" in args:
new_locations = set(args["checked_locations"]) new_locations = set(args["checked_locations"])
# TODO: make this take locations from other players on the same slot so proper coop happens # TODO: make this take locations from other players on the same slot so proper coop happens
#items_to_give = [self.kh2slotdata["LocalItems"][str(location_id)] for location_id in new_locations if # items_to_give = [self.kh2slotdata["LocalItems"][str(location_id)] for location_id in new_locations if
# location_id in self.kh2LocalItems.keys()] # location_id in self.kh2LocalItems.keys()]
self.checked_locations |= new_locations self.checked_locations |= new_locations
async def checkWorldLocations(self): async def checkWorldLocations(self):
try: try:
currentworldint = int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + 0x0714DB8, 1), "big") currentworldint = int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + 0x0714DB8, 1), "big")
curworldid = self.worldid[currentworldint] if currentworldint in self.worldid:
if currentworldint != 1: curworldid = self.worldid[currentworldint]
for location, data in curworldid.items(): for location, data in curworldid.items():
if location not in self.locations_checked \ if location not in self.locations_checked \
and (int.from_bytes( and (int.from_bytes(
@ -442,16 +442,9 @@ class KH2Context(CommonContext):
return isChecked return isChecked
async def give_item(self, item, ItemType="ServerItems"): async def give_item(self, item, ItemType="ServerItems"):
while not self.kh2connected:
await asyncio.sleep(1)
try: try:
itemname = self.lookup_id_to_item[item] itemname = self.lookup_id_to_item[item]
itemcode = self.item_name_to_data[itemname] itemcode = self.item_name_to_data[itemname]
# cannot give items during loading screens
# 0x8E9DA3=load 0xAB8BC7=black 0x2A148E8=controllable 0x715568=room transition
while int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Now, 1), "big") in {255, 1}:
await asyncio.sleep(1)
if itemcode.ability: if itemcode.ability:
abilityInvoType = 0 abilityInvoType = 0
TwilightZone = 2 TwilightZone = 2
@ -459,7 +452,6 @@ class KH2Context(CommonContext):
abilityInvoType = 1 abilityInvoType = 1
TwilightZone = -2 TwilightZone = -2
if itemname in {"High Jump", "Quick Run", "Dodge Roll", "Aerial Dodge", "Glide"}: if itemname in {"High Jump", "Quick Run", "Dodge Roll", "Aerial Dodge", "Glide"}:
self.kh2seedsave["AmountInvo"][ItemType]["Growth"][itemname] += 1 self.kh2seedsave["AmountInvo"][ItemType]["Growth"][itemname] += 1
return return
@ -609,7 +601,6 @@ class KH2Context(CommonContext):
for itemName in master_keyblade: for itemName in master_keyblade:
itemData = self.item_name_to_data[itemName] itemData = self.item_name_to_data[itemName]
# if isChecked:
# if the inventory slot for that keyblade is less than the amount they should have # if the inventory slot for that keyblade is less than the amount they should have
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1), if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
"big") <= 0: "big") <= 0:

View File

@ -195,7 +195,7 @@ def patch_kh2(self, output_directory):
if data.item.player == self.player: if data.item.player == self.player:
itemcode = item_dictionary_table[data.item.name].kh2id itemcode = item_dictionary_table[data.item.name].kh2id
else: else:
itemcode = 461 itemcode = 90 # castle map
else: else:
increaseStat(self.multiworld.per_slot_randoms[self.player].randint(0, 3)) increaseStat(self.multiworld.per_slot_randoms[self.player].randint(0, 3))
itemcode = 0 itemcode = 0

View File

@ -1,6 +1,6 @@
from BaseClasses import Tutorial, ItemClassification from BaseClasses import Tutorial, ItemClassification
import logging
from .Items import * from .Items import *
from .Locations import all_locations, setup_locations, exclusion_table from .Locations import all_locations, setup_locations, exclusion_table
@ -97,7 +97,8 @@ class KH2World(World):
if item in ActionAbility_Table.keys() or item in SupportAbility_Table.keys(): if item in ActionAbility_Table.keys() or item in SupportAbility_Table.keys():
# cannot have more than the quantity for abilties # cannot have more than the quantity for abilties
if value > item_dictionary_table[item].quantity: if value > item_dictionary_table[item].quantity:
print(f"{self.multiworld.get_file_safe_player_name(self.player)} cannot have more than {item_dictionary_table[item].quantity} of {item}") logging.info(f"{self.multiworld.get_file_safe_player_name(self.player)} cannot have more than {item_dictionary_table[item].quantity} of {item}"
f"Changing the amount to the max amount")
value = item_dictionary_table[item].quantity value = item_dictionary_table[item].quantity
self.item_quantity_dict[item] -= value self.item_quantity_dict[item] -= value
@ -128,9 +129,12 @@ class KH2World(World):
luckyemblemamount = self.multiworld.LuckyEmblemsAmount[self.player].value luckyemblemamount = self.multiworld.LuckyEmblemsAmount[self.player].value
luckyemblemrequired = self.multiworld.LuckyEmblemsRequired[self.player].value luckyemblemrequired = self.multiworld.LuckyEmblemsRequired[self.player].value
if luckyemblemamount < luckyemblemrequired: if luckyemblemamount < luckyemblemrequired:
logging.info(f"Lucky Emblem Amount {self.multiworld.LuckyEmblemsAmount[self.player].value} is less than required "
f"{self.multiworld.LuckyEmblemsRequired[self.player].value} for player {self.multiworld.get_file_safe_player_name(self.player)}."
f" Setting amount to {self.multiworld.LuckyEmblemsRequired[self.player].value}")
luckyemblemamount = max(luckyemblemamount, luckyemblemrequired) luckyemblemamount = max(luckyemblemamount, luckyemblemrequired)
print(f"Lucky Emblem Amount {self.multiworld.LuckyEmblemsAmount[self.player].value} is less than required \ self.multiworld.LuckyEmblemsAmount[self.player].value = luckyemblemamount
{self.multiworld.LuckyEmblemsRequired[self.player].value} for player {self.multiworld.get_file_safe_player_name(self.player)}")
self.item_quantity_dict[ItemName.LuckyEmblem] = item_dictionary_table[ItemName.LuckyEmblem].quantity + luckyemblemamount self.item_quantity_dict[ItemName.LuckyEmblem] = item_dictionary_table[ItemName.LuckyEmblem].quantity + luckyemblemamount
# give this proof to unlock the final door once the player has the amount of lucky emblem required # give this proof to unlock the final door once the player has the amount of lucky emblem required
self.item_quantity_dict[ItemName.ProofofNonexistence] = 0 self.item_quantity_dict[ItemName.ProofofNonexistence] = 0
@ -146,19 +150,23 @@ class KH2World(World):
self.RandomSuperBoss.remove(location) self.RandomSuperBoss.remove(location)
# Testing if the player has the right amount of Bounties for Completion. # Testing if the player has the right amount of Bounties for Completion.
if len(self.RandomSuperBoss) < self.BountiesAmount: if len(self.RandomSuperBoss) < self.BountiesAmount:
print(f"{self.multiworld.get_file_safe_player_name(self.player)} has too many bounties than bosses") logging.info(f"{self.multiworld.get_file_safe_player_name(self.player)} has too many bounties than bosses."
f" Setting total bounties to {len(self.RandomSuperBoss)}")
self.BountiesAmount = len(self.RandomSuperBoss) self.BountiesAmount = len(self.RandomSuperBoss)
self.multiworld.BountyAmount[self.player].value = len(self.RandomSuperBoss) self.multiworld.BountyAmount[self.player].value = self.BountiesAmount
if len(self.RandomSuperBoss) < self.BountiesRequired: if len(self.RandomSuperBoss) < self.BountiesRequired:
print(f"{self.multiworld.get_file_safe_player_name(self.player)} has too many required bounties") logging.info(f"{self.multiworld.get_file_safe_player_name(self.player)} has too many required bounties."
f" Setting required bounties to {len(self.RandomSuperBoss)}")
self.BountiesRequired = len(self.RandomSuperBoss) self.BountiesRequired = len(self.RandomSuperBoss)
self.multiworld.BountyRequired[self.player].value = len(self.RandomSuperBoss) self.multiworld.BountyRequired[self.player].value = self.BountiesRequired
if self.BountiesAmount < self.BountiesRequired: if self.BountiesAmount < self.BountiesRequired:
logging.info(f"Bounties Amount {self.multiworld.BountyAmount[self.player].value} is less than required "
f"{self.multiworld.BountyRequired[self.player].value} for player {self.multiworld.get_file_safe_player_name(self.player)}."
f" Setting amount to {self.multiworld.BountyRequired[self.player].value}")
self.BountiesAmount = max(self.BountiesAmount, self.BountiesRequired) self.BountiesAmount = max(self.BountiesAmount, self.BountiesRequired)
print(f"Bounties Amount {self.multiworld.BountyAmount[self.player].value} is less than required \ self.multiworld.BountyAmount[self.player].value = self.BountiesAmount
{self.multiworld.BountyRequired[self.player].value} for player {self.multiworld.get_file_safe_player_name(self.player)}")
self.multiworld.start_hints[self.player].value.add(ItemName.Bounty) self.multiworld.start_hints[self.player].value.add(ItemName.Bounty)
self.item_quantity_dict[ItemName.ProofofNonexistence] = 0 self.item_quantity_dict[ItemName.ProofofNonexistence] = 0