2024-06-06 18:36:14 +00:00
|
|
|
import bisect
|
2024-06-05 23:36:02 +00:00
|
|
|
import logging
|
|
|
|
import pathlib
|
2023-06-27 07:30:54 +00:00
|
|
|
import weakref
|
2023-03-20 20:24:47 +00:00
|
|
|
from enum import Enum, auto
|
2024-06-05 23:36:02 +00:00
|
|
|
from typing import Optional, Callable, List, Iterable, Tuple
|
2023-03-20 20:24:47 +00:00
|
|
|
|
2024-06-05 23:36:02 +00:00
|
|
|
from Utils import local_path, open_filename
|
2023-03-20 20:24:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Type(Enum):
|
|
|
|
TOOL = auto()
|
2023-06-19 07:57:17 +00:00
|
|
|
MISC = auto()
|
2023-03-20 20:24:47 +00:00
|
|
|
CLIENT = auto()
|
|
|
|
ADJUSTER = auto()
|
2023-06-19 07:57:17 +00:00
|
|
|
FUNC = auto() # do not use anymore
|
|
|
|
HIDDEN = auto()
|
2023-03-20 20:24:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Component:
|
|
|
|
display_name: str
|
2023-06-19 07:57:17 +00:00
|
|
|
type: Type
|
2023-03-20 20:24:47 +00:00
|
|
|
script_name: Optional[str]
|
|
|
|
frozen_name: Optional[str]
|
|
|
|
icon: str # just the name, no suffix
|
|
|
|
cli: bool
|
|
|
|
func: Optional[Callable]
|
|
|
|
file_identifier: Optional[Callable[[str], bool]]
|
|
|
|
|
|
|
|
def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_name: Optional[str] = None,
|
2023-06-19 07:57:17 +00:00
|
|
|
cli: bool = False, icon: str = 'icon', component_type: Optional[Type] = None,
|
|
|
|
func: Optional[Callable] = None, file_identifier: Optional[Callable[[str], bool]] = None):
|
2023-03-20 20:24:47 +00:00
|
|
|
self.display_name = display_name
|
|
|
|
self.script_name = script_name
|
|
|
|
self.frozen_name = frozen_name or f'Archipelago{script_name}' if script_name else None
|
|
|
|
self.icon = icon
|
|
|
|
self.cli = cli
|
2023-06-19 07:57:17 +00:00
|
|
|
if component_type == Type.FUNC:
|
|
|
|
from Utils import deprecate
|
|
|
|
deprecate(f"Launcher Component {self.display_name} is using Type.FUNC Type, which is pending removal.")
|
|
|
|
component_type = Type.MISC
|
|
|
|
|
|
|
|
self.type = component_type or (
|
|
|
|
Type.CLIENT if "Client" in display_name else
|
|
|
|
Type.ADJUSTER if "Adjuster" in display_name else Type.MISC)
|
2023-03-20 20:24:47 +00:00
|
|
|
self.func = func
|
|
|
|
self.file_identifier = file_identifier
|
|
|
|
|
|
|
|
def handles_file(self, path: str):
|
|
|
|
return self.file_identifier(path) if self.file_identifier else False
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f"{self.__class__.__name__}({self.display_name})"
|
|
|
|
|
2024-06-05 23:36:02 +00:00
|
|
|
|
2023-06-27 07:30:54 +00:00
|
|
|
processes = weakref.WeakSet()
|
|
|
|
|
2024-06-05 23:36:02 +00:00
|
|
|
|
2023-06-25 00:31:25 +00:00
|
|
|
def launch_subprocess(func: Callable, name: str = None):
|
2023-06-27 07:30:54 +00:00
|
|
|
global processes
|
2023-06-25 00:31:25 +00:00
|
|
|
import multiprocessing
|
2023-06-27 07:30:54 +00:00
|
|
|
process = multiprocessing.Process(target=func, name=name)
|
2023-06-25 00:31:25 +00:00
|
|
|
process.start()
|
2023-06-27 07:30:54 +00:00
|
|
|
processes.add(process)
|
2023-03-20 20:24:47 +00:00
|
|
|
|
2024-06-05 23:36:02 +00:00
|
|
|
|
2023-03-20 20:24:47 +00:00
|
|
|
class SuffixIdentifier:
|
|
|
|
suffixes: Iterable[str]
|
|
|
|
|
|
|
|
def __init__(self, *args: str):
|
|
|
|
self.suffixes = args
|
|
|
|
|
2024-04-16 21:03:30 +00:00
|
|
|
def __call__(self, path: str) -> bool:
|
2023-03-20 20:24:47 +00:00
|
|
|
if isinstance(path, str):
|
|
|
|
for suffix in self.suffixes:
|
|
|
|
if path.endswith(suffix):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-06-25 00:31:25 +00:00
|
|
|
def launch_textclient():
|
|
|
|
import CommonClient
|
|
|
|
launch_subprocess(CommonClient.run_as_textclient, name="TextClient")
|
|
|
|
|
|
|
|
|
2024-06-05 23:36:02 +00:00
|
|
|
def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, pathlib.Path]]:
|
|
|
|
if not apworld_src:
|
|
|
|
apworld_src = open_filename('Select APWorld file to install', (('APWorld', ('.apworld',)),))
|
|
|
|
if not apworld_src:
|
|
|
|
# user closed menu
|
|
|
|
return
|
|
|
|
|
|
|
|
if not apworld_src.endswith(".apworld"):
|
|
|
|
raise Exception(f"Wrong file format, looking for .apworld. File identified: {apworld_src}")
|
|
|
|
|
|
|
|
apworld_path = pathlib.Path(apworld_src)
|
|
|
|
|
2024-06-06 18:36:14 +00:00
|
|
|
module_name = pathlib.Path(apworld_path.name).stem
|
2024-06-05 23:36:02 +00:00
|
|
|
try:
|
|
|
|
import zipfile
|
2024-06-06 18:36:14 +00:00
|
|
|
zipfile.ZipFile(apworld_path).open(module_name + "/__init__.py")
|
2024-06-05 23:36:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raise Exception("Archive appears invalid or damaged.") from e
|
|
|
|
except KeyError as e:
|
|
|
|
raise Exception("Archive appears to not be an apworld. (missing __init__.py)") from e
|
|
|
|
|
|
|
|
import worlds
|
|
|
|
if worlds.user_folder is None:
|
|
|
|
raise Exception("Custom Worlds directory appears to not be writable.")
|
|
|
|
for world_source in worlds.world_sources:
|
|
|
|
if apworld_path.samefile(world_source.resolved_path):
|
2024-06-06 18:36:14 +00:00
|
|
|
# Note that this doesn't check if the same world is already installed.
|
|
|
|
# It only checks if the user is trying to install the apworld file
|
|
|
|
# that comes from the installation location (worlds or custom_worlds)
|
2024-06-05 23:36:02 +00:00
|
|
|
raise Exception(f"APWorld is already installed at {world_source.resolved_path}.")
|
|
|
|
|
|
|
|
# TODO: run generic test suite over the apworld.
|
|
|
|
# TODO: have some kind of version system to tell from metadata if the apworld should be compatible.
|
|
|
|
|
|
|
|
target = pathlib.Path(worlds.user_folder) / apworld_path.name
|
|
|
|
import shutil
|
|
|
|
shutil.copyfile(apworld_path, target)
|
|
|
|
|
2024-06-06 18:36:14 +00:00
|
|
|
# If a module with this name is already loaded, then we can't load it now.
|
|
|
|
# TODO: We need to be able to unload a world module,
|
|
|
|
# so the user can update a world without restarting the application.
|
|
|
|
found_already_loaded = False
|
|
|
|
for loaded_world in worlds.world_sources:
|
|
|
|
loaded_name = pathlib.Path(loaded_world.path).stem
|
|
|
|
if module_name == loaded_name:
|
|
|
|
found_already_loaded = True
|
|
|
|
break
|
|
|
|
if found_already_loaded:
|
|
|
|
raise Exception(f"Installed APWorld successfully, but '{module_name}' is already loaded,\n"
|
|
|
|
"so a Launcher restart is required to use the new installation.")
|
|
|
|
world_source = worlds.WorldSource(str(target), is_zip=True)
|
|
|
|
bisect.insort(worlds.world_sources, world_source)
|
|
|
|
world_source.load()
|
|
|
|
|
2024-06-05 23:36:02 +00:00
|
|
|
return apworld_path, target
|
|
|
|
|
|
|
|
|
|
|
|
def install_apworld(apworld_path: str = "") -> None:
|
|
|
|
try:
|
|
|
|
res = _install_apworld(apworld_path)
|
|
|
|
if res is None:
|
|
|
|
logging.info("Aborting APWorld installation.")
|
|
|
|
return
|
|
|
|
source, target = res
|
|
|
|
except Exception as e:
|
|
|
|
import Utils
|
|
|
|
Utils.messagebox(e.__class__.__name__, str(e), error=True)
|
|
|
|
logging.exception(e)
|
|
|
|
else:
|
|
|
|
import Utils
|
|
|
|
logging.info(f"Installed APWorld successfully, copied {source} to {target}.")
|
|
|
|
Utils.messagebox("Install complete.", f"Installed APWorld from {source}.")
|
|
|
|
|
|
|
|
|
2023-03-20 20:24:47 +00:00
|
|
|
components: List[Component] = [
|
|
|
|
# Launcher
|
2023-06-19 07:57:17 +00:00
|
|
|
Component('Launcher', 'Launcher', component_type=Type.HIDDEN),
|
2023-03-20 20:24:47 +00:00
|
|
|
# Core
|
|
|
|
Component('Host', 'MultiServer', 'ArchipelagoServer', cli=True,
|
|
|
|
file_identifier=SuffixIdentifier('.archipelago', '.zip')),
|
|
|
|
Component('Generate', 'Generate', cli=True),
|
2024-06-05 23:36:02 +00:00
|
|
|
Component("Install APWorld", func=install_apworld, file_identifier=SuffixIdentifier(".apworld")),
|
2023-06-25 00:31:25 +00:00
|
|
|
Component('Text Client', 'CommonClient', 'ArchipelagoTextClient', func=launch_textclient),
|
2023-03-20 20:24:47 +00:00
|
|
|
Component('Links Awakening DX Client', 'LinksAwakeningClient',
|
|
|
|
file_identifier=SuffixIdentifier('.apladx')),
|
|
|
|
Component('LttP Adjuster', 'LttPAdjuster'),
|
|
|
|
# Minecraft
|
|
|
|
Component('Minecraft Client', 'MinecraftClient', icon='mcicon', cli=True,
|
|
|
|
file_identifier=SuffixIdentifier('.apmc')),
|
|
|
|
# Ocarina of Time
|
|
|
|
Component('OoT Client', 'OoTClient',
|
|
|
|
file_identifier=SuffixIdentifier('.apz5')),
|
|
|
|
Component('OoT Adjuster', 'OoTAdjuster'),
|
|
|
|
# FF1
|
|
|
|
Component('FF1 Client', 'FF1Client'),
|
|
|
|
# TLoZ
|
2023-06-29 00:06:45 +00:00
|
|
|
Component('Zelda 1 Client', 'Zelda1Client', file_identifier=SuffixIdentifier('.aptloz')),
|
2023-03-20 20:24:47 +00:00
|
|
|
# ChecksFinder
|
|
|
|
Component('ChecksFinder Client', 'ChecksFinderClient'),
|
|
|
|
# Starcraft 2
|
|
|
|
Component('Starcraft 2 Client', 'Starcraft2Client'),
|
|
|
|
# Wargroove
|
|
|
|
Component('Wargroove Client', 'WargrooveClient'),
|
|
|
|
# Zillion
|
|
|
|
Component('Zillion Client', 'ZillionClient',
|
|
|
|
file_identifier=SuffixIdentifier('.apzl')),
|
Mega Man Battle Network 3: Implement New Game (#1198)
* Initializes MMBN3 world with empty files
* Adds item names to item dict
* Adds locations and names
* Adds skeleton of MMBN3Client. Mostly copy pasta from OOT
* Fixed some style and formatting
* More incremental Lua tests
* Adds all locations and checking to Lua connector
* Made class definitions for TextPet Parser
* Begun connecting item delivery system through lua and textpet
* Lua Connection can now send test items
* Item Delivery is now parameterized. Test command can send any chip
* Adds the ability to send non-chip items
* Fixes name errors in python client
* Fixes count for zenny, attempts to fix bugfrags
* Fixes an issue where you always received 255 bugfrags
* Converts zenny and bugfrag amounts to little endian bytecode
* Checks game state before sending chips
Adds debug option to display information overlayed on rom
Fixes chip indexing issue for chips with ids over 255
Minor text fixes
* Adds in some animation reset instructions during item get message
* Stores previously collected item index in save, re-sends missing items
* Adds title screen check before sending locations
Loading items from save could not be done via RAM. Had to be added in
assembly
* Adds progressive undernet check
* Added library for lzss decoding bits of rom
* More progress on parsing text events from ROM
* Adds a way to inject messages into ScriptArchive data structure and generate bytecode
* Adds Item definitions, passes to client
* Adds regions and item collection rules
* Touched up a few names and values that have changed in preparation for the final patching
* Modifying messages via item is now successful
* Added generate_output hook to generate ROM data
* Generates ROM successfully
* Fixes navi cust give index
* Whoops forgot to wrap this in brackets
* Injects extra scripts for undernet rankings
* Programs had ammount and color swapped
* Prompts the user for their username when connecting
* Adds flagClear to the list of commands to avoid overwriting
* Fixes message box crashes and several other multiworld issues
* Fixes IDs and names of several items and locations
* Added .gba to gitignore
* Fixes compatibility after recent rebase
* Fixes some locations and items that are otherwise unobtainable
* Attempts to make a working launcher in the installer
* Creates installer and fixes several inaccessible locations
* Many minor changes to items, locations, and requirements made during testing
* Adds an info page for MMBN3
* Fixes failing tests by removing duplicate IDs and properly marking progression items
* Accidentally forgot to un-remove the thing
* Whoops, changed this by accident
* Updates self.world references to self.multiworld
* Fixes imports to use from imports instead of using the namespace
* Removed some leftover merge artifacts from inno setup
* Puts back that darned signtool line again
* Adds Overworld Metro keys as items
* Adds TamaCode and puts shortcuts behind cyber passes
* Fixes Numberman code 16 check
* Fixes metro access logic and adds text to metro
* Reworks Lua to fix crashing when many items are queued
* Items for other BN3 games for different players are no longer given in the main player's ROM as well
* Fixes incorrect Item ID for ACDC Metro
* Fixes multi-box text messages
* Adds timer before sending an item
* Forgot to remove the second box of SubMems
* Updates patch and lua to prevent softlocks and crashes
* Adds options for extra undernet ranks, exclude jobs
* Extra GigFreez now gives 20 bugfrags
* Additional Progressive Undernets can no longer appear on the WWW Base
* Moves item signal byte to empty area of flags instead of end of RAM
* Adds Chocolate Shop locations and navi chips to fill them
* Fixes save crash, and added chocolates to lua
* Fixes chocolate stand selling out text, removes DrillMan cube in Undernet
* Replaces old messaging system with direct memory manipulation for receiving items
* Removes NDSPY requirements from MMBN3 by manually adapting the GBA's lz10 algorithm
* Fixes the names of Hospital-1 Locations
* Adds Canary Bit to avoid sending checks when title screen check fails
* Gaining a cybermetro pass will now open the shortcut immediately
* Randomizes the two accessible areas of Undernet 7, adds Hammer as item
* Adds new locations to connector lua
* Injects the name of the item into trade quests
* Fixes copy-paste error in docs
* Fixes merge artifacts and depracated code
* Nut-wafer stand now faces Lan the right way after buying
* Removes unused Goal Option and updates the readme to include most recent changes
* Touch-ups and formatting changes
* The Great Fillerization update. Dozens of items changed to Filler
* Replaces instances of Mega Man with MegaMan
* Update worlds/mmbn3/docs/en_MegaMan Battle Network 3.md
Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
* Update worlds/mmbn3/__init__.py
Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
Co-authored-by: SoldierofOrder <107806872+SoldierofOrder@users.noreply.github.com>
* Changes code ordering to suit base class's
* assert_generate now checks for roms. Minor text fixes
* Makes player specific frequency and excluded location options
* Apply suggestions from code review
Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
* Addresses suggested changes from PR review
* Replaces ndspy lz10 with MIT-compliant nlzss lz10
* apworld compatibility fix for mmbn3_options from utils
* Addressing more comments by el-u
* APworld will now pull patch from zip folder
* Apply suggestions from code review
Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
* Cleaned up comments for progressive undernet ROM function, moved index list to field to avoid re-initializing
* Removes improper player-indexed location/item dicts, replaces with world member variables
* Avoids redefining list in progressive undernet ROM function
* Filler items can no longer be generated beyond their specified amounts
* Fixes list copying issue with item frequencies
* Adds BN3 Client Generation back into Launcher settings
* Fixes typos causing huge problems
* Fixed non-relative import for apworld
* Removes custom enum implementation that broke pickle
* Displays message when attempting to load an incorrect ROM, will not attempt to patch it
* Filler items can now only be placed once
* Changes path in setup doc to match Lua path changes
* Fixes file extension for MMBN3 file
* Replaces magic number with reference to value in NetUtils
* Moves victory rules to set_rules. Removes commented out code
* Rewrites Lua script to send block of memory
* Fixes off-by-one error in sending bytes for locations
* Fixes issue with invalid characters in text parsing, and WWW monitor text box parsing
* Moves trade text injection to init so it has access to options
* Attempts to split the text boxes for hinted items
* Trade checks now provide hints if the option is set for them
* Fixes escape character issue for BizHawk 2.9.1
Something in Bizhawk lua parsing changed to dislike the escaped tilde.
I'm not even entirely sure why it was escaped in the first place, but
this should fix the compatibility of it.
* Re-adds desk check that it turns out actually does exist
* Updates requirements to mention bizhawk 2.7 instead of 2.3.1
* Fixes off-by-one error in command byte counts
* Fixes program color indices
* Fixes newline PEP violations
* Reverts an accidental whitespace change made to launcher.py
* Fixes URL formatting on link to settings from setup guide
Co-authored-by: Zach Parks <zach@alliware.com>
* Splits several lines in the readme to avoid excessive length
* Fixes formatting and (hopefully) reduces cringe of joke in setup doc
* Removes unnecessary constructor
* Changes item frequency generation to avoid reusing the same references
Co-authored-by: Zach Parks <zach@alliware.com>
---------
Co-authored-by: el-u <109771707+el-u@users.noreply.github.com>
Co-authored-by: SoldierofOrder <107806872+SoldierofOrder@users.noreply.github.com>
Co-authored-by: Zach Parks <zach@alliware.com>
2023-06-29 18:36:01 +00:00
|
|
|
|
|
|
|
#MegaMan Battle Network 3
|
|
|
|
Component('MMBN3 Client', 'MMBN3Client', file_identifier=SuffixIdentifier('.apbn3'))
|
2023-03-20 20:24:47 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
icon_paths = {
|
2023-04-30 16:10:58 +00:00
|
|
|
'icon': local_path('data', 'icon.png'),
|
|
|
|
'mcicon': local_path('data', 'mcicon.png'),
|
2023-04-17 00:35:54 +00:00
|
|
|
'discord': local_path('data', 'discord-mark-blue.png'),
|
2023-03-20 20:24:47 +00:00
|
|
|
}
|