This allows multiple client/connector pairs to run at the same time. It also includes a few other miscellaneous small changes that accumulated as I went. They can be split if desired
- Whatever the `client_socket:send` line (~440) was doing with that missing operator, it's no longer doing. Don't ask me how it was working before. Lua is witchcraft.
- Removed the `settimeout(2)` which causes the infamous emulator freeze (and replaced it with a `settimeout(0)` when the server socket is created). It appears to be unnecessary to set a timeout for discovering a client. Maybe at some point in time it was useful to keep the success rate for connecting high, but it seems to not be a problem if the timeout is 0 instead.
- Also updated the Emerald setup to remove mention of the freezing.
- Connector script now picks the first port that's not in use in a range of 5 ports.
- To summarize why I was previously under the impression that multiple running scripts would not detect when a port was in use:
1. Calling `socket.bind` in the existing script will first create an ipv6 socket.
2. A second concurrent script trying to bind to the same port would I think fail to create an ipv6 socket but then succeed in creating an ipv4 socket on the same port.
3. That second socket could never communicate with a client; extra clients would just bounce off the first script.
4. The third concurrent script will then fail on both and actually give an `address already in use` error.
- I'm not _really_ sure what's going on there. But forcing one or the other by calling `socket.tcp4()` or `socket.tcp6()` means that only one script will believe it has the port while any others will give `address already in use` as you'd expect.
- As a side note, our `socket.lua` is much wonkier than I had previously thought. I understand some parts were added for LADX and when BizHawk 2.9 came out, but as far back as the file's history in this repo, it has provided a strange, modified interface as compared to the file it was originally derived from, to no benefit as far as I can tell.
- The connector script closes `server` once it finds a client and opens a new one if the connection drops. I'm not sure this ultimately has an effect, but it seems more proper.
- If the connector script's main function returns because of some error or refusal to proceed, the script no longer tries to resume the coroutine it was part of, which would flood the log with irrelevant errors.
- Creating `SyncError`s in `guarded_read` and `guarded_write` would raise its own error because the wrong variable was being used in its message.
- A call to `_bizhawk.connect` can take a while as the client tries the possible ports. There's a modification that will wait on either the `connect` or the exit event. And if the exit event fires while still looking for a connector script, this cancels the `connect` so the window can close.
- Related: It takes 2-3 seconds for a call to `asyncio.open_connection` to come back with any sort of response on my machine, which can be significant now that we're trying multiple ports in sequence. I guess it could fire off 5 tasks at once. Might cause some weirdness if there exist multiple scripts and multiple clients looking for each other at the same time.
- Also related: The first time a client attempts to connect to a script, they accept each other and start communicating as expected. The second client to try that port seems to believe it connects and will then time out on the first message. And then all subsequent attempts to connect to that port by any client will be refused (as expected) until the script shuts down or restarts. I haven't been able to explain this behavior. It adds more time to a client's search for a script, but doesn't ultimately cause problems.
Adds a generic client that can communicate with BizHawk. Similar to SNIClient, but for arbitrary systems and doesn't have an intermediary application like SNI.
Certain multiworld settings (bug observed with item link settings) can cause the total item count in TLoZ world to exceed 255. This causes an overflow in the loop to receive all pending items. This adds an additional byte to be used as a high byte for the items obtained counter.
This approach was taken due to the surrounding bytes being occupied, preventing a direct 16-bit number from being used without moving to a different location and leaving more empty bytes in the memory block for save data.
There was a bug that randomly after opening and closing the menu, some players on Bizhawk would get old items again. Tracking this down took multiple hours over the course of several weeks. The root cause turned out to be reading from the System Bus domain while an DMA copy was happening. Doing so is undefined behavior on GBC (though I'm sure some game relies on it). On Gambatte, you end up reading some garbage byte no matter what the read is (unsure what the providence of the byte is - some garbage, some register, the actual DMA data, who knows?). Normally, this isn't an issue, as Bizhawk callbacks only happen during vblank/halt, which is generally a state where we have valid WRAM to read from. However - a setting is being passed around the community for Bizhawk that changes the frame counter to go from "only when Vblank happens" to "whenever some number of audio samples have happened" which causes the bizhawk callbacks to happen....nearly whenever. Including during a DMA. You can tell this is happening if you print the `PC` register when reading memory - if it matches `FFXX` then you are executing in a routine in HRAM and likely doing a DMA.
Additionally, the check items counter specifically is in WRAM Bank 1 which could be swapped out of - will have to keep an eye on this - generally LADX lives in Bank 1, but there are a few things that use the other banks (swap space for some objects??). This could be a problem on any platform - if we get more reports of bad items gets, that's probably why.
Also, fixes some logging that was never getting reenabled.
* 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>
* Fix links to TASVideos.org using HTTP
* Revise all docs mentioning Lua in EmuHawk which are in English
resolvesTASEmulators/BizHawk#3650
* Correct capitalisation of "BizHawk"
in strings and camelCase identifiers
* Use the term "EmuHawk" when referring to the app, in English docs
---------
Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
* Fixes the socket library for bizhawk 2.9/lua 5.4 by including another one in parallel
* Fixes lua 5.4 support by making socket.lua into a "modern" module (the `module` keyword is gone)
* Adds the linux version and 32 bit windows socket dlls because why not
* Merges common functions into `common.lua` - the only functional change of this should be that:
* Some things that were locals are globals now - this can be changed, I just was lazy and it likely doesn't matter
* `drawText` now uses middle/bottom for all prints - feel free to do what you like with that change
This is a Lua script for BizHawk that implements the relevant parts of
the RetroArch networking API used by the Archipelago LADX Client.
socket.lua and core.dll are exact copies of the same files in
data/lua/OOT and various other folders. There is a PR consolidating
these into the base folder, which this commit is anticipating.
LADX "just works"(tm) when this is loaded in Bizhawk.
Adds Adventure for the Atari 2600, NTSC version. New randomizer, not based on prior works. Somewhat atypical of current AP rom patch games; The generator does not require the adventure rom, but writes some data to an .apadvn APContainer file that the client uses along with a base bsdiff patch to generate a final rom file.
* Coin items received or found in the Game Corner are now shuffled, locations require Coin Case
* Prizesanity option (shuffle Game Corner Prizes)
* DexSanity option: location checks for marking Pokémon as caught in your Pokédex. Also an option to set all Pokémon in your Pokédex as seen from the start, to aid in locating them.
* Option to randomize the layout of the Rock Tunnel.
* Area 1-to-1 mapping: When one instance of a Wild Pokémon in a given area is randomized, all instances of that Pokémon will be the same. So that if a route had 3 different Pokémon before, it will have 3 after randomization.
* Option to randomize the moves taught by TMs.
* Exact controls for TM/HM compatibility chances.
* Option to randomize Pokémon's pallets or set them based on primary type.
* Added Cinnabar Gym trainers to Trainersanity and randomized the quiz questions and answers. Getting a correct answer will flag the trainer as defeated so that you can obtain the Trainersanity check without defeating the trainer if you answer correctly.
## What is this fixing or adding?
- Adds the majority of OoTR 7.0 features:
- Pot shuffle, Freestanding item shuffle, Crate shuffle, Beehive shuffle
- Key rings mode
- Dungeon shortcuts to speed up dungeons
- "Regional" shuffle for dungeon items
- New options for shop pricing in shopsanity
- Expanded Ganon's Boss Key shuffle options
- Pre-planted beans
- Improved Chest Appearance Matches Contents mode
- Blue Fire Arrows
- Bonk self-damage
- Finer control over MQ dungeons and spawn position randomization
- Several bugfixes as a result of the update:
- Items recognized by the server and valid starting items are now in a 1-to-1 correspondence. In particular, starting with keys is now supported.
- Entrance randomization success rate improved. Hopefully it is now at 100%.
Co-authored-by: Zach Parks <zach@alliware.com>
Adds Trainersanity option (Each non-scripted trainer has a location check, adding 317 locations)
Adds Randomize Pokedex option. It is required to obtain items from Oak's Aides.
Adds option to add all normal shop items to all normal shops.
Adds DeathLink option.
Adds traps.
Improves Type Chart randomization.
Items can be received during battle.
Stores start inventory in ROM. Only requests remote start inventory if patch is from v1.
Fixes logic bugs.
Various other improvements.
* OoT: ER improvements
Include dungeon rewards in itempool to allow for ER improvement
Better validate_world function by checking for multi-entrance incompatibility more efficiently
Fix some generation failures by ensuring all entrances placed with logic
Introduce bias to some interior entrance placement to improve generation rate
* OoT: fix overworld ER spoiler information
* OoT: rewrite dungeon item placement algorithm
in particular, no longer assumes that exactly the number of vanilla keys is present, which lets it place more or fewer items.
* OoT: auto-send more locations
Now should autosend cows, DMT/DMC great fairies, medigoron, and bombchu salesman
This should be every check autosending. these ones are super weird for some reason and didn't get fixed with the others
* OoT: add items forced local by settings to AP's local_items
* OoT: fast-fill shop junk items
* OoT: ensure that Kokiri Shop is always reachable immediately in closed forest
hence Deku Shield can be bought to leave the forest
* OoT: randomize internal connect name
Connect name is now a random 16-character string.
This should prevent any issues with connecting to a room with the wrong ROM with probability almost 1.
* OoT: introduce TrackRandomRange for trials hint and mq dungeon maps
* OoT: enable proper itemlinking of songs and dungeon items, with restricted placements according to player settings
* OoT: barren hint oversight fix
* OoT: allow NL + ER to roll properly
* OoT: 3.8 compatibility
set and list builtins don't have proper typing support until 3.9, apparently
* OoT: remove Gerudo Membership Card location from the pool if fortress open and card not randomized
another long-standing bug squished
* OoT: exclude locations in the itemlink song fill if they aren't also priority
* OoT: prevent data bleed when client isn't closed between different game connections
I don't understand why people keep doing this
* OoT: linter appeasement
it was a real error though
* fixing merge conflicts is hard
* oot merge update #2
* OoT: removed accidentally duplicated code
* [Pokemon] Logic fixes
* [Pokemon] Fix seed name length
* [Pokemon] Location name changes
* [Pokemon] Hidden Item Nurse Bed logic fix
* Badges Needed description update
* Ensure player name does not exceed 16 bytes
* Player name check fix
* Remove unique items in start_inventory from item pool
* Vending Machine Drinks will not be created as filler
* Skip trainer text
* Badges needed for viridian gym text
* Add slot data for trackers
* free fly map in slot data and old_man = vanilla allows more free fly maps
* Re-add mistakenly removed slot data item
* Add tracker link to setup doc
* Doc fix
* Fix base patch
* Change pre_fill to generate_basic so items are pre-filled before item links
* Rename some hidden locations
* missing file from commit and revert one errant location name change
* CommonClient: Focus text field when requesting input.
* CommonClient: Store and prefill last server address.
* CommonClient: Focus and select portion of server address upon start.
* CommonClient: Don't allow editing of address while connected.
* CommonClient: Don't make pressing Enter in the address bar disconnect you.
* CommonClient: Use TextInput.text_validate_unfocus over jank workaround.
* CommonClient: Fixed hang when closing after failed handshake.
* CommonClient: Made scrollbar wider and interactable.
* oot: remove all escape characters in LogicTricks.py
* only attempt to connect to client once
* oot: don't kill player outside ToT or in market entrance
fixed camera makes the game crash outside ToT. added market entrance to be safe, it doesn't matter if you don't die there
* Clients: now featuring tooltips and some general cleanup
* Clients: fade in tooltip over 0.25 seconds
* Clients: reset slot and team when disconnecting
* Clients: allow joining multiworld via link (TextClient only for now)