Undertale: Various Fixes (#2146)

* Changed the pathing code to use os.path.join, instead of adding strings together, also fixed the savepath command using UndertaleContext instead of self.ctx (Credit to Wackerly for finding the self.ctx issue and fix)

* Undertale: Fixed a debug function in the game not requiring debug to be enabled.

* Undetale: Fixed a logic bug with the location "Letter Quest"
This commit is contained in:
Mewlif 2023-09-20 04:18:53 -04:00 committed by GitHub
parent a0eea3a650
commit aff852fb45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 21 deletions

View File

@ -29,31 +29,31 @@ class UndertaleCommandProcessor(ClientCommandProcessor):
def _cmd_patch(self): def _cmd_patch(self):
"""Patch the game.""" """Patch the game."""
if isinstance(self.ctx, UndertaleContext): if isinstance(self.ctx, UndertaleContext):
os.makedirs(name=os.getcwd() + "\\Undertale", exist_ok=True) os.makedirs(name=os.path.join(os.getcwd(), "Undertale"), exist_ok=True)
self.ctx.patch_game() self.ctx.patch_game()
self.output("Patched.") self.output("Patched.")
def _cmd_savepath(self, directory: str): def _cmd_savepath(self, directory: str):
"""Redirect to proper save data folder. (Use before connecting!)""" """Redirect to proper save data folder. (Use before connecting!)"""
if isinstance(self.ctx, UndertaleContext): if isinstance(self.ctx, UndertaleContext):
UndertaleContext.save_game_folder = directory self.ctx.save_game_folder = directory
self.output("Changed to the following directory: " + directory) self.output("Changed to the following directory: " + self.ctx.save_game_folder)
@mark_raw @mark_raw
def _cmd_auto_patch(self, steaminstall: typing.Optional[str] = None): def _cmd_auto_patch(self, steaminstall: typing.Optional[str] = None):
"""Patch the game automatically.""" """Patch the game automatically."""
if isinstance(self.ctx, UndertaleContext): if isinstance(self.ctx, UndertaleContext):
os.makedirs(name=os.getcwd() + "\\Undertale", exist_ok=True) os.makedirs(name=os.path.join(os.getcwd(), "Undertale"), exist_ok=True)
tempInstall = steaminstall tempInstall = steaminstall
if not os.path.isfile(os.path.join(tempInstall, "data.win")): if not os.path.isfile(os.path.join(tempInstall, "data.win")):
tempInstall = None tempInstall = None
if tempInstall is None: if tempInstall is None:
tempInstall = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Undertale" tempInstall = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Undertale"
if not os.path.exists("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Undertale"): if not os.path.exists(tempInstall):
tempInstall = "C:\\Program Files\\Steam\\steamapps\\common\\Undertale" tempInstall = "C:\\Program Files\\Steam\\steamapps\\common\\Undertale"
elif not os.path.exists(tempInstall): elif not os.path.exists(tempInstall):
tempInstall = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Undertale" tempInstall = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Undertale"
if not os.path.exists("C:\\Program Files (x86)\\Steam\\steamapps\\common\\Undertale"): if not os.path.exists(tempInstall):
tempInstall = "C:\\Program Files\\Steam\\steamapps\\common\\Undertale" tempInstall = "C:\\Program Files\\Steam\\steamapps\\common\\Undertale"
if not os.path.exists(tempInstall) or not os.path.exists(tempInstall) or not os.path.isfile(os.path.join(tempInstall, "data.win")): if not os.path.exists(tempInstall) or not os.path.exists(tempInstall) or not os.path.isfile(os.path.join(tempInstall, "data.win")):
self.output("ERROR: Cannot find Undertale. Please rerun the command with the correct folder." self.output("ERROR: Cannot find Undertale. Please rerun the command with the correct folder."
@ -61,8 +61,8 @@ class UndertaleCommandProcessor(ClientCommandProcessor):
else: else:
for file_name in os.listdir(tempInstall): for file_name in os.listdir(tempInstall):
if file_name != "steam_api.dll": if file_name != "steam_api.dll":
shutil.copy(tempInstall+"\\"+file_name, shutil.copy(os.path.join(tempInstall, file_name),
os.getcwd() + "\\Undertale\\" + file_name) os.path.join(os.getcwd(), "Undertale", file_name))
self.ctx.patch_game() self.ctx.patch_game()
self.output("Patching successful!") self.output("Patching successful!")
@ -111,13 +111,13 @@ class UndertaleContext(CommonContext):
self.save_game_folder = os.path.expandvars(r"%localappdata%/UNDERTALE") self.save_game_folder = os.path.expandvars(r"%localappdata%/UNDERTALE")
def patch_game(self): def patch_game(self):
with open(os.getcwd() + "/Undertale/data.win", "rb") as f: with open(os.path.join(os.getcwd(), "Undertale", "data.win"), "rb") as f:
patchedFile = bsdiff4.patch(f.read(), undertale.data_path("patch.bsdiff")) patchedFile = bsdiff4.patch(f.read(), undertale.data_path("patch.bsdiff"))
with open(os.getcwd() + "/Undertale/data.win", "wb") as f: with open(os.path.join(os.getcwd(), "Undertale", "data.win"), "wb") as f:
f.write(patchedFile) f.write(patchedFile)
os.makedirs(name=os.getcwd() + "\\Undertale\\" + "Custom Sprites", exist_ok=True) os.makedirs(name=os.path.join(os.getcwd(), "Undertale", "Custom Sprites"), exist_ok=True)
with open(os.path.expandvars(os.getcwd() + "\\Undertale\\" + "Custom Sprites\\" + with open(os.path.expandvars(os.path.join(os.getcwd(), "Undertale", "Custom Sprites",
"Which Character.txt"), "w") as f: "Which Character.txt")), "w") as f:
f.writelines(["// Put the folder name of the sprites you want to play as, make sure it is the only " f.writelines(["// Put the folder name of the sprites you want to play as, make sure it is the only "
"line other than this one.\n", "frisk"]) "line other than this one.\n", "frisk"])
f.close() f.close()
@ -385,7 +385,7 @@ async def multi_watcher(ctx: UndertaleContext):
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for file in files: for file in files:
if "spots.mine" in file and "Online" in ctx.tags: if "spots.mine" in file and "Online" in ctx.tags:
with open(root + "/" + file, "r") as mine: with open(os.path.join(root, file), "r") as mine:
this_x = mine.readline() this_x = mine.readline()
this_y = mine.readline() this_y = mine.readline()
this_room = mine.readline() this_room = mine.readline()
@ -408,7 +408,7 @@ async def game_watcher(ctx: UndertaleContext):
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for file in files: for file in files:
if ".item" in file: if ".item" in file:
os.remove(root+"/"+file) os.remove(os.path.join(root, file))
sync_msg = [{"cmd": "Sync"}] sync_msg = [{"cmd": "Sync"}]
if ctx.locations_checked: if ctx.locations_checked:
sync_msg.append({"cmd": "LocationChecks", "locations": list(ctx.locations_checked)}) sync_msg.append({"cmd": "LocationChecks", "locations": list(ctx.locations_checked)})
@ -424,13 +424,13 @@ async def game_watcher(ctx: UndertaleContext):
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for file in files: for file in files:
if "DontBeMad.mad" in file: if "DontBeMad.mad" in file:
os.remove(root+"/"+file) os.remove(os.path.join(root, file))
if "DeathLink" in ctx.tags: if "DeathLink" in ctx.tags:
await ctx.send_death() await ctx.send_death()
if "scout" == file: if "scout" == file:
sending = [] sending = []
try: try:
with open(root+"/"+file, "r") as f: with open(os.path.join(root, file), "r") as f:
lines = f.readlines() lines = f.readlines()
for l in lines: for l in lines:
if ctx.server_locations.__contains__(int(l)+12000): if ctx.server_locations.__contains__(int(l)+12000):
@ -438,11 +438,11 @@ async def game_watcher(ctx: UndertaleContext):
finally: finally:
await ctx.send_msgs([{"cmd": "LocationScouts", "locations": sending, await ctx.send_msgs([{"cmd": "LocationScouts", "locations": sending,
"create_as_hint": int(2)}]) "create_as_hint": int(2)}])
os.remove(root+"/"+file) os.remove(os.path.join(root, file))
if "check.spot" in file: if "check.spot" in file:
sending = [] sending = []
try: try:
with open(root+"/"+file, "r") as f: with open(os.path.join(root, file), "r") as f:
lines = f.readlines() lines = f.readlines()
for l in lines: for l in lines:
sending = sending+[(int(l.rstrip('\n')))+12000] sending = sending+[(int(l.rstrip('\n')))+12000]
@ -451,7 +451,7 @@ async def game_watcher(ctx: UndertaleContext):
if "victory" in file and str(ctx.route) in file: if "victory" in file and str(ctx.route) in file:
victory = True victory = True
if ".playerspot" in file and "Online" not in ctx.tags: if ".playerspot" in file and "Online" not in ctx.tags:
os.remove(root+"/"+file) os.remove(os.path.join(root, file))
if "victory" in file: if "victory" in file:
if str(ctx.route) == "all_routes": if str(ctx.route) == "all_routes":
if "neutral" in file and ctx.completed_routes["neutral"] != 1: if "neutral" in file and ctx.completed_routes["neutral"] != 1:

View File

@ -113,7 +113,7 @@ def set_rules(multiworld: MultiWorld, player: int):
set_rule(multiworld.get_location("Hush Trade", player), set_rule(multiworld.get_location("Hush Trade", player),
lambda state: state.can_reach("News Show", "Region", player) and state.has("Hot Dog...?", player, 1)) lambda state: state.can_reach("News Show", "Region", player) and state.has("Hot Dog...?", player, 1))
set_rule(multiworld.get_location("Letter Quest", player), set_rule(multiworld.get_location("Letter Quest", player),
lambda state: state.can_reach("New Home Exit", "Entrance", player)) lambda state: state.can_reach("New Home Exit", "Entrance", player) and state.has("Undyne Date", player))
if (not _undertale_is_route(multiworld.state, player, 2)) or _undertale_is_route(multiworld.state, player, 3): if (not _undertale_is_route(multiworld.state, player, 2)) or _undertale_is_route(multiworld.state, player, 3):
set_rule(multiworld.get_location("Nicecream Punch Card", player), set_rule(multiworld.get_location("Nicecream Punch Card", player),
lambda state: state.has("Punch Card", player, 3) and state.can_reach("Waterfall", "Region", player)) lambda state: state.has("Punch Card", player, 3) and state.can_reach("Waterfall", "Region", player))

Binary file not shown.