Files
Grinch-AP/worlds/jakanddaxter/client.py

631 lines
29 KiB
Python
Raw Permalink Normal View History

Jak and Daxter: Implement New Game (#3291) * Jak 1: Initial commit: Cell Locations, Items, and Regions modeled. * Jak 1: Wrote Regions, Rules, init. Untested. * Jak 1: Fixed mistakes, need better understanding of Entrances. * Jak 1: Fixed bugs, refactored Regions, added missing Special Checks. First spoiler log generated. * Jak 1: Add Scout Fly Locations, code and style cleanup. * Jak 1: Add Scout Flies to Regions. * Jak 1: Add version info. * Jak 1: Reduced code smell. * Jak 1: Fixed UT bugs, added Free The Sages as Locations. * Jak 1: Refactor ID scheme to better fit game's scheme. Add more subregions and rules, but still missing one-way Entrances. * Jak 1: Add some one-ways, adjust scout fly offset. * Jak 1: Found Scout Fly ID's for first 4 maps. * Jak 1: Add more scout fly ID's, refactor game/AP ID translation for easier reading and code reuse. * Jak 1: Fixed a few things. Four maps to go. * Jak 1: Last of the scout flies mapped! * Jak 1: simplify citadel sages logic. * Jak 1: WebWorld setup, some documentation. * Jak 1: Initial checkin of Client. Removed the colon from the game name. * Jak 1: Refactored client into components, working on async communication between the client and the game. * Jak 1: In tandem with new ArchipelaGOAL memory structure, define read_memory. * Jak 1: There's magic in the air... * Jak 1: Fixed bug translating scout fly ID's. * Jak 1: Make the REPL a little more verbose, easier to debug. * Jak 1: Did you know Snowy Mountain had such specific unlock requirements? I didn't. * Jak 1: Update Documentation. * Jak 1: Simplify user interaction with agents, make process more robust/less dependent on order of ops. * Jak 1: Simplified startup process, updated docs, prayed. * Jak 1: quick fix to settings. * Jak and Daxter: Implement New Game (#1) * Jak 1: Initial commit: Cell Locations, Items, and Regions modeled. * Jak 1: Wrote Regions, Rules, init. Untested. * Jak 1: Fixed mistakes, need better understanding of Entrances. * Jak 1: Fixed bugs, refactored Regions, added missing Special Checks. First spoiler log generated. * Jak 1: Add Scout Fly Locations, code and style cleanup. * Jak 1: Add Scout Flies to Regions. * Jak 1: Add version info. * Jak 1: Reduced code smell. * Jak 1: Fixed UT bugs, added Free The Sages as Locations. * Jak 1: Refactor ID scheme to better fit game's scheme. Add more subregions and rules, but still missing one-way Entrances. * Jak 1: Add some one-ways, adjust scout fly offset. * Jak 1: Found Scout Fly ID's for first 4 maps. * Jak 1: Add more scout fly ID's, refactor game/AP ID translation for easier reading and code reuse. * Jak 1: Fixed a few things. Four maps to go. * Jak 1: Last of the scout flies mapped! * Jak 1: simplify citadel sages logic. * Jak 1: WebWorld setup, some documentation. * Jak 1: Initial checkin of Client. Removed the colon from the game name. * Jak 1: Refactored client into components, working on async communication between the client and the game. * Jak 1: In tandem with new ArchipelaGOAL memory structure, define read_memory. * Jak 1: There's magic in the air... * Jak 1: Fixed bug translating scout fly ID's. * Jak 1: Make the REPL a little more verbose, easier to debug. * Jak 1: Did you know Snowy Mountain had such specific unlock requirements? I didn't. * Jak 1: Update Documentation. * Jak 1: Simplify user interaction with agents, make process more robust/less dependent on order of ops. * Jak 1: Simplified startup process, updated docs, prayed. * Jak 1: quick fix to settings. * Jak and Daxter: Genericize Items, Update Scout Fly logic, Add Victory Condition. (#3) * Jak 1: Update to 0.4.6. Decouple locations from items, support filler items. * Jak 1: Total revamp of Items. This is where everything broke. * Jak 1: Decouple 7 scout fly checks from normal checks, update regions/rules for orb counts/traders. * Jak 1: correct regions/rules, account for sequential oracle/miner locations. * Jak 1: make nicer strings. * Jak 1: Add logic for finished game. First full run complete! * Jak 1: update group names. * Jak and Daxter - Gondola, Pontoons, Rules, Regions, and Client Update * Jak 1: Overhaul of regions, rules, and special locations. Updated game info page. * Jak 1: Preparations for Alpha. Reintroducing automatic startup in client. Updating docs, readme, codeowners. * Alpha Updates (#15) * Jak 1: Consolidate client into apworld, create launcher icon, improve setup docs. * Jak 1: Update setup guide. * Jak 1: Load title screen, save states of in/outboxes. * Logging Update (#16) * Jak 1: Separate info and debug logs. * Jak 1: Update world info to refer to Archipelago Options menu. * Deathlink (#18) * Jak 1: Implement Deathlink. TODO: make it optional... * Jak 1: Issue a proper send-event for deathlink deaths. * Jak 1: Added cause of death to deathlink, fixed typo. * Jak 1: Make Deathlink toggleable. * Jak 1: Added player name to death text, added zoomer/flut/fishing text, simplified GOAL call for deathlink. * Jak 1: Fix death text in client logger. * Move Randomizer (#26) * Finally remove debug-segment text, update Python imports to relative paths. * HUGE refactor to Regions/Rules to support move rando, first hub area coded. * More refactoring. * Another refactor - may squash. * Fix some Rules, reuse some code by returning key regions from build_regions. * More regions added. A couple of TODOs. * Fixed trade logic, added LPC regions. * Added Spider, Snowy, Boggy. Fixed Misty's orbs. * Fix circular import, assert orb counts per level, fix a few naming errors. * Citadel added, missing locs and connections fixed. First move rando seed generated. * Add Move Rando to Options class. * Fixed rules for prerequisite moves. * Implement client functionality for move rando, add blurbs to game info page. * Fix wrong address for cache checks. * Fix byte alignment of offsets, refactor read_memory for better code reuse. * Refactor memory offsets and add some unit tests. * Make green eco the filler item, also define a maximum ID. Fix Boggy tether locations. * Move rando fixes (#29) * Fix virtual regions in Snowy. Fix some GMC problems. * Fix Deathlink on sunken slides. * Removed unncessary code causing build failure. * Orbsanity (#32) * My big dumb shortcut: a 2000 item array. * A better idea: bundle orbs as a numerical option and make array variable size. * Have Item/Region generation respect the chosen Orbsanity bundle size. Fix trade logic. * Separate Global/Local Orbsanity options. TODO - re-introduce orb factory for per-level option. * Per-level Orbsanity implemented w/ orb bundle factory. * Implement Orbsanity for client, fix some things up for regions. * Fix location name/id mappings. * Fix client orb collection on connection. * Fix minor Deathlink bug, add Update instructions. * Finishing Touches (#36) * Set up connector level thresholds, completion goal choices. * Send AP sender/recipient info to game via client. * Slight refactors. * Refactor option checking, add DataStorage handling of traded orbs. * Update instructions to change order of load/connect. * Add Option check to ensure enough Locations exist for Cell Count thresholds. Fix Final Door region. * Need some height move to get LPC sunken chamber cell. * Rename completion_condition to jak_completion_condition (#41) * The Afterparty (#42) * Fixes to Jak client, rules, options, and more. * Post-rebase fixes. * Remove orbsanity reset code, optimize game text in client. * More game text optimization. * Added more specific troubleshooting/setup instructions. * Add known issue about large releases taking time. (Dodge 6,666th commit.) * Remove "Bundle of", Add location name groups, set better default RootDirectory for new players. * Make orb trade amounts configurable, make orbsanity defaults more reasonable. * Add HUD info to doc. * Exempt's Code Review Updates (#43) * Round 1 of code review updates, the easy stuff. * Factor options checking away from region/rule creation. * Code review updates round 2, more complex stuff. * Code review updates round 3: the mental health annihilator * Code review updates part 4: redemption. * More code review feedback, simplifying code, etc. * Added a host.yaml option to override friendly limits, plus a couple of code review updates. * Added singleplayer limits, player names to enforcement rules. * Updated friendly limits to be more strict, optimized recalculate logic. * Today's the big day Jak: updates docs for mod support in OpenGOAL Launcher * Rearranged and clarified some instructions, ADDED PATH-SPACE FIX TO CLIENT. * Fix deathlink reset stalls on a busy client. (#47) * Jak & Daxter Client : queue game text messages to get items faster during release (#48) * queue game text messages to write them during the main_tick function and empty the message queue faster during release * wrap comment for code style character limit Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * remove useless blank line Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * whitespace code style Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * Move JsonMessageData dataclass outside of ReplClient class for code clarity --------- Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * Item Classifications (and REPL fixes) (#49) * Changes to item classifications * Bugfixes to power cell thresholds. * Fix bugs in item_type_helper. * Refactor 100 cell door to pass unit tests. * Quick fix to ReplClient. * Not so quick fix to ReplClient. * Display friendly limits in options tooltips. * Use math.ceil like a normal person. * Missed a space. * Fix non-accessibility due to bad orb calculation. * Updated documentation. * More Options, More Docs, More Tests (#51) * Reorder cell counts, require punch for Klaww. * Friendlier friendly friendlies. * Removed custom_worlds references from docs/setup guide, focused OpenGOAL Launcher language. * Increased breadth of unit tests. * Clean imports of unit tests. * Create OptionGroups. * Fix region rule bug with Punch for Klaww. * Include Punch For Klaww in slot data. * Update worlds/jakanddaxter/__init__.py Co-authored-by: Scipio Wright <scipiowright@gmail.com> * Temper and Harden Text Client (#52) * Provide config path so OpenGOAL can use mod-specific saves and settings. * Add versioning to MemoryReader. Harden the client against user errors. * Updated comments. * Add Deathlink as a "statement of intent" to the YAML. Small updates to client. * Revert deathlink changes. * Update error message. * Added color markup to log messages printed in text client. * Separate loggers by agent, write markup to GUI and non-markup to disk simultaneously. * Refactor MemoryReader callbacks from main_tick to constructor. * Make callback names more... informative. * Give users explicit instructions in error messages. * Stellar Messaging (#54) * Use new ap-messenger functions for text writing. * Remove Powershell requirement, bump memory version to 3. * Error message update w/ instructions for game crash. * Create no console window for gk. * ISO Data Enhancement (#58) * Add iso-path as argument to GOAL compiler. # Conflicts: # worlds/jakanddaxter/Client.py * More resilient handling of iso_path. * Fixed scout fly ID mismatches. * Corrected iso_data subpath. * Update memory version to 4. * Docs update for iso_data. * Auto Detect OpenGOAL Install (#63) * Auto detect OpenGOAL install path. Also fix Deathlink on server connection. * Updated docs, add instructions to error messages. * Slight tweak to error text. * J&D : add per region location groups (#64) * add per region power cells location group * add per region scout flies location group * add per zone orb bundle groups (I'm not particularly happy about this code, but I figured doing it this way was the point of least friction/duplication) * guess who forgot 9 very important characters in each line of the last commit * Rearrange location group names, quick fix to client error handling. * Fix pycharm warnings. * Fix more pycharm warnings. * Light cleanup: fix icons, add bug report page, remove py 3.8 code. * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Code review updates on comments, tooltips, and type hints. * Update type hint for lists in regions. * Missed todo removal. * More type hint updates. * Small region updates for location accessibility, small updates to world guide and README.md. * Add GMC scout fly location group. * Improved sanitization of game text. * Traps 2 (#70) * Add trap items, relevant options, and citadel orb caches. * Update REPL to send traps to game. * Fix item counter. * Allow player to select which traps to use. * Fix host.yaml doc strings, ap-setup-options typing, bump memory version to 5. * Alter some trap names. * Update world doc. * Add health trap. * Added 3 more trap types. * Protect against empty trap list. * Reword traps paragraph in world doc. * Another update to trap paragraph. * Concisify trap option docstring. * Timestamp on game log file. * Update client to handle waiting on title screen. * Send slot name and seed to game. * Use self.random instead. * Update setup doc for new title screen. * Quick clarification of orb caches in world doc. * Sanitize slot info earlier. * Added to and improved unit tests. * Light cleanup on world. * Optimizations to movement rules, docs: known issues update. * Quick fixes for beta 0.5.0 release: template options and LPC logic. * Quick fix to spoiler counts. * Reorganize world guide for faster navigation. * Fix links. * Update HUD section. * Found a way to render apostrophes in item names. * March Refactors (#77) * Reorg imports, small fix to Rock Village movement. * Fix wait-on-title message never going to ready message. * Colorama init fix. * Swap trap list for a dictionary of trap weights. * The more laws, the less justice. * Quick readability update. * Have memory reader provide instructions for slow booting games. * Revert some things. * Update setup_en.md * Update HUD mode lingo for combined msgs. * Remade launcher icon, sized correctly. * I don't know why I can't be satisfied with things. * Apply suggestions from Scipio Co-authored-by: Scipio Wright <scipiowright@gmail.com> * Properly use the settings API instead of Utils. * Newline on requirements.txt. * Add __init__ files for frozen builds. * Replace an ap_inform function with a CommonClient built-in. * Resize icon to match kivymd expected size. * First round of Treble code reviews. * Second round of Treble code reviews. * Third round of Treble code reviews. * Missed an unncessary if condition. * Missed unnecessary comments. * Fourth round of Treble code reviews. * Switch trap dictionary to OptionCounter. * Use existing slot name/seed from network protocol. * Violet code review updates. * Violet code review updates part 2. * Refactor to avoid floating imports (Violet part 3). * Found a few more valid characters for messaging. * Move tests out of init, add colon to game name (now that it's safe). * But don't include those chars for file text. * Implement Vi suggestion on webhost-capable friendly limits. * Revert "Implement Vi suggestion on webhost-capable friendly limits." This reverts commit 2d012b7f4a9a4c13985ecd7303bb1fc646831c86. * Rename all files for PEP8. * Refactor how maximums work on webhost. * Fix rogue UT. * Don't rush. * Fix client post-PEP8. --------- Co-authored-by: Justus Lind <DeamonHunter@users.noreply.github.com> Co-authored-by: Romain BERNARD <30secondstodraw@gmail.com> Co-authored-by: Scipio Wright <scipiowright@gmail.com> Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com>
2025-05-21 08:12:27 -04:00
# Python standard libraries
import asyncio
import json
import logging
import os
import subprocess
import sys
from asyncio import Task
from datetime import datetime
from logging import Logger
from typing import Awaitable
# Misc imports
import colorama
import pymem
from pymem.exception import ProcessNotFound
# Archipelago imports
import ModuleUpdate
import Utils
from CommonClient import ClientCommandProcessor, CommonContext, server_loop, gui_enabled
from NetUtils import ClientStatus
# Jak imports
from .game_id import jak1_name
from .options import EnableOrbsanity
from .agents.memory_reader import JakAndDaxterMemoryReader
from .agents.repl_client import JakAndDaxterReplClient
from . import JakAndDaxterWorld
ModuleUpdate.update()
logger = logging.getLogger("JakClient")
all_tasks: set[Task] = set()
def create_task_log_exception(awaitable: Awaitable) -> asyncio.Task:
async def _log_exception(a):
try:
return await a
except Exception as e:
logger.exception(e)
finally:
all_tasks.remove(task)
task = asyncio.create_task(_log_exception(awaitable))
all_tasks.add(task)
return task
class JakAndDaxterClientCommandProcessor(ClientCommandProcessor):
ctx: "JakAndDaxterContext"
# The command processor is not async so long-running operations like the /repl connect command
# (which takes 10-15 seconds to compile the game) have to be requested with user-initiated flags.
# The flags are checked by the agents every main_tick.
def _cmd_repl(self, *arguments: str):
"""Sends a command to the OpenGOAL REPL. Arguments:
- connect : connect the client to the REPL (goalc).
- status : check internal status of the REPL."""
if arguments:
if arguments[0] == "connect":
self.ctx.on_log_info(logger, "This may take a bit... Wait for the success audio cue before continuing!")
self.ctx.repl.initiated_connect = True
if arguments[0] == "status":
create_task_log_exception(self.ctx.repl.print_status())
def _cmd_memr(self, *arguments: str):
"""Sends a command to the Memory Reader. Arguments:
- connect : connect the memory reader to the game process (gk).
- status : check the internal status of the Memory Reader."""
if arguments:
if arguments[0] == "connect":
self.ctx.memr.initiated_connect = True
if arguments[0] == "status":
create_task_log_exception(self.ctx.memr.print_status())
class JakAndDaxterContext(CommonContext):
game = jak1_name
items_handling = 0b111 # Full item handling
command_processor = JakAndDaxterClientCommandProcessor
# We'll need two agents working in tandem to handle two-way communication with the game.
# The REPL Client will handle the server->game direction by issuing commands directly to the running game.
# But the REPL cannot send information back to us, it only ingests information we send it.
# Luckily OpenGOAL sets up memory addresses to write to, that AutoSplit can read from, for speedrunning.
# We'll piggyback off this system with a Memory Reader, and that will handle the game->server direction.
repl: JakAndDaxterReplClient
memr: JakAndDaxterMemoryReader
# And two associated tasks, so we have handles on them.
repl_task: asyncio.Task
memr_task: asyncio.Task
# Storing some information for writing save slot identifiers.
slot_seed: str
def __init__(self, server_address: str | None, password: str | None) -> None:
self.repl = JakAndDaxterReplClient(self.on_log_error,
self.on_log_warn,
self.on_log_success,
self.on_log_info)
self.memr = JakAndDaxterMemoryReader(self.on_location_check,
self.on_finish_check,
self.on_deathlink_check,
self.on_deathlink_toggle,
self.on_orb_trade,
self.on_log_error,
self.on_log_warn,
self.on_log_success,
self.on_log_info)
# self.repl.load_data()
# self.memr.load_data()
super().__init__(server_address, password)
def run_gui(self):
from kvui import GameManager
class JakAndDaxterManager(GameManager):
logging_pairs = [
("Client", "Archipelago")
]
base_title = "Jak and Daxter ArchipelaGOAL Client"
self.ui = JakAndDaxterManager(self)
self.ui_task = asyncio.create_task(self.ui.async_run(), name="UI")
async def server_auth(self, password_requested: bool = False):
if password_requested and not self.password:
await super(JakAndDaxterContext, self).server_auth(password_requested)
await self.get_username()
self.tags = set()
await self.send_connect()
def on_package(self, cmd: str, args: dict):
if cmd == "RoomInfo":
self.slot_seed = args["seed_name"]
if cmd == "Connected":
slot_data = args["slot_data"]
orbsanity_option = slot_data["enable_orbsanity"]
if orbsanity_option == EnableOrbsanity.option_per_level:
orbsanity_bundle = slot_data["level_orbsanity_bundle_size"]
elif orbsanity_option == EnableOrbsanity.option_global:
orbsanity_bundle = slot_data["global_orbsanity_bundle_size"]
else:
orbsanity_bundle = 1
# Connected packet is unaware of starting inventory or if player is returning to an existing game.
# Set initial_item_count to 0, see below comments for more info.
if not self.repl.received_initial_items and self.repl.initial_item_count < 0:
self.repl.initial_item_count = 0
create_task_log_exception(
self.repl.setup_options(orbsanity_option,
orbsanity_bundle,
slot_data["fire_canyon_cell_count"],
slot_data["mountain_pass_cell_count"],
slot_data["lava_tube_cell_count"],
slot_data["citizen_orb_trade_amount"],
slot_data["oracle_orb_trade_amount"],
slot_data["trap_effect_duration"],
slot_data["jak_completion_condition"],
self.auth[:16], # The slot name
self.slot_seed[:8]))
# Because Orbsanity and the orb traders in the game are intrinsically linked, we need the server
# to track our trades at all times to support async play. "Retrieved" will tell us the orbs we lost,
# while "ReceivedItems" will tell us the orbs we gained. This will give us the correct balance.
if orbsanity_option in [EnableOrbsanity.option_per_level, EnableOrbsanity.option_global]:
async def get_orb_balance():
await self.send_msgs([{"cmd": "Get", "keys": [f"jakanddaxter_{self.auth}_orbs_paid"]}])
create_task_log_exception(get_orb_balance())
# Tell the server if Deathlink is enabled or disabled in the in-game options.
# This allows us to "remember" the user's choice.
self.on_deathlink_toggle()
if cmd == "Retrieved":
if f"jakanddaxter_{self.auth}_orbs_paid" in args["keys"]:
orbs_traded = args["keys"][f"jakanddaxter_{self.auth}_orbs_paid"]
orbs_traded = orbs_traded if orbs_traded is not None else 0
create_task_log_exception(self.repl.subtract_traded_orbs(orbs_traded))
if cmd == "ReceivedItems":
# If you have a starting inventory or are returning to a game where you have items, a ReceivedItems will be
# in the same network packet as Connected. This guarantees it is the first of any ReceivedItems we process.
# In this case, we should set the initial_item_count to > 0, even if already set to 0 by Connected, as well
# as the received_initial_items flag. Finally, use send_connection_status to tell the player to wait while
# we process the initial items. However, we will skip all this if there was no initial ReceivedItems and
# the REPL indicates it already handled any initial items (0 or otherwise).
if not self.repl.received_initial_items and not self.repl.processed_initial_items:
self.repl.received_initial_items = True
self.repl.initial_item_count = len(args["items"])
create_task_log_exception(self.repl.send_connection_status("wait"))
# This enumeration should run on every ReceivedItems packet,
# regardless of it being on initial connection or midway through a game.
for index, item in enumerate(args["items"], start=args["index"]):
logger.debug(f"index: {str(index)}, item: {str(item)}")
self.repl.item_inbox[index] = item
async def json_to_game_text(self, args: dict):
if "type" in args and args["type"] in {"ItemSend"}:
my_item_name: str | None = None
my_item_finder: str | None = None
their_item_name: str | None = None
their_item_owner: str | None = None
item = args["item"]
recipient = args["receiving"]
# Receiving an item from the server.
if self.slot_concerns_self(recipient):
my_item_name = self.item_names.lookup_in_game(item.item)
# Did we find it, or did someone else?
if self.slot_concerns_self(item.player):
my_item_finder = "MYSELF"
else:
my_item_finder = self.player_names[item.player]
# Sending an item to the server.
if self.slot_concerns_self(item.player):
their_item_name = self.item_names.lookup_in_slot(item.item, recipient)
# Does it belong to us, or to someone else?
if self.slot_concerns_self(recipient):
their_item_owner = "MYSELF"
else:
their_item_owner = self.player_names[recipient]
# Write to game display.
self.repl.queue_game_text(my_item_name, my_item_finder, their_item_name, their_item_owner)
# Even though N items come in as 1 ReceivedItems packet, there are still N PrintJson packets to process,
# and they all arrive before the ReceivedItems packet does. Defer processing of these packets as
# async tasks to speed up large releases of items.
def on_print_json(self, args: dict) -> None:
create_task_log_exception(self.json_to_game_text(args))
super(JakAndDaxterContext, self).on_print_json(args)
# We need to do a little more than just use CommonClient's on_deathlink.
def on_deathlink(self, data: dict):
if self.memr.deathlink_enabled:
self.repl.received_deathlink = True
super().on_deathlink(data)
# We don't need an ap_inform function because check_locations solves that need.
def on_location_check(self, location_ids: list[int]):
create_task_log_exception(self.check_locations(location_ids))
# CommonClient has no finished_game function, so we will have to craft our own. TODO - Update if that changes.
async def ap_inform_finished_game(self):
if not self.finished_game and self.memr.finished_game:
message = [{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}]
await self.send_msgs(message)
self.finished_game = True
def on_finish_check(self):
create_task_log_exception(self.ap_inform_finished_game())
# We need to do a little more than just use CommonClient's send_death.
async def ap_inform_deathlink(self):
if self.memr.deathlink_enabled:
player = self.player_names[self.slot] if self.slot is not None else "Jak"
death_text = self.memr.cause_of_death.replace("Jak", player)
await self.send_death(death_text)
self.on_log_warn(logger, death_text)
# Reset all flags, but leave the death count alone.
self.memr.send_deathlink = False
self.memr.cause_of_death = ""
def on_deathlink_check(self):
create_task_log_exception(self.ap_inform_deathlink())
# We don't need an ap_inform function because update_death_link solves that need.
def on_deathlink_toggle(self):
create_task_log_exception(self.update_death_link(self.memr.deathlink_enabled))
# Orb trades are situations unique to Jak, so we have to craft our own function.
async def ap_inform_orb_trade(self, orbs_changed: int):
if self.memr.orbsanity_enabled:
await self.send_msgs([{"cmd": "Set",
"key": f"jakanddaxter_{self.auth}_orbs_paid",
"default": 0,
"want_reply": False,
"operations": [{"operation": "add", "value": orbs_changed}]
}])
def on_orb_trade(self, orbs_changed: int):
create_task_log_exception(self.ap_inform_orb_trade(orbs_changed))
def _markup_panels(self, msg: str, c: str = None):
color = self.jsontotextparser.color_codes[c] if c else None
message = f"[color={color}]{msg}[/color]" if c else msg
self.ui.log_panels["Archipelago"].on_message_markup(message)
self.ui.log_panels["All"].on_message_markup(message)
def on_log_error(self, lg: Logger, message: str):
lg.error(message)
if self.ui:
self._markup_panels(message, "red")
def on_log_warn(self, lg: Logger, message: str):
lg.warning(message)
if self.ui:
self._markup_panels(message, "orange")
def on_log_success(self, lg: Logger, message: str):
lg.info(message)
if self.ui:
self._markup_panels(message, "green")
def on_log_info(self, lg: Logger, message: str):
lg.info(message)
if self.ui:
self._markup_panels(message)
async def run_repl_loop(self):
while True:
await self.repl.main_tick()
await asyncio.sleep(0.1)
async def run_memr_loop(self):
while True:
await self.memr.main_tick()
await asyncio.sleep(0.1)
def find_root_directory(ctx: JakAndDaxterContext):
# The path to this file is platform-dependent.
if Utils.is_windows:
appdata = os.getenv("APPDATA")
settings_path = os.path.normpath(f"{appdata}/OpenGOAL-Launcher/settings.json")
elif Utils.is_linux:
home = os.path.expanduser("~")
settings_path = os.path.normpath(f"{home}/.config/OpenGOAL-Launcher/settings.json")
elif Utils.is_macos:
home = os.path.expanduser("~")
settings_path = os.path.normpath(f"{home}/Library/Application Support/OpenGOAL-Launcher/settings.json")
else:
ctx.on_log_error(logger, f"Unknown operating system: {sys.platform}!")
return
# Boilerplate messages that all error messages in this function should have.
err_title = "Unable to locate the ArchipelaGOAL install directory"
alt_instructions = (f"Please verify that OpenGOAL and ArchipelaGOAL are installed properly. "
f"If the problem persists, follow these steps:\n"
f" Run the OpenGOAL Launcher, click Jak and Daxter > Features > Mods > ArchipelaGOAL.\n"
f" Then click Advanced > Open Game Data Folder.\n"
f" Go up one folder, then copy this path.\n"
f" Run the Archipelago Launcher, click Open host.yaml.\n"
f" Set the value of 'jakanddaxter_options > root_directory' to this path.\n"
f" Replace all backslashes in the path with forward slashes.\n"
f" Set the value of 'jakanddaxter_options > auto_detect_root_directory' to false, "
f"then save and close the host.yaml file.\n"
f" Close all launchers, games, clients, and console windows, then restart Archipelago.")
if not os.path.exists(settings_path):
msg = (f"{err_title}: The OpenGOAL settings file does not exist.\n"
Jak and Daxter: Implement New Game (#3291) * Jak 1: Initial commit: Cell Locations, Items, and Regions modeled. * Jak 1: Wrote Regions, Rules, init. Untested. * Jak 1: Fixed mistakes, need better understanding of Entrances. * Jak 1: Fixed bugs, refactored Regions, added missing Special Checks. First spoiler log generated. * Jak 1: Add Scout Fly Locations, code and style cleanup. * Jak 1: Add Scout Flies to Regions. * Jak 1: Add version info. * Jak 1: Reduced code smell. * Jak 1: Fixed UT bugs, added Free The Sages as Locations. * Jak 1: Refactor ID scheme to better fit game's scheme. Add more subregions and rules, but still missing one-way Entrances. * Jak 1: Add some one-ways, adjust scout fly offset. * Jak 1: Found Scout Fly ID's for first 4 maps. * Jak 1: Add more scout fly ID's, refactor game/AP ID translation for easier reading and code reuse. * Jak 1: Fixed a few things. Four maps to go. * Jak 1: Last of the scout flies mapped! * Jak 1: simplify citadel sages logic. * Jak 1: WebWorld setup, some documentation. * Jak 1: Initial checkin of Client. Removed the colon from the game name. * Jak 1: Refactored client into components, working on async communication between the client and the game. * Jak 1: In tandem with new ArchipelaGOAL memory structure, define read_memory. * Jak 1: There's magic in the air... * Jak 1: Fixed bug translating scout fly ID's. * Jak 1: Make the REPL a little more verbose, easier to debug. * Jak 1: Did you know Snowy Mountain had such specific unlock requirements? I didn't. * Jak 1: Update Documentation. * Jak 1: Simplify user interaction with agents, make process more robust/less dependent on order of ops. * Jak 1: Simplified startup process, updated docs, prayed. * Jak 1: quick fix to settings. * Jak and Daxter: Implement New Game (#1) * Jak 1: Initial commit: Cell Locations, Items, and Regions modeled. * Jak 1: Wrote Regions, Rules, init. Untested. * Jak 1: Fixed mistakes, need better understanding of Entrances. * Jak 1: Fixed bugs, refactored Regions, added missing Special Checks. First spoiler log generated. * Jak 1: Add Scout Fly Locations, code and style cleanup. * Jak 1: Add Scout Flies to Regions. * Jak 1: Add version info. * Jak 1: Reduced code smell. * Jak 1: Fixed UT bugs, added Free The Sages as Locations. * Jak 1: Refactor ID scheme to better fit game's scheme. Add more subregions and rules, but still missing one-way Entrances. * Jak 1: Add some one-ways, adjust scout fly offset. * Jak 1: Found Scout Fly ID's for first 4 maps. * Jak 1: Add more scout fly ID's, refactor game/AP ID translation for easier reading and code reuse. * Jak 1: Fixed a few things. Four maps to go. * Jak 1: Last of the scout flies mapped! * Jak 1: simplify citadel sages logic. * Jak 1: WebWorld setup, some documentation. * Jak 1: Initial checkin of Client. Removed the colon from the game name. * Jak 1: Refactored client into components, working on async communication between the client and the game. * Jak 1: In tandem with new ArchipelaGOAL memory structure, define read_memory. * Jak 1: There's magic in the air... * Jak 1: Fixed bug translating scout fly ID's. * Jak 1: Make the REPL a little more verbose, easier to debug. * Jak 1: Did you know Snowy Mountain had such specific unlock requirements? I didn't. * Jak 1: Update Documentation. * Jak 1: Simplify user interaction with agents, make process more robust/less dependent on order of ops. * Jak 1: Simplified startup process, updated docs, prayed. * Jak 1: quick fix to settings. * Jak and Daxter: Genericize Items, Update Scout Fly logic, Add Victory Condition. (#3) * Jak 1: Update to 0.4.6. Decouple locations from items, support filler items. * Jak 1: Total revamp of Items. This is where everything broke. * Jak 1: Decouple 7 scout fly checks from normal checks, update regions/rules for orb counts/traders. * Jak 1: correct regions/rules, account for sequential oracle/miner locations. * Jak 1: make nicer strings. * Jak 1: Add logic for finished game. First full run complete! * Jak 1: update group names. * Jak and Daxter - Gondola, Pontoons, Rules, Regions, and Client Update * Jak 1: Overhaul of regions, rules, and special locations. Updated game info page. * Jak 1: Preparations for Alpha. Reintroducing automatic startup in client. Updating docs, readme, codeowners. * Alpha Updates (#15) * Jak 1: Consolidate client into apworld, create launcher icon, improve setup docs. * Jak 1: Update setup guide. * Jak 1: Load title screen, save states of in/outboxes. * Logging Update (#16) * Jak 1: Separate info and debug logs. * Jak 1: Update world info to refer to Archipelago Options menu. * Deathlink (#18) * Jak 1: Implement Deathlink. TODO: make it optional... * Jak 1: Issue a proper send-event for deathlink deaths. * Jak 1: Added cause of death to deathlink, fixed typo. * Jak 1: Make Deathlink toggleable. * Jak 1: Added player name to death text, added zoomer/flut/fishing text, simplified GOAL call for deathlink. * Jak 1: Fix death text in client logger. * Move Randomizer (#26) * Finally remove debug-segment text, update Python imports to relative paths. * HUGE refactor to Regions/Rules to support move rando, first hub area coded. * More refactoring. * Another refactor - may squash. * Fix some Rules, reuse some code by returning key regions from build_regions. * More regions added. A couple of TODOs. * Fixed trade logic, added LPC regions. * Added Spider, Snowy, Boggy. Fixed Misty's orbs. * Fix circular import, assert orb counts per level, fix a few naming errors. * Citadel added, missing locs and connections fixed. First move rando seed generated. * Add Move Rando to Options class. * Fixed rules for prerequisite moves. * Implement client functionality for move rando, add blurbs to game info page. * Fix wrong address for cache checks. * Fix byte alignment of offsets, refactor read_memory for better code reuse. * Refactor memory offsets and add some unit tests. * Make green eco the filler item, also define a maximum ID. Fix Boggy tether locations. * Move rando fixes (#29) * Fix virtual regions in Snowy. Fix some GMC problems. * Fix Deathlink on sunken slides. * Removed unncessary code causing build failure. * Orbsanity (#32) * My big dumb shortcut: a 2000 item array. * A better idea: bundle orbs as a numerical option and make array variable size. * Have Item/Region generation respect the chosen Orbsanity bundle size. Fix trade logic. * Separate Global/Local Orbsanity options. TODO - re-introduce orb factory for per-level option. * Per-level Orbsanity implemented w/ orb bundle factory. * Implement Orbsanity for client, fix some things up for regions. * Fix location name/id mappings. * Fix client orb collection on connection. * Fix minor Deathlink bug, add Update instructions. * Finishing Touches (#36) * Set up connector level thresholds, completion goal choices. * Send AP sender/recipient info to game via client. * Slight refactors. * Refactor option checking, add DataStorage handling of traded orbs. * Update instructions to change order of load/connect. * Add Option check to ensure enough Locations exist for Cell Count thresholds. Fix Final Door region. * Need some height move to get LPC sunken chamber cell. * Rename completion_condition to jak_completion_condition (#41) * The Afterparty (#42) * Fixes to Jak client, rules, options, and more. * Post-rebase fixes. * Remove orbsanity reset code, optimize game text in client. * More game text optimization. * Added more specific troubleshooting/setup instructions. * Add known issue about large releases taking time. (Dodge 6,666th commit.) * Remove "Bundle of", Add location name groups, set better default RootDirectory for new players. * Make orb trade amounts configurable, make orbsanity defaults more reasonable. * Add HUD info to doc. * Exempt's Code Review Updates (#43) * Round 1 of code review updates, the easy stuff. * Factor options checking away from region/rule creation. * Code review updates round 2, more complex stuff. * Code review updates round 3: the mental health annihilator * Code review updates part 4: redemption. * More code review feedback, simplifying code, etc. * Added a host.yaml option to override friendly limits, plus a couple of code review updates. * Added singleplayer limits, player names to enforcement rules. * Updated friendly limits to be more strict, optimized recalculate logic. * Today's the big day Jak: updates docs for mod support in OpenGOAL Launcher * Rearranged and clarified some instructions, ADDED PATH-SPACE FIX TO CLIENT. * Fix deathlink reset stalls on a busy client. (#47) * Jak & Daxter Client : queue game text messages to get items faster during release (#48) * queue game text messages to write them during the main_tick function and empty the message queue faster during release * wrap comment for code style character limit Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * remove useless blank line Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * whitespace code style Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * Move JsonMessageData dataclass outside of ReplClient class for code clarity --------- Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * Item Classifications (and REPL fixes) (#49) * Changes to item classifications * Bugfixes to power cell thresholds. * Fix bugs in item_type_helper. * Refactor 100 cell door to pass unit tests. * Quick fix to ReplClient. * Not so quick fix to ReplClient. * Display friendly limits in options tooltips. * Use math.ceil like a normal person. * Missed a space. * Fix non-accessibility due to bad orb calculation. * Updated documentation. * More Options, More Docs, More Tests (#51) * Reorder cell counts, require punch for Klaww. * Friendlier friendly friendlies. * Removed custom_worlds references from docs/setup guide, focused OpenGOAL Launcher language. * Increased breadth of unit tests. * Clean imports of unit tests. * Create OptionGroups. * Fix region rule bug with Punch for Klaww. * Include Punch For Klaww in slot data. * Update worlds/jakanddaxter/__init__.py Co-authored-by: Scipio Wright <scipiowright@gmail.com> * Temper and Harden Text Client (#52) * Provide config path so OpenGOAL can use mod-specific saves and settings. * Add versioning to MemoryReader. Harden the client against user errors. * Updated comments. * Add Deathlink as a "statement of intent" to the YAML. Small updates to client. * Revert deathlink changes. * Update error message. * Added color markup to log messages printed in text client. * Separate loggers by agent, write markup to GUI and non-markup to disk simultaneously. * Refactor MemoryReader callbacks from main_tick to constructor. * Make callback names more... informative. * Give users explicit instructions in error messages. * Stellar Messaging (#54) * Use new ap-messenger functions for text writing. * Remove Powershell requirement, bump memory version to 3. * Error message update w/ instructions for game crash. * Create no console window for gk. * ISO Data Enhancement (#58) * Add iso-path as argument to GOAL compiler. # Conflicts: # worlds/jakanddaxter/Client.py * More resilient handling of iso_path. * Fixed scout fly ID mismatches. * Corrected iso_data subpath. * Update memory version to 4. * Docs update for iso_data. * Auto Detect OpenGOAL Install (#63) * Auto detect OpenGOAL install path. Also fix Deathlink on server connection. * Updated docs, add instructions to error messages. * Slight tweak to error text. * J&D : add per region location groups (#64) * add per region power cells location group * add per region scout flies location group * add per zone orb bundle groups (I'm not particularly happy about this code, but I figured doing it this way was the point of least friction/duplication) * guess who forgot 9 very important characters in each line of the last commit * Rearrange location group names, quick fix to client error handling. * Fix pycharm warnings. * Fix more pycharm warnings. * Light cleanup: fix icons, add bug report page, remove py 3.8 code. * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Code review updates on comments, tooltips, and type hints. * Update type hint for lists in regions. * Missed todo removal. * More type hint updates. * Small region updates for location accessibility, small updates to world guide and README.md. * Add GMC scout fly location group. * Improved sanitization of game text. * Traps 2 (#70) * Add trap items, relevant options, and citadel orb caches. * Update REPL to send traps to game. * Fix item counter. * Allow player to select which traps to use. * Fix host.yaml doc strings, ap-setup-options typing, bump memory version to 5. * Alter some trap names. * Update world doc. * Add health trap. * Added 3 more trap types. * Protect against empty trap list. * Reword traps paragraph in world doc. * Another update to trap paragraph. * Concisify trap option docstring. * Timestamp on game log file. * Update client to handle waiting on title screen. * Send slot name and seed to game. * Use self.random instead. * Update setup doc for new title screen. * Quick clarification of orb caches in world doc. * Sanitize slot info earlier. * Added to and improved unit tests. * Light cleanup on world. * Optimizations to movement rules, docs: known issues update. * Quick fixes for beta 0.5.0 release: template options and LPC logic. * Quick fix to spoiler counts. * Reorganize world guide for faster navigation. * Fix links. * Update HUD section. * Found a way to render apostrophes in item names. * March Refactors (#77) * Reorg imports, small fix to Rock Village movement. * Fix wait-on-title message never going to ready message. * Colorama init fix. * Swap trap list for a dictionary of trap weights. * The more laws, the less justice. * Quick readability update. * Have memory reader provide instructions for slow booting games. * Revert some things. * Update setup_en.md * Update HUD mode lingo for combined msgs. * Remade launcher icon, sized correctly. * I don't know why I can't be satisfied with things. * Apply suggestions from Scipio Co-authored-by: Scipio Wright <scipiowright@gmail.com> * Properly use the settings API instead of Utils. * Newline on requirements.txt. * Add __init__ files for frozen builds. * Replace an ap_inform function with a CommonClient built-in. * Resize icon to match kivymd expected size. * First round of Treble code reviews. * Second round of Treble code reviews. * Third round of Treble code reviews. * Missed an unncessary if condition. * Missed unnecessary comments. * Fourth round of Treble code reviews. * Switch trap dictionary to OptionCounter. * Use existing slot name/seed from network protocol. * Violet code review updates. * Violet code review updates part 2. * Refactor to avoid floating imports (Violet part 3). * Found a few more valid characters for messaging. * Move tests out of init, add colon to game name (now that it's safe). * But don't include those chars for file text. * Implement Vi suggestion on webhost-capable friendly limits. * Revert "Implement Vi suggestion on webhost-capable friendly limits." This reverts commit 2d012b7f4a9a4c13985ecd7303bb1fc646831c86. * Rename all files for PEP8. * Refactor how maximums work on webhost. * Fix rogue UT. * Don't rush. * Fix client post-PEP8. --------- Co-authored-by: Justus Lind <DeamonHunter@users.noreply.github.com> Co-authored-by: Romain BERNARD <30secondstodraw@gmail.com> Co-authored-by: Scipio Wright <scipiowright@gmail.com> Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com>
2025-05-21 08:12:27 -04:00
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
with open(settings_path, "r") as f:
load = json.load(f)
# This settings file has changed format once before, and may do so again in the future.
# Guard against future incompatibilities by checking the file version first, and use that to determine
# what JSON keys to look for next.
try:
settings_version = load["version"]
logger.debug(f"OpenGOAL settings file version: {settings_version}")
except KeyError:
msg = (f"{err_title}: The OpenGOAL settings file has no version number!\n"
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
try:
if settings_version == "2.0":
jak1_installed = load["games"]["Jak 1"]["isInstalled"]
mod_sources = load["games"]["Jak 1"]["modsInstalledVersion"]
elif settings_version == "3.0":
jak1_installed = load["games"]["jak1"]["isInstalled"]
mod_sources = load["games"]["jak1"]["mods"]
else:
msg = (f"{err_title}: The OpenGOAL settings file has an unknown version number ({settings_version}).\n"
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
except KeyError as e:
msg = (f"{err_title}: The OpenGOAL settings file does not contain key entry {e}!\n"
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
Jak and Daxter: Implement New Game (#3291) * Jak 1: Initial commit: Cell Locations, Items, and Regions modeled. * Jak 1: Wrote Regions, Rules, init. Untested. * Jak 1: Fixed mistakes, need better understanding of Entrances. * Jak 1: Fixed bugs, refactored Regions, added missing Special Checks. First spoiler log generated. * Jak 1: Add Scout Fly Locations, code and style cleanup. * Jak 1: Add Scout Flies to Regions. * Jak 1: Add version info. * Jak 1: Reduced code smell. * Jak 1: Fixed UT bugs, added Free The Sages as Locations. * Jak 1: Refactor ID scheme to better fit game's scheme. Add more subregions and rules, but still missing one-way Entrances. * Jak 1: Add some one-ways, adjust scout fly offset. * Jak 1: Found Scout Fly ID's for first 4 maps. * Jak 1: Add more scout fly ID's, refactor game/AP ID translation for easier reading and code reuse. * Jak 1: Fixed a few things. Four maps to go. * Jak 1: Last of the scout flies mapped! * Jak 1: simplify citadel sages logic. * Jak 1: WebWorld setup, some documentation. * Jak 1: Initial checkin of Client. Removed the colon from the game name. * Jak 1: Refactored client into components, working on async communication between the client and the game. * Jak 1: In tandem with new ArchipelaGOAL memory structure, define read_memory. * Jak 1: There's magic in the air... * Jak 1: Fixed bug translating scout fly ID's. * Jak 1: Make the REPL a little more verbose, easier to debug. * Jak 1: Did you know Snowy Mountain had such specific unlock requirements? I didn't. * Jak 1: Update Documentation. * Jak 1: Simplify user interaction with agents, make process more robust/less dependent on order of ops. * Jak 1: Simplified startup process, updated docs, prayed. * Jak 1: quick fix to settings. * Jak and Daxter: Implement New Game (#1) * Jak 1: Initial commit: Cell Locations, Items, and Regions modeled. * Jak 1: Wrote Regions, Rules, init. Untested. * Jak 1: Fixed mistakes, need better understanding of Entrances. * Jak 1: Fixed bugs, refactored Regions, added missing Special Checks. First spoiler log generated. * Jak 1: Add Scout Fly Locations, code and style cleanup. * Jak 1: Add Scout Flies to Regions. * Jak 1: Add version info. * Jak 1: Reduced code smell. * Jak 1: Fixed UT bugs, added Free The Sages as Locations. * Jak 1: Refactor ID scheme to better fit game's scheme. Add more subregions and rules, but still missing one-way Entrances. * Jak 1: Add some one-ways, adjust scout fly offset. * Jak 1: Found Scout Fly ID's for first 4 maps. * Jak 1: Add more scout fly ID's, refactor game/AP ID translation for easier reading and code reuse. * Jak 1: Fixed a few things. Four maps to go. * Jak 1: Last of the scout flies mapped! * Jak 1: simplify citadel sages logic. * Jak 1: WebWorld setup, some documentation. * Jak 1: Initial checkin of Client. Removed the colon from the game name. * Jak 1: Refactored client into components, working on async communication between the client and the game. * Jak 1: In tandem with new ArchipelaGOAL memory structure, define read_memory. * Jak 1: There's magic in the air... * Jak 1: Fixed bug translating scout fly ID's. * Jak 1: Make the REPL a little more verbose, easier to debug. * Jak 1: Did you know Snowy Mountain had such specific unlock requirements? I didn't. * Jak 1: Update Documentation. * Jak 1: Simplify user interaction with agents, make process more robust/less dependent on order of ops. * Jak 1: Simplified startup process, updated docs, prayed. * Jak 1: quick fix to settings. * Jak and Daxter: Genericize Items, Update Scout Fly logic, Add Victory Condition. (#3) * Jak 1: Update to 0.4.6. Decouple locations from items, support filler items. * Jak 1: Total revamp of Items. This is where everything broke. * Jak 1: Decouple 7 scout fly checks from normal checks, update regions/rules for orb counts/traders. * Jak 1: correct regions/rules, account for sequential oracle/miner locations. * Jak 1: make nicer strings. * Jak 1: Add logic for finished game. First full run complete! * Jak 1: update group names. * Jak and Daxter - Gondola, Pontoons, Rules, Regions, and Client Update * Jak 1: Overhaul of regions, rules, and special locations. Updated game info page. * Jak 1: Preparations for Alpha. Reintroducing automatic startup in client. Updating docs, readme, codeowners. * Alpha Updates (#15) * Jak 1: Consolidate client into apworld, create launcher icon, improve setup docs. * Jak 1: Update setup guide. * Jak 1: Load title screen, save states of in/outboxes. * Logging Update (#16) * Jak 1: Separate info and debug logs. * Jak 1: Update world info to refer to Archipelago Options menu. * Deathlink (#18) * Jak 1: Implement Deathlink. TODO: make it optional... * Jak 1: Issue a proper send-event for deathlink deaths. * Jak 1: Added cause of death to deathlink, fixed typo. * Jak 1: Make Deathlink toggleable. * Jak 1: Added player name to death text, added zoomer/flut/fishing text, simplified GOAL call for deathlink. * Jak 1: Fix death text in client logger. * Move Randomizer (#26) * Finally remove debug-segment text, update Python imports to relative paths. * HUGE refactor to Regions/Rules to support move rando, first hub area coded. * More refactoring. * Another refactor - may squash. * Fix some Rules, reuse some code by returning key regions from build_regions. * More regions added. A couple of TODOs. * Fixed trade logic, added LPC regions. * Added Spider, Snowy, Boggy. Fixed Misty's orbs. * Fix circular import, assert orb counts per level, fix a few naming errors. * Citadel added, missing locs and connections fixed. First move rando seed generated. * Add Move Rando to Options class. * Fixed rules for prerequisite moves. * Implement client functionality for move rando, add blurbs to game info page. * Fix wrong address for cache checks. * Fix byte alignment of offsets, refactor read_memory for better code reuse. * Refactor memory offsets and add some unit tests. * Make green eco the filler item, also define a maximum ID. Fix Boggy tether locations. * Move rando fixes (#29) * Fix virtual regions in Snowy. Fix some GMC problems. * Fix Deathlink on sunken slides. * Removed unncessary code causing build failure. * Orbsanity (#32) * My big dumb shortcut: a 2000 item array. * A better idea: bundle orbs as a numerical option and make array variable size. * Have Item/Region generation respect the chosen Orbsanity bundle size. Fix trade logic. * Separate Global/Local Orbsanity options. TODO - re-introduce orb factory for per-level option. * Per-level Orbsanity implemented w/ orb bundle factory. * Implement Orbsanity for client, fix some things up for regions. * Fix location name/id mappings. * Fix client orb collection on connection. * Fix minor Deathlink bug, add Update instructions. * Finishing Touches (#36) * Set up connector level thresholds, completion goal choices. * Send AP sender/recipient info to game via client. * Slight refactors. * Refactor option checking, add DataStorage handling of traded orbs. * Update instructions to change order of load/connect. * Add Option check to ensure enough Locations exist for Cell Count thresholds. Fix Final Door region. * Need some height move to get LPC sunken chamber cell. * Rename completion_condition to jak_completion_condition (#41) * The Afterparty (#42) * Fixes to Jak client, rules, options, and more. * Post-rebase fixes. * Remove orbsanity reset code, optimize game text in client. * More game text optimization. * Added more specific troubleshooting/setup instructions. * Add known issue about large releases taking time. (Dodge 6,666th commit.) * Remove "Bundle of", Add location name groups, set better default RootDirectory for new players. * Make orb trade amounts configurable, make orbsanity defaults more reasonable. * Add HUD info to doc. * Exempt's Code Review Updates (#43) * Round 1 of code review updates, the easy stuff. * Factor options checking away from region/rule creation. * Code review updates round 2, more complex stuff. * Code review updates round 3: the mental health annihilator * Code review updates part 4: redemption. * More code review feedback, simplifying code, etc. * Added a host.yaml option to override friendly limits, plus a couple of code review updates. * Added singleplayer limits, player names to enforcement rules. * Updated friendly limits to be more strict, optimized recalculate logic. * Today's the big day Jak: updates docs for mod support in OpenGOAL Launcher * Rearranged and clarified some instructions, ADDED PATH-SPACE FIX TO CLIENT. * Fix deathlink reset stalls on a busy client. (#47) * Jak & Daxter Client : queue game text messages to get items faster during release (#48) * queue game text messages to write them during the main_tick function and empty the message queue faster during release * wrap comment for code style character limit Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * remove useless blank line Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * whitespace code style Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * Move JsonMessageData dataclass outside of ReplClient class for code clarity --------- Co-authored-by: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> * Item Classifications (and REPL fixes) (#49) * Changes to item classifications * Bugfixes to power cell thresholds. * Fix bugs in item_type_helper. * Refactor 100 cell door to pass unit tests. * Quick fix to ReplClient. * Not so quick fix to ReplClient. * Display friendly limits in options tooltips. * Use math.ceil like a normal person. * Missed a space. * Fix non-accessibility due to bad orb calculation. * Updated documentation. * More Options, More Docs, More Tests (#51) * Reorder cell counts, require punch for Klaww. * Friendlier friendly friendlies. * Removed custom_worlds references from docs/setup guide, focused OpenGOAL Launcher language. * Increased breadth of unit tests. * Clean imports of unit tests. * Create OptionGroups. * Fix region rule bug with Punch for Klaww. * Include Punch For Klaww in slot data. * Update worlds/jakanddaxter/__init__.py Co-authored-by: Scipio Wright <scipiowright@gmail.com> * Temper and Harden Text Client (#52) * Provide config path so OpenGOAL can use mod-specific saves and settings. * Add versioning to MemoryReader. Harden the client against user errors. * Updated comments. * Add Deathlink as a "statement of intent" to the YAML. Small updates to client. * Revert deathlink changes. * Update error message. * Added color markup to log messages printed in text client. * Separate loggers by agent, write markup to GUI and non-markup to disk simultaneously. * Refactor MemoryReader callbacks from main_tick to constructor. * Make callback names more... informative. * Give users explicit instructions in error messages. * Stellar Messaging (#54) * Use new ap-messenger functions for text writing. * Remove Powershell requirement, bump memory version to 3. * Error message update w/ instructions for game crash. * Create no console window for gk. * ISO Data Enhancement (#58) * Add iso-path as argument to GOAL compiler. # Conflicts: # worlds/jakanddaxter/Client.py * More resilient handling of iso_path. * Fixed scout fly ID mismatches. * Corrected iso_data subpath. * Update memory version to 4. * Docs update for iso_data. * Auto Detect OpenGOAL Install (#63) * Auto detect OpenGOAL install path. Also fix Deathlink on server connection. * Updated docs, add instructions to error messages. * Slight tweak to error text. * J&D : add per region location groups (#64) * add per region power cells location group * add per region scout flies location group * add per zone orb bundle groups (I'm not particularly happy about this code, but I figured doing it this way was the point of least friction/duplication) * guess who forgot 9 very important characters in each line of the last commit * Rearrange location group names, quick fix to client error handling. * Fix pycharm warnings. * Fix more pycharm warnings. * Light cleanup: fix icons, add bug report page, remove py 3.8 code. * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Update worlds/jakanddaxter/Options.py Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> * Code review updates on comments, tooltips, and type hints. * Update type hint for lists in regions. * Missed todo removal. * More type hint updates. * Small region updates for location accessibility, small updates to world guide and README.md. * Add GMC scout fly location group. * Improved sanitization of game text. * Traps 2 (#70) * Add trap items, relevant options, and citadel orb caches. * Update REPL to send traps to game. * Fix item counter. * Allow player to select which traps to use. * Fix host.yaml doc strings, ap-setup-options typing, bump memory version to 5. * Alter some trap names. * Update world doc. * Add health trap. * Added 3 more trap types. * Protect against empty trap list. * Reword traps paragraph in world doc. * Another update to trap paragraph. * Concisify trap option docstring. * Timestamp on game log file. * Update client to handle waiting on title screen. * Send slot name and seed to game. * Use self.random instead. * Update setup doc for new title screen. * Quick clarification of orb caches in world doc. * Sanitize slot info earlier. * Added to and improved unit tests. * Light cleanup on world. * Optimizations to movement rules, docs: known issues update. * Quick fixes for beta 0.5.0 release: template options and LPC logic. * Quick fix to spoiler counts. * Reorganize world guide for faster navigation. * Fix links. * Update HUD section. * Found a way to render apostrophes in item names. * March Refactors (#77) * Reorg imports, small fix to Rock Village movement. * Fix wait-on-title message never going to ready message. * Colorama init fix. * Swap trap list for a dictionary of trap weights. * The more laws, the less justice. * Quick readability update. * Have memory reader provide instructions for slow booting games. * Revert some things. * Update setup_en.md * Update HUD mode lingo for combined msgs. * Remade launcher icon, sized correctly. * I don't know why I can't be satisfied with things. * Apply suggestions from Scipio Co-authored-by: Scipio Wright <scipiowright@gmail.com> * Properly use the settings API instead of Utils. * Newline on requirements.txt. * Add __init__ files for frozen builds. * Replace an ap_inform function with a CommonClient built-in. * Resize icon to match kivymd expected size. * First round of Treble code reviews. * Second round of Treble code reviews. * Third round of Treble code reviews. * Missed an unncessary if condition. * Missed unnecessary comments. * Fourth round of Treble code reviews. * Switch trap dictionary to OptionCounter. * Use existing slot name/seed from network protocol. * Violet code review updates. * Violet code review updates part 2. * Refactor to avoid floating imports (Violet part 3). * Found a few more valid characters for messaging. * Move tests out of init, add colon to game name (now that it's safe). * But don't include those chars for file text. * Implement Vi suggestion on webhost-capable friendly limits. * Revert "Implement Vi suggestion on webhost-capable friendly limits." This reverts commit 2d012b7f4a9a4c13985ecd7303bb1fc646831c86. * Rename all files for PEP8. * Refactor how maximums work on webhost. * Fix rogue UT. * Don't rush. * Fix client post-PEP8. --------- Co-authored-by: Justus Lind <DeamonHunter@users.noreply.github.com> Co-authored-by: Romain BERNARD <30secondstodraw@gmail.com> Co-authored-by: Scipio Wright <scipiowright@gmail.com> Co-authored-by: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com>
2025-05-21 08:12:27 -04:00
if not jak1_installed:
msg = (f"{err_title}: The OpenGOAL Launcher is missing a normal install of Jak 1!\n"
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
if mod_sources is None:
msg = (f"{err_title}: No mod sources have been configured in the OpenGOAL Launcher!\n"
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
# Mods can come from multiple user-defined sources.
# Make no assumptions about where ArchipelaGOAL comes from, we should find it ourselves.
archipelagoal_source = None
for src in mod_sources:
for mod in mod_sources[src].keys():
if mod == "archipelagoal":
archipelagoal_source = src
# Using this file, we could verify the right version is installed, but we don't need to.
if archipelagoal_source is None:
msg = (f"{err_title}: The ArchipelaGOAL mod is not installed in the OpenGOAL Launcher!\n"
f"{alt_instructions}")
ctx.on_log_error(logger, msg)
return
# This is just the base OpenGOAL directory, we need to go deeper.
base_path = load["installationDir"]
mod_relative_path = f"features/jak1/mods/{archipelagoal_source}/archipelagoal"
mod_path = os.path.normpath(
os.path.join(
os.path.normpath(base_path),
os.path.normpath(mod_relative_path)))
return mod_path
async def run_game(ctx: JakAndDaxterContext):
# These may already be running. If they are not running, try to start them.
# TODO - Support other OS's. 1: Pymem is Windows-only. 2: on Linux, there's no ".exe."
gk_running = False
try:
pymem.Pymem("gk.exe") # The GOAL Kernel
gk_running = True
except ProcessNotFound:
ctx.on_log_warn(logger, "Game not running, attempting to start.")
goalc_running = False
try:
pymem.Pymem("goalc.exe") # The GOAL Compiler and REPL
goalc_running = True
except ProcessNotFound:
ctx.on_log_warn(logger, "Compiler not running, attempting to start.")
try:
auto_detect_root_directory = JakAndDaxterWorld.settings.auto_detect_root_directory
if auto_detect_root_directory:
root_path = find_root_directory(ctx)
else:
root_path = JakAndDaxterWorld.settings.root_directory
# Always trust your instincts... the user may not have entered their root_directory properly.
# We don't have to do this check if the root directory was auto-detected.
if "/" not in root_path:
msg = (f"The ArchipelaGOAL root directory contains no path. (Are you missing forward slashes?)\n"
f"Please check your host.yaml file.\n"
f"Verify the value of 'jakanddaxter_options > root_directory' is a valid existing path, "
f"and all backslashes have been replaced with forward slashes.")
ctx.on_log_error(logger, msg)
return
# Start by checking the existence of the root directory provided in the host.yaml file (or found automatically).
root_path = os.path.normpath(root_path)
if not os.path.exists(root_path):
msg = (f"The ArchipelaGOAL root directory does not exist, unable to locate the Game and Compiler.\n"
f"Please check your host.yaml file.\n"
f"If the value of 'jakanddaxter_options > auto_detect_root_directory' is true, verify that OpenGOAL "
f"is installed properly.\n"
f"If it is false, check the value of 'jakanddaxter_options > root_directory'. "
f"Verify it is a valid existing path, and all backslashes have been replaced with forward slashes.")
ctx.on_log_error(logger, msg)
return
# Now double-check the existence of the two executables we need.
gk_path = os.path.join(root_path, "gk.exe")
goalc_path = os.path.join(root_path, "goalc.exe")
if not os.path.exists(gk_path) or not os.path.exists(goalc_path):
msg = (f"The Game and Compiler could not be found in the ArchipelaGOAL root directory.\n"
f"Please check your host.yaml file.\n"
f"If the value of 'jakanddaxter_options > auto_detect_root_directory' is true, verify that OpenGOAL "
f"is installed properly.\n"
f"If it is false, check the value of 'jakanddaxter_options > root_directory'. "
f"Verify it is a valid existing path, and all backslashes have been replaced with forward slashes.")
ctx.on_log_error(logger, msg)
return
# Now we can FINALLY attempt to start the programs.
if not gk_running:
# Per-mod saves and settings are stored outside the ArchipelaGOAL root folder, so we have to traverse
# a relative path, normalize it, and pass it in as an argument to gk. This folder will be created if
# it does not exist.
config_relative_path = "../_settings/archipelagoal"
config_path = os.path.normpath(
os.path.join(
root_path,
os.path.normpath(config_relative_path)))
# The game freezes if text is inadvertently selected in the stdout/stderr data streams. Let's pipe those
# streams to a file, and let's not clutter the screen with another console window.
timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
log_path = os.path.join(Utils.user_path("logs"), f"JakAndDaxterGame_{timestamp}.txt")
log_path = os.path.normpath(log_path)
with open(log_path, "w") as log_file:
gk_process = subprocess.Popen(
[gk_path, "--game", "jak1",
"--config-path", config_path,
"--", "-v", "-boot", "-fakeiso", "-debug"],
stdout=log_file,
stderr=log_file,
creationflags=subprocess.CREATE_NO_WINDOW)
if not goalc_running:
# For the OpenGOAL Compiler, the existence of the "data" subfolder indicates you are running it from
# a built package. This subfolder is treated as its proj_path.
proj_path = os.path.join(root_path, "data")
if os.path.exists(proj_path):
# Look for "iso_data" path to automate away an oft-forgotten manual step of mod updates.
# All relative paths should start from root_path and end with "jak1".
goalc_args = []
possible_relative_paths = {
"../../../../../active/jak1/data/iso_data/jak1",
"./data/iso_data/jak1",
}
for iso_relative_path in possible_relative_paths:
iso_path = os.path.normpath(
os.path.join(
root_path,
os.path.normpath(iso_relative_path)))
if os.path.exists(iso_path):
goalc_args = [goalc_path, "--game", "jak1", "--proj-path", proj_path, "--iso-path", iso_path]
logger.debug(f"iso_data folder found: {iso_path}")
break
else:
logger.debug(f"iso_data folder not found, continuing: {iso_path}")
if not goalc_args:
msg = (f"The iso_data folder could not be found.\n"
f"Please follow these steps:\n"
f" Run the OpenGOAL Launcher, click Jak and Daxter > Advanced > Open Game Data Folder.\n"
f" Copy the iso_data folder from this location.\n"
f" Click Jak and Daxter > Features > Mods > ArchipelaGOAL > Advanced > "
f"Open Game Data Folder.\n"
f" Paste the iso_data folder in this location.\n"
f" Click Advanced > Compile. When this is done, click Continue.\n"
f" Close all launchers, games, clients, and console windows, then restart Archipelago.\n"
f"(See Setup Guide for more details.)")
ctx.on_log_error(logger, msg)
return
# The non-existence of the "data" subfolder indicates you are running it from source, as a developer.
# The compiler will traverse upward to find the project path on its own. It will also assume your
# "iso_data" folder is at the root of your repository. Therefore, we don't need any of those arguments.
else:
goalc_args = [goalc_path, "--game", "jak1"]
# This needs to be a new console. The REPL console cannot share a window with any other process.
goalc_process = subprocess.Popen(goalc_args, creationflags=subprocess.CREATE_NEW_CONSOLE)
except AttributeError as e:
if " " in e.args[0]:
# YAML keys in Host.yaml ought to contain no spaces, which means this is a much more important error.
ctx.on_log_error(logger, e.args[0])
else:
ctx.on_log_error(logger,
f"Host.yaml does not contain {e.args[0]}, unable to locate game executables.")
return
except FileNotFoundError as e:
msg = (f"The following path could not be found: {e.filename}\n"
f"Please check your host.yaml file.\n"
f"If the value of 'jakanddaxter_options > auto_detect_root_directory' is true, verify that OpenGOAL "
f"is installed properly.\n"
f"If it is false, check the value of 'jakanddaxter_options > root_directory'."
f"Verify it is a valid existing path, and all backslashes have been replaced with forward slashes.")
ctx.on_log_error(logger, msg)
return
# Auto connect the repl and memr agents. Sleep 5 because goalc takes just a little bit of time to load,
# and it's not something we can await.
ctx.on_log_info(logger, "This may take a bit... Wait for the game's title sequence before continuing!")
await asyncio.sleep(5)
ctx.repl.initiated_connect = True
ctx.memr.initiated_connect = True
async def main():
Utils.init_logging("JakAndDaxterClient", exception_logger="Client")
ctx = JakAndDaxterContext(None, None)
ctx.server_task = asyncio.create_task(server_loop(ctx), name="server loop")
ctx.repl_task = create_task_log_exception(ctx.run_repl_loop())
ctx.memr_task = create_task_log_exception(ctx.run_memr_loop())
if gui_enabled:
ctx.run_gui()
ctx.run_cli()
# Find and run the game (gk) and compiler/repl (goalc).
create_task_log_exception(run_game(ctx))
await ctx.exit_event.wait()
await ctx.shutdown()
def launch():
# use colorama to display colored text highlighting
colorama.just_fix_windows_console()
asyncio.run(main())
colorama.deinit()