Compare commits
234 Commits
allow_coll
...
linux-py31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9eb2d3ea3e | ||
|
|
f04054a177 | ||
|
|
18127a75f5 | ||
|
|
899de428df | ||
|
|
f401702e7c | ||
|
|
68bfe1705d | ||
|
|
98b0bf7456 | ||
|
|
7674e62ba7 | ||
|
|
0b33c25b39 | ||
|
|
62f4e62d71 | ||
|
|
48add4687c | ||
|
|
cc08e853a0 | ||
|
|
7e3fa5058d | ||
|
|
c74577d708 | ||
|
|
a8b76b1310 | ||
|
|
c8ebad1dfe | ||
|
|
d3447a3983 | ||
|
|
11b2b5ed2f | ||
|
|
a0464ecea1 | ||
|
|
97fd78ba1b | ||
|
|
a60f370224 | ||
|
|
0363630f61 | ||
|
|
39c7c7291e | ||
|
|
a368520200 | ||
|
|
5d25f908a4 | ||
|
|
9edab76567 | ||
|
|
91b60f2e21 | ||
|
|
41b59488e3 | ||
|
|
42da24cb5e | ||
|
|
28c5e9ee65 | ||
|
|
b55174ccdf | ||
|
|
7bcf299412 | ||
|
|
a7816d186f | ||
|
|
9d40471dee | ||
|
|
b704070de5 | ||
|
|
6c459066a7 | ||
|
|
4c3eaf2996 | ||
|
|
bb56f7b400 | ||
|
|
22ed7ff9c3 | ||
|
|
173513c9f4 | ||
|
|
c0cf35edda | ||
|
|
dcc628f878 | ||
|
|
b950af09a6 | ||
|
|
58aea7ca58 | ||
|
|
06a25a903e | ||
|
|
62a265cc31 | ||
|
|
67c3076572 | ||
|
|
ab5cb7adad | ||
|
|
5e84f91d2f | ||
|
|
a7a17a5a4d | ||
|
|
a6ea3e1953 | ||
|
|
0515acc8fe | ||
|
|
bf5c1cbbbf | ||
|
|
c8fb46a5e6 | ||
|
|
a38a2903d5 | ||
|
|
4ef7e43521 | ||
|
|
e1f17fadfc | ||
|
|
4dc934729d | ||
|
|
722757e18a | ||
|
|
0ca3c5e6a2 | ||
|
|
664bbd86bb | ||
|
|
7a9d4272be | ||
|
|
7559adbb14 | ||
|
|
1a7bc4ffd4 | ||
|
|
be74a4a71a | ||
|
|
cb634fa8d4 | ||
|
|
f6758524d5 | ||
|
|
f395a6d184 | ||
|
|
ea03c90152 | ||
|
|
50d9ab041a | ||
|
|
acd3cb45bf | ||
|
|
8a78062825 | ||
|
|
599cd2c82e | ||
|
|
89ec31708e | ||
|
|
ef211da27f | ||
|
|
0122eb38ab | ||
|
|
3d8bc0bb67 | ||
|
|
d85c13ef0e | ||
|
|
27cb93d319 | ||
|
|
b0e8c8db6b | ||
|
|
5a7d20d393 | ||
|
|
808203a50f | ||
|
|
d8f79b4a42 | ||
|
|
02ef6cee47 | ||
|
|
e716b50f8c | ||
|
|
3fdf07677c | ||
|
|
d3baca9251 | ||
|
|
f52ca2571f | ||
|
|
469807ba01 | ||
|
|
8ada91939c | ||
|
|
054d14baa4 | ||
|
|
f0324e60f8 | ||
|
|
70ff19ac8c | ||
|
|
b02b329181 | ||
|
|
8b7ffaf671 | ||
|
|
c711d803f8 | ||
|
|
3c3954f5e8 | ||
|
|
05d398a51d | ||
|
|
5eadbc9840 | ||
|
|
0c1e3097c3 | ||
|
|
cdf7ca1dcc | ||
|
|
77fbd0eb2b | ||
|
|
c7284f90d9 | ||
|
|
8d559daa35 | ||
|
|
e49ffc64f2 | ||
|
|
94a02510c0 | ||
|
|
9d73988030 | ||
|
|
81411a191c | ||
|
|
6059b5ef66 | ||
|
|
0bc5a3bc8d | ||
|
|
11fdb29357 | ||
|
|
bbef7a4cbc | ||
|
|
8e7bbb4ea8 | ||
|
|
6628e8c85d | ||
|
|
84402a1b55 | ||
|
|
f4035b8621 | ||
|
|
bbf8546867 | ||
|
|
67a22b8b43 | ||
|
|
8e6ec85532 | ||
|
|
8fc50510a0 | ||
|
|
aa6ad5d34f | ||
|
|
ccb89dd65c | ||
|
|
a86c0aa37d | ||
|
|
ece6598b09 | ||
|
|
eef8f7af1a | ||
|
|
c626618221 | ||
|
|
47989325f8 | ||
|
|
815e7e6b0a | ||
|
|
a61a1f58c6 | ||
|
|
4c24872264 | ||
|
|
e778e49574 | ||
|
|
25f7413881 | ||
|
|
397ce8343e | ||
|
|
37fdc00517 | ||
|
|
03aa9b3604 | ||
|
|
8f52e4654f | ||
|
|
a86fd37860 | ||
|
|
eb503adb13 | ||
|
|
cbf72becc1 | ||
|
|
cdd460ae15 | ||
|
|
ffd968d89d | ||
|
|
8d73746d5b | ||
|
|
5ed56db48a | ||
|
|
5f447f4e6b | ||
|
|
f015cf4298 | ||
|
|
e43bb99622 | ||
|
|
34de5a57af | ||
|
|
510a460d84 | ||
|
|
6e271b643d | ||
|
|
8971340a66 | ||
|
|
30cfd3186c | ||
|
|
1dc4e2b44b | ||
|
|
d5b4a91a13 | ||
|
|
bf5282dfa8 | ||
|
|
4eea91daab | ||
|
|
20e80d06cf | ||
|
|
59b78528a9 | ||
|
|
cd4fd18706 | ||
|
|
af44c1ba3d | ||
|
|
3ef0a56ec2 | ||
|
|
4ff282a384 | ||
|
|
f3dad894ec | ||
|
|
a5373e3672 | ||
|
|
639606e0be | ||
|
|
bb79073ce7 | ||
|
|
53b3cd029e | ||
|
|
99bd525c8e | ||
|
|
d14ab97849 | ||
|
|
f50e85b401 | ||
|
|
b64565594a | ||
|
|
ae7dad8bf9 | ||
|
|
b7c74919b7 | ||
|
|
a7f7f91aaf | ||
|
|
e62f989ce8 | ||
|
|
21c6c28755 | ||
|
|
f0403b9c9d | ||
|
|
f09f3663d6 | ||
|
|
b5bd93c420 | ||
|
|
90813c0f4b | ||
|
|
e2c4293a6d | ||
|
|
963c33c02a | ||
|
|
7d603e7d8d | ||
|
|
f2e1495d39 | ||
|
|
7927b2ee25 | ||
|
|
4f2b13a674 | ||
|
|
ffd7d5da74 | ||
|
|
67eb370200 | ||
|
|
4456e36fbb | ||
|
|
7fd9e71b3c | ||
|
|
f4a68f1c3d | ||
|
|
754a57cf69 | ||
|
|
384577e421 | ||
|
|
0ed3865c30 | ||
|
|
77b2ed54a6 | ||
|
|
0386d9f6d2 | ||
|
|
7e52b6d8bb | ||
|
|
03cf525b2c | ||
|
|
e1f46d623c | ||
|
|
5bb6ff0ce0 | ||
|
|
256f493ada | ||
|
|
3ec2d45f4f | ||
|
|
b3895750ab | ||
|
|
7591404151 | ||
|
|
d48e1e447f | ||
|
|
206f8cf5ed | ||
|
|
0c6b1827fe | ||
|
|
017f91c1b5 | ||
|
|
95b01def6b | ||
|
|
5977e401d5 | ||
|
|
21a3c74783 | ||
|
|
2fb9176511 | ||
|
|
1c69fb3c3c | ||
|
|
91502505a1 | ||
|
|
01c13ca243 | ||
|
|
c2a8b842de | ||
|
|
856efebc39 | ||
|
|
5a4203649d | ||
|
|
ddb764a9b6 | ||
|
|
9f65f22fac | ||
|
|
b7ff9b69ba | ||
|
|
012e6ba24c | ||
|
|
cd9d0bebc8 | ||
|
|
3fa6588637 | ||
|
|
e6d16c905c | ||
|
|
958829d491 | ||
|
|
9ee37b0ec5 | ||
|
|
81a239325d | ||
|
|
67bf12369a | ||
|
|
d4b793902f | ||
|
|
6671b21a86 | ||
|
|
6d13dc4944 | ||
|
|
ff9f563d4a | ||
|
|
d825576f12 | ||
|
|
5d6184f1fd |
18
.github/workflows/build.yml
vendored
@@ -36,8 +36,7 @@ jobs:
|
|||||||
Expand-Archive -Path enemizer.zip -DestinationPath EnemizerCLI -Force
|
Expand-Archive -Path enemizer.zip -DestinationPath EnemizerCLI -Force
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip setuptools
|
python -m pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
|
||||||
python setup.py build_exe --yes
|
python setup.py build_exe --yes
|
||||||
$NAME="$(ls build)".Split('.',2)[1]
|
$NAME="$(ls build)".Split('.',2)[1]
|
||||||
$ZIP_NAME="Archipelago_$NAME.7z"
|
$ZIP_NAME="Archipelago_$NAME.7z"
|
||||||
@@ -53,8 +52,8 @@ jobs:
|
|||||||
path: dist/${{ env.ZIP_NAME }}
|
path: dist/${{ env.ZIP_NAME }}
|
||||||
retention-days: 7 # keep for 7 days, should be enough
|
retention-days: 7 # keep for 7 days, should be enough
|
||||||
|
|
||||||
build-ubuntu1804:
|
build-ubuntu2004:
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
# - copy code below to release.yml -
|
# - copy code below to release.yml -
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -66,10 +65,10 @@ jobs:
|
|||||||
- name: Get a recent python
|
- name: Get a recent python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.10'
|
||||||
- name: Install build-time dependencies
|
- name: Install build-time dependencies
|
||||||
run: |
|
run: |
|
||||||
echo "PYTHON=python3.9" >> $GITHUB_ENV
|
echo "PYTHON=python3.10" >> $GITHUB_ENV
|
||||||
wget -nv https://github.com/AppImage/AppImageKit/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage
|
wget -nv https://github.com/AppImage/AppImageKit/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage
|
||||||
chmod a+rx appimagetool-x86_64.AppImage
|
chmod a+rx appimagetool-x86_64.AppImage
|
||||||
./appimagetool-x86_64.AppImage --appimage-extract
|
./appimagetool-x86_64.AppImage --appimage-extract
|
||||||
@@ -85,8 +84,7 @@ jobs:
|
|||||||
# charset-normalizer was somehow incomplete in the github runner
|
# charset-normalizer was somehow incomplete in the github runner
|
||||||
"${{ env.PYTHON }}" -m venv venv
|
"${{ env.PYTHON }}" -m venv venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
"${{ env.PYTHON }}" -m pip install --upgrade pip PyGObject setuptools charset-normalizer
|
"${{ env.PYTHON }}" -m pip install --upgrade pip PyGObject charset-normalizer
|
||||||
pip install -r requirements.txt
|
|
||||||
python setup.py build_exe --yes bdist_appimage --yes
|
python setup.py build_exe --yes bdist_appimage --yes
|
||||||
echo -e "setup.py build output:\n `ls build`"
|
echo -e "setup.py build output:\n `ls build`"
|
||||||
echo -e "setup.py dist output:\n `ls dist`"
|
echo -e "setup.py dist output:\n `ls dist`"
|
||||||
@@ -96,6 +94,10 @@ jobs:
|
|||||||
echo "APPIMAGE_NAME=$APPIMAGE_NAME" >> $GITHUB_ENV
|
echo "APPIMAGE_NAME=$APPIMAGE_NAME" >> $GITHUB_ENV
|
||||||
echo "TAR_NAME=$TAR_NAME" >> $GITHUB_ENV
|
echo "TAR_NAME=$TAR_NAME" >> $GITHUB_ENV
|
||||||
# - copy code above to release.yml -
|
# - copy code above to release.yml -
|
||||||
|
- name: Build Again
|
||||||
|
run: |
|
||||||
|
source venv/bin/activate
|
||||||
|
python setup.py build_exe --yes
|
||||||
- name: Store AppImage
|
- name: Store AppImage
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
4
.github/workflows/lint.yml
vendored
@@ -12,7 +12,7 @@ on:
|
|||||||
- '**.py'
|
- '**.py'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
flake8:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip wheel
|
python -m pip install --upgrade pip wheel
|
||||||
pip install flake8 pytest pytest-subtests
|
pip install flake8
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
- name: Lint with flake8
|
- name: Lint with flake8
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
13
.github/workflows/release.yml
vendored
@@ -29,8 +29,8 @@ jobs:
|
|||||||
# build-release-windows: # this is done by hand because of signing
|
# build-release-windows: # this is done by hand because of signing
|
||||||
# build-release-macos: # LF volunteer
|
# build-release-macos: # LF volunteer
|
||||||
|
|
||||||
build-release-ubuntu1804:
|
build-release-ubuntu2004:
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- name: Set env
|
- name: Set env
|
||||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
@@ -44,10 +44,10 @@ jobs:
|
|||||||
- name: Get a recent python
|
- name: Get a recent python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.10'
|
||||||
- name: Install build-time dependencies
|
- name: Install build-time dependencies
|
||||||
run: |
|
run: |
|
||||||
echo "PYTHON=python3.9" >> $GITHUB_ENV
|
echo "PYTHON=python3.10" >> $GITHUB_ENV
|
||||||
wget -nv https://github.com/AppImage/AppImageKit/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage
|
wget -nv https://github.com/AppImage/AppImageKit/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage
|
||||||
chmod a+rx appimagetool-x86_64.AppImage
|
chmod a+rx appimagetool-x86_64.AppImage
|
||||||
./appimagetool-x86_64.AppImage --appimage-extract
|
./appimagetool-x86_64.AppImage --appimage-extract
|
||||||
@@ -63,9 +63,8 @@ jobs:
|
|||||||
# charset-normalizer was somehow incomplete in the github runner
|
# charset-normalizer was somehow incomplete in the github runner
|
||||||
"${{ env.PYTHON }}" -m venv venv
|
"${{ env.PYTHON }}" -m venv venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
"${{ env.PYTHON }}" -m pip install --upgrade pip PyGObject setuptools charset-normalizer
|
"${{ env.PYTHON }}" -m pip install --upgrade pip PyGObject charset-normalizer
|
||||||
pip install -r requirements.txt
|
python setup.py build_exe --yes bdist_appimage --yes
|
||||||
python setup.py build --yes bdist_appimage --yes
|
|
||||||
echo -e "setup.py build output:\n `ls build`"
|
echo -e "setup.py build output:\n `ls build`"
|
||||||
echo -e "setup.py dist output:\n `ls dist`"
|
echo -e "setup.py dist output:\n `ls dist`"
|
||||||
cd dist && export APPIMAGE_NAME="`ls *.AppImage`" && cd ..
|
cd dist && export APPIMAGE_NAME="`ls *.AppImage`" && cd ..
|
||||||
|
|||||||
4
.github/workflows/unittests.yml
vendored
@@ -52,8 +52,8 @@ jobs:
|
|||||||
python-version: ${{ matrix.python.version }}
|
python-version: ${{ matrix.python.version }}
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip wheel
|
python -m pip install --upgrade pip
|
||||||
pip install flake8 pytest pytest-subtests
|
pip install pytest pytest-subtests
|
||||||
python ModuleUpdate.py --yes --force --append "WebHostLib/requirements.txt"
|
python ModuleUpdate.py --yes --force --append "WebHostLib/requirements.txt"
|
||||||
- name: Unittests
|
- name: Unittests
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
2
.gitignore
vendored
@@ -26,6 +26,7 @@
|
|||||||
*multisave
|
*multisave
|
||||||
*.archipelago
|
*.archipelago
|
||||||
*.apsave
|
*.apsave
|
||||||
|
*.BIN
|
||||||
|
|
||||||
build
|
build
|
||||||
bundle/components.wxs
|
bundle/components.wxs
|
||||||
@@ -52,6 +53,7 @@ Output Logs/
|
|||||||
/setup.ini
|
/setup.ini
|
||||||
/installdelete.iss
|
/installdelete.iss
|
||||||
/data/user.kv
|
/data/user.kv
|
||||||
|
/datapackage
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|||||||
516
AdventureClient.py
Normal file
@@ -0,0 +1,516 @@
|
|||||||
|
import asyncio
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import bsdiff4
|
||||||
|
import subprocess
|
||||||
|
import zipfile
|
||||||
|
from asyncio import StreamReader, StreamWriter, CancelledError
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
import Utils
|
||||||
|
from NetUtils import ClientStatus
|
||||||
|
from Utils import async_start
|
||||||
|
from CommonClient import CommonContext, server_loop, gui_enabled, ClientCommandProcessor, logger, \
|
||||||
|
get_base_parser
|
||||||
|
from worlds.adventure import AdventureDeltaPatch
|
||||||
|
|
||||||
|
from worlds.adventure.Locations import base_location_id
|
||||||
|
from worlds.adventure.Rom import AdventureForeignItemInfo, AdventureAutoCollectLocation, BatNoTouchLocation
|
||||||
|
from worlds.adventure.Items import base_adventure_item_id, standard_item_max, item_table
|
||||||
|
from worlds.adventure.Offsets import static_item_element_size, connector_port_offset
|
||||||
|
|
||||||
|
SYSTEM_MESSAGE_ID = 0
|
||||||
|
|
||||||
|
CONNECTION_TIMING_OUT_STATUS = \
|
||||||
|
"Connection timing out. Please restart your emulator, then restart connector_adventure.lua"
|
||||||
|
CONNECTION_REFUSED_STATUS = \
|
||||||
|
"Connection Refused. Please start your emulator and make sure connector_adventure.lua is running"
|
||||||
|
CONNECTION_RESET_STATUS = \
|
||||||
|
"Connection was reset. Please restart your emulator, then restart connector_adventure.lua"
|
||||||
|
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
||||||
|
CONNECTION_CONNECTED_STATUS = "Connected"
|
||||||
|
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
||||||
|
|
||||||
|
SCRIPT_VERSION = 1
|
||||||
|
|
||||||
|
|
||||||
|
class AdventureCommandProcessor(ClientCommandProcessor):
|
||||||
|
def __init__(self, ctx: CommonContext):
|
||||||
|
super().__init__(ctx)
|
||||||
|
|
||||||
|
def _cmd_2600(self):
|
||||||
|
"""Check 2600 Connection State"""
|
||||||
|
if isinstance(self.ctx, AdventureContext):
|
||||||
|
logger.info(f"2600 Status: {self.ctx.atari_status}")
|
||||||
|
|
||||||
|
def _cmd_aconnect(self):
|
||||||
|
"""Discard current atari 2600 connection state"""
|
||||||
|
if isinstance(self.ctx, AdventureContext):
|
||||||
|
self.ctx.atari_sync_task.cancel()
|
||||||
|
|
||||||
|
|
||||||
|
class AdventureContext(CommonContext):
|
||||||
|
command_processor = AdventureCommandProcessor
|
||||||
|
game = 'Adventure'
|
||||||
|
lua_connector_port: int = 17242
|
||||||
|
|
||||||
|
def __init__(self, server_address, password):
|
||||||
|
super().__init__(server_address, password)
|
||||||
|
self.freeincarnates_used: int = -1
|
||||||
|
self.freeincarnate_pending: int = 0
|
||||||
|
self.foreign_items: [AdventureForeignItemInfo] = []
|
||||||
|
self.autocollect_items: [AdventureAutoCollectLocation] = []
|
||||||
|
self.atari_streams: (StreamReader, StreamWriter) = None
|
||||||
|
self.atari_sync_task = None
|
||||||
|
self.messages = {}
|
||||||
|
self.locations_array = None
|
||||||
|
self.atari_status = CONNECTION_INITIAL_STATUS
|
||||||
|
self.awaiting_rom = False
|
||||||
|
self.display_msgs = True
|
||||||
|
self.deathlink_pending = False
|
||||||
|
self.set_deathlink = False
|
||||||
|
self.client_compatibility_mode = 0
|
||||||
|
self.items_handling = 0b111
|
||||||
|
self.checked_locations_sent: bool = False
|
||||||
|
self.port_offset = 0
|
||||||
|
self.bat_no_touch_locations: [BatNoTouchLocation] = []
|
||||||
|
self.local_item_locations = {}
|
||||||
|
self.dragon_speed_info = {}
|
||||||
|
|
||||||
|
options = Utils.get_options()
|
||||||
|
self.display_msgs = options["adventure_options"]["display_msgs"]
|
||||||
|
|
||||||
|
async def server_auth(self, password_requested: bool = False):
|
||||||
|
if password_requested and not self.password:
|
||||||
|
await super(AdventureContext, self).server_auth(password_requested)
|
||||||
|
if not self.auth:
|
||||||
|
self.auth = self.player_name
|
||||||
|
if not self.auth:
|
||||||
|
self.awaiting_rom = True
|
||||||
|
logger.info('Awaiting connection to adventure_connector to get Player information')
|
||||||
|
return
|
||||||
|
|
||||||
|
await self.send_connect()
|
||||||
|
|
||||||
|
def _set_message(self, msg: str, msg_id: int):
|
||||||
|
if self.display_msgs:
|
||||||
|
self.messages[(time.time(), msg_id)] = msg
|
||||||
|
|
||||||
|
def on_package(self, cmd: str, args: dict):
|
||||||
|
if cmd == 'Connected':
|
||||||
|
self.locations_array = None
|
||||||
|
if Utils.get_options()["adventure_options"].get("death_link", False):
|
||||||
|
self.set_deathlink = True
|
||||||
|
async_start(self.get_freeincarnates_used())
|
||||||
|
elif cmd == "RoomInfo":
|
||||||
|
self.seed_name = args['seed_name']
|
||||||
|
elif cmd == 'Print':
|
||||||
|
msg = args['text']
|
||||||
|
if ': !' not in msg:
|
||||||
|
self._set_message(msg, SYSTEM_MESSAGE_ID)
|
||||||
|
elif cmd == "ReceivedItems":
|
||||||
|
msg = f"Received {', '.join([self.item_names[item.item] for item in args['items']])}"
|
||||||
|
self._set_message(msg, SYSTEM_MESSAGE_ID)
|
||||||
|
elif cmd == "Retrieved":
|
||||||
|
self.freeincarnates_used = args["keys"][f"adventure_{self.auth}_freeincarnates_used"]
|
||||||
|
if self.freeincarnates_used is None:
|
||||||
|
self.freeincarnates_used = 0
|
||||||
|
self.freeincarnates_used += self.freeincarnate_pending
|
||||||
|
self.send_pending_freeincarnates()
|
||||||
|
elif cmd == "SetReply":
|
||||||
|
if args["key"] == f"adventure_{self.auth}_freeincarnates_used":
|
||||||
|
self.freeincarnates_used = args["value"]
|
||||||
|
if self.freeincarnates_used is None:
|
||||||
|
self.freeincarnates_used = 0
|
||||||
|
self.freeincarnates_used += self.freeincarnate_pending
|
||||||
|
self.send_pending_freeincarnates()
|
||||||
|
|
||||||
|
def on_deathlink(self, data: dict):
|
||||||
|
self.deathlink_pending = True
|
||||||
|
super().on_deathlink(data)
|
||||||
|
|
||||||
|
def run_gui(self):
|
||||||
|
from kvui import GameManager
|
||||||
|
|
||||||
|
class AdventureManager(GameManager):
|
||||||
|
logging_pairs = [
|
||||||
|
("Client", "Archipelago")
|
||||||
|
]
|
||||||
|
base_title = "Archipelago Adventure Client"
|
||||||
|
|
||||||
|
self.ui = AdventureManager(self)
|
||||||
|
self.ui_task = asyncio.create_task(self.ui.async_run(), name="UI")
|
||||||
|
|
||||||
|
async def get_freeincarnates_used(self):
|
||||||
|
if self.server and not self.server.socket.closed:
|
||||||
|
await self.send_msgs([{"cmd": "SetNotify", "keys": [f"adventure_{self.auth}_freeincarnates_used"]}])
|
||||||
|
await self.send_msgs([{"cmd": "Get", "keys": [f"adventure_{self.auth}_freeincarnates_used"]}])
|
||||||
|
|
||||||
|
def send_pending_freeincarnates(self):
|
||||||
|
if self.freeincarnate_pending > 0:
|
||||||
|
async_start(self.send_pending_freeincarnates_impl(self.freeincarnate_pending))
|
||||||
|
self.freeincarnate_pending = 0
|
||||||
|
|
||||||
|
async def send_pending_freeincarnates_impl(self, send_val: int) -> None:
|
||||||
|
await self.send_msgs([{"cmd": "Set", "key": f"adventure_{self.auth}_freeincarnates_used",
|
||||||
|
"default": 0, "want_reply": False,
|
||||||
|
"operations": [{"operation": "add", "value": send_val}]}])
|
||||||
|
|
||||||
|
async def used_freeincarnate(self) -> None:
|
||||||
|
if self.server and not self.server.socket.closed:
|
||||||
|
await self.send_msgs([{"cmd": "Set", "key": f"adventure_{self.auth}_freeincarnates_used",
|
||||||
|
"default": 0, "want_reply": True,
|
||||||
|
"operations": [{"operation": "add", "value": 1}]}])
|
||||||
|
else:
|
||||||
|
self.freeincarnate_pending = self.freeincarnate_pending + 1
|
||||||
|
|
||||||
|
|
||||||
|
def convert_item_id(ap_item_id: int):
|
||||||
|
static_item_index = ap_item_id - base_adventure_item_id
|
||||||
|
return static_item_index * static_item_element_size
|
||||||
|
|
||||||
|
|
||||||
|
def get_payload(ctx: AdventureContext):
|
||||||
|
current_time = time.time()
|
||||||
|
items = []
|
||||||
|
dragon_speed_update = {}
|
||||||
|
diff_a_locked = ctx.diff_a_mode > 0
|
||||||
|
diff_b_locked = ctx.diff_b_mode > 0
|
||||||
|
freeincarnate_count = 0
|
||||||
|
for item in ctx.items_received:
|
||||||
|
item_id_str = str(item.item)
|
||||||
|
if base_adventure_item_id < item.item <= standard_item_max:
|
||||||
|
items.append(convert_item_id(item.item))
|
||||||
|
elif item_id_str in ctx.dragon_speed_info:
|
||||||
|
if item.item in dragon_speed_update:
|
||||||
|
last_index = len(ctx.dragon_speed_info[item_id_str]) - 1
|
||||||
|
dragon_speed_update[item.item] = ctx.dragon_speed_info[item_id_str][last_index]
|
||||||
|
else:
|
||||||
|
dragon_speed_update[item.item] = ctx.dragon_speed_info[item_id_str][0]
|
||||||
|
elif item.item == item_table["Left Difficulty Switch"].id:
|
||||||
|
diff_a_locked = False
|
||||||
|
elif item.item == item_table["Right Difficulty Switch"].id:
|
||||||
|
diff_b_locked = False
|
||||||
|
elif item.item == item_table["Freeincarnate"].id:
|
||||||
|
freeincarnate_count = freeincarnate_count + 1
|
||||||
|
freeincarnates_available = 0
|
||||||
|
|
||||||
|
if ctx.freeincarnates_used >= 0:
|
||||||
|
freeincarnates_available = freeincarnate_count - (ctx.freeincarnates_used + ctx.freeincarnate_pending)
|
||||||
|
ret = json.dumps(
|
||||||
|
{
|
||||||
|
"items": items,
|
||||||
|
"messages": {f'{key[0]}:{key[1]}': value for key, value in ctx.messages.items()
|
||||||
|
if key[0] > current_time - 10},
|
||||||
|
"deathlink": ctx.deathlink_pending,
|
||||||
|
"dragon_speeds": dragon_speed_update,
|
||||||
|
"difficulty_a_locked": diff_a_locked,
|
||||||
|
"difficulty_b_locked": diff_b_locked,
|
||||||
|
"freeincarnates_available": freeincarnates_available,
|
||||||
|
"bat_logic": ctx.bat_logic
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ctx.deathlink_pending = False
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
async def parse_locations(data: List, ctx: AdventureContext):
|
||||||
|
locations = data
|
||||||
|
|
||||||
|
# for loc_name, loc_data in location_table.items():
|
||||||
|
|
||||||
|
# if flags["EventFlag"][280] & 1 and not ctx.finished_game:
|
||||||
|
# await ctx.send_msgs([
|
||||||
|
# {"cmd": "StatusUpdate",
|
||||||
|
# "status": 30}
|
||||||
|
# ])
|
||||||
|
# ctx.finished_game = True
|
||||||
|
if locations == ctx.locations_array:
|
||||||
|
return
|
||||||
|
ctx.locations_array = locations
|
||||||
|
if locations is not None:
|
||||||
|
await ctx.send_msgs([{"cmd": "LocationChecks", "locations": locations}])
|
||||||
|
|
||||||
|
|
||||||
|
def send_ap_foreign_items(adventure_context):
|
||||||
|
foreign_item_json_list = []
|
||||||
|
autocollect_item_json_list = []
|
||||||
|
bat_no_touch_locations_json_list = []
|
||||||
|
for fi in adventure_context.foreign_items:
|
||||||
|
foreign_item_json_list.append(fi.get_dict())
|
||||||
|
for fi in adventure_context.autocollect_items:
|
||||||
|
autocollect_item_json_list.append(fi.get_dict())
|
||||||
|
for ntl in adventure_context.bat_no_touch_locations:
|
||||||
|
bat_no_touch_locations_json_list.append(ntl.get_dict())
|
||||||
|
payload = json.dumps(
|
||||||
|
{
|
||||||
|
"foreign_items": foreign_item_json_list,
|
||||||
|
"autocollect_items": autocollect_item_json_list,
|
||||||
|
"local_item_locations": adventure_context.local_item_locations,
|
||||||
|
"bat_no_touch_locations": bat_no_touch_locations_json_list
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print("sending foreign items")
|
||||||
|
msg = payload.encode()
|
||||||
|
(reader, writer) = adventure_context.atari_streams
|
||||||
|
writer.write(msg)
|
||||||
|
writer.write(b'\n')
|
||||||
|
|
||||||
|
|
||||||
|
def send_checked_locations_if_needed(adventure_context):
|
||||||
|
if not adventure_context.checked_locations_sent and adventure_context.checked_locations is not None:
|
||||||
|
if len(adventure_context.checked_locations) == 0:
|
||||||
|
return
|
||||||
|
checked_short_ids = []
|
||||||
|
for location in adventure_context.checked_locations:
|
||||||
|
checked_short_ids.append(location - base_location_id)
|
||||||
|
print("Sending checked locations")
|
||||||
|
payload = json.dumps(
|
||||||
|
{
|
||||||
|
"checked_locations": checked_short_ids,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = payload.encode()
|
||||||
|
(reader, writer) = adventure_context.atari_streams
|
||||||
|
writer.write(msg)
|
||||||
|
writer.write(b'\n')
|
||||||
|
adventure_context.checked_locations_sent = True
|
||||||
|
|
||||||
|
|
||||||
|
async def atari_sync_task(ctx: AdventureContext):
|
||||||
|
logger.info("Starting Atari 2600 connector. Use /2600 for status information")
|
||||||
|
while not ctx.exit_event.is_set():
|
||||||
|
try:
|
||||||
|
error_status = None
|
||||||
|
if ctx.atari_streams:
|
||||||
|
(reader, writer) = ctx.atari_streams
|
||||||
|
msg = get_payload(ctx).encode()
|
||||||
|
writer.write(msg)
|
||||||
|
writer.write(b'\n')
|
||||||
|
try:
|
||||||
|
await asyncio.wait_for(writer.drain(), timeout=1.5)
|
||||||
|
try:
|
||||||
|
# Data will return a dict with 1+ fields
|
||||||
|
# 1. A keepalive response of the Players Name (always)
|
||||||
|
# 2. romhash field with sha256 hash of the ROM memory region
|
||||||
|
# 3. locations, messages, and deathLink
|
||||||
|
# 4. freeincarnate, to indicate a freeincarnate was used
|
||||||
|
data = await asyncio.wait_for(reader.readline(), timeout=5)
|
||||||
|
data_decoded = json.loads(data.decode())
|
||||||
|
if 'scriptVersion' not in data_decoded or data_decoded['scriptVersion'] != SCRIPT_VERSION:
|
||||||
|
msg = "You are connecting with an incompatible Lua script version. Ensure your connector " \
|
||||||
|
"Lua and AdventureClient are from the same Archipelago installation."
|
||||||
|
logger.info(msg, extra={'compact_gui': True})
|
||||||
|
ctx.gui_error('Error', msg)
|
||||||
|
error_status = CONNECTION_RESET_STATUS
|
||||||
|
if ctx.seed_name and bytes(ctx.seed_name, encoding='ASCII') != ctx.seed_name_from_data:
|
||||||
|
msg = "The server is running a different multiworld than your client is. " \
|
||||||
|
"(invalid seed_name)"
|
||||||
|
logger.info(msg, extra={'compact_gui': True})
|
||||||
|
ctx.gui_error('Error', msg)
|
||||||
|
error_status = CONNECTION_RESET_STATUS
|
||||||
|
if 'romhash' in data_decoded:
|
||||||
|
if ctx.rom_hash.upper() != data_decoded['romhash'].upper():
|
||||||
|
msg = "The rom hash does not match the client rom hash data"
|
||||||
|
print("got " + data_decoded['romhash'])
|
||||||
|
print("expected " + str(ctx.rom_hash))
|
||||||
|
logger.info(msg, extra={'compact_gui': True})
|
||||||
|
ctx.gui_error('Error', msg)
|
||||||
|
error_status = CONNECTION_RESET_STATUS
|
||||||
|
if ctx.auth is None:
|
||||||
|
ctx.auth = ctx.player_name
|
||||||
|
if ctx.awaiting_rom:
|
||||||
|
await ctx.server_auth(False)
|
||||||
|
if 'locations' in data_decoded and ctx.game and ctx.atari_status == CONNECTION_CONNECTED_STATUS \
|
||||||
|
and not error_status and ctx.auth:
|
||||||
|
# Not just a keep alive ping, parse
|
||||||
|
async_start(parse_locations(data_decoded['locations'], ctx))
|
||||||
|
if 'deathLink' in data_decoded and data_decoded['deathLink'] > 0 and 'DeathLink' in ctx.tags:
|
||||||
|
dragon_name = "a dragon"
|
||||||
|
if data_decoded['deathLink'] == 1:
|
||||||
|
dragon_name = "Rhindle"
|
||||||
|
elif data_decoded['deathLink'] == 2:
|
||||||
|
dragon_name = "Yorgle"
|
||||||
|
elif data_decoded['deathLink'] == 3:
|
||||||
|
dragon_name = "Grundle"
|
||||||
|
print (ctx.auth + " has been eaten by " + dragon_name )
|
||||||
|
await ctx.send_death(ctx.auth + " has been eaten by " + dragon_name)
|
||||||
|
# TODO - also if player reincarnates with a dragon onscreen ' dies to avoid being eaten by '
|
||||||
|
if 'victory' in data_decoded and not ctx.finished_game:
|
||||||
|
await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}])
|
||||||
|
ctx.finished_game = True
|
||||||
|
if 'freeincarnate' in data_decoded:
|
||||||
|
await ctx.used_freeincarnate()
|
||||||
|
if ctx.set_deathlink:
|
||||||
|
await ctx.update_death_link(True)
|
||||||
|
send_checked_locations_if_needed(ctx)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.debug("Read Timed Out, Reconnecting")
|
||||||
|
error_status = CONNECTION_TIMING_OUT_STATUS
|
||||||
|
writer.close()
|
||||||
|
ctx.atari_streams = None
|
||||||
|
except ConnectionResetError as e:
|
||||||
|
logger.debug("Read failed due to Connection Lost, Reconnecting")
|
||||||
|
error_status = CONNECTION_RESET_STATUS
|
||||||
|
writer.close()
|
||||||
|
ctx.atari_streams = None
|
||||||
|
except TimeoutError:
|
||||||
|
logger.debug("Connection Timed Out, Reconnecting")
|
||||||
|
error_status = CONNECTION_TIMING_OUT_STATUS
|
||||||
|
writer.close()
|
||||||
|
ctx.atari_streams = None
|
||||||
|
except ConnectionResetError:
|
||||||
|
logger.debug("Connection Lost, Reconnecting")
|
||||||
|
error_status = CONNECTION_RESET_STATUS
|
||||||
|
writer.close()
|
||||||
|
ctx.atari_streams = None
|
||||||
|
except CancelledError:
|
||||||
|
logger.debug("Connection Cancelled, Reconnecting")
|
||||||
|
error_status = CONNECTION_RESET_STATUS
|
||||||
|
writer.close()
|
||||||
|
ctx.atari_streams = None
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
print("unknown exception " + e)
|
||||||
|
raise
|
||||||
|
if ctx.atari_status == CONNECTION_TENTATIVE_STATUS:
|
||||||
|
if not error_status:
|
||||||
|
logger.info("Successfully Connected to 2600")
|
||||||
|
ctx.atari_status = CONNECTION_CONNECTED_STATUS
|
||||||
|
ctx.checked_locations_sent = False
|
||||||
|
send_ap_foreign_items(ctx)
|
||||||
|
send_checked_locations_if_needed(ctx)
|
||||||
|
else:
|
||||||
|
ctx.atari_status = f"Was tentatively connected but error occurred: {error_status}"
|
||||||
|
elif error_status:
|
||||||
|
ctx.atari_status = error_status
|
||||||
|
logger.info("Lost connection to 2600 and attempting to reconnect. Use /2600 for status updates")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
port = ctx.lua_connector_port + ctx.port_offset
|
||||||
|
logger.debug(f"Attempting to connect to 2600 on port {port}")
|
||||||
|
print(f"Attempting to connect to 2600 on port {port}")
|
||||||
|
ctx.atari_streams = await asyncio.wait_for(
|
||||||
|
asyncio.open_connection("localhost",
|
||||||
|
port),
|
||||||
|
timeout=10)
|
||||||
|
ctx.atari_status = CONNECTION_TENTATIVE_STATUS
|
||||||
|
except TimeoutError:
|
||||||
|
logger.debug("Connection Timed Out, Trying Again")
|
||||||
|
ctx.atari_status = CONNECTION_TIMING_OUT_STATUS
|
||||||
|
continue
|
||||||
|
except ConnectionRefusedError:
|
||||||
|
logger.debug("Connection Refused, Trying Again")
|
||||||
|
ctx.atari_status = CONNECTION_REFUSED_STATUS
|
||||||
|
continue
|
||||||
|
except CancelledError:
|
||||||
|
pass
|
||||||
|
except CancelledError:
|
||||||
|
pass
|
||||||
|
print("exiting atari sync task")
|
||||||
|
|
||||||
|
|
||||||
|
async def run_game(romfile):
|
||||||
|
auto_start = Utils.get_options()["adventure_options"].get("rom_start", True)
|
||||||
|
rom_args = Utils.get_options()["adventure_options"].get("rom_args")
|
||||||
|
if auto_start is True:
|
||||||
|
import webbrowser
|
||||||
|
webbrowser.open(romfile)
|
||||||
|
elif os.path.isfile(auto_start):
|
||||||
|
open_args = [auto_start, romfile]
|
||||||
|
if rom_args is not None:
|
||||||
|
open_args.insert(1, rom_args)
|
||||||
|
subprocess.Popen(open_args,
|
||||||
|
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
|
|
||||||
|
async def patch_and_run_game(patch_file, ctx):
|
||||||
|
base_name = os.path.splitext(patch_file)[0]
|
||||||
|
comp_path = base_name + '.a26'
|
||||||
|
try:
|
||||||
|
base_rom = AdventureDeltaPatch.get_source_data()
|
||||||
|
except Exception as msg:
|
||||||
|
logger.info(msg, extra={'compact_gui': True})
|
||||||
|
ctx.gui_error('Error', msg)
|
||||||
|
|
||||||
|
with open(Utils.local_path("data", "adventure_basepatch.bsdiff4"), "rb") as file:
|
||||||
|
basepatch = bytes(file.read())
|
||||||
|
|
||||||
|
base_patched_rom_data = bsdiff4.patch(base_rom, basepatch)
|
||||||
|
|
||||||
|
with zipfile.ZipFile(patch_file, 'r') as patch_archive:
|
||||||
|
if not AdventureDeltaPatch.check_version(patch_archive):
|
||||||
|
logger.error("apadvn version doesn't match this client. Make sure your generator and client are the same")
|
||||||
|
raise Exception("apadvn version doesn't match this client.")
|
||||||
|
|
||||||
|
ctx.foreign_items = AdventureDeltaPatch.read_foreign_items(patch_archive)
|
||||||
|
ctx.autocollect_items = AdventureDeltaPatch.read_autocollect_items(patch_archive)
|
||||||
|
ctx.local_item_locations = AdventureDeltaPatch.read_local_item_locations(patch_archive)
|
||||||
|
ctx.dragon_speed_info = AdventureDeltaPatch.read_dragon_speed_info(patch_archive)
|
||||||
|
ctx.seed_name_from_data, ctx.player_name = AdventureDeltaPatch.read_rom_info(patch_archive)
|
||||||
|
ctx.diff_a_mode, ctx.diff_b_mode = AdventureDeltaPatch.read_difficulty_switch_info(patch_archive)
|
||||||
|
ctx.bat_logic = AdventureDeltaPatch.read_bat_logic(patch_archive)
|
||||||
|
ctx.bat_no_touch_locations = AdventureDeltaPatch.read_bat_no_touch(patch_archive)
|
||||||
|
ctx.rom_deltas = AdventureDeltaPatch.read_rom_deltas(patch_archive)
|
||||||
|
ctx.auth = ctx.player_name
|
||||||
|
|
||||||
|
patched_rom_data = AdventureDeltaPatch.apply_rom_deltas(base_patched_rom_data, ctx.rom_deltas)
|
||||||
|
rom_hash = hashlib.sha256()
|
||||||
|
rom_hash.update(patched_rom_data)
|
||||||
|
ctx.rom_hash = rom_hash.hexdigest()
|
||||||
|
ctx.port_offset = patched_rom_data[connector_port_offset]
|
||||||
|
|
||||||
|
with open(comp_path, "wb") as patched_rom_file:
|
||||||
|
patched_rom_file.write(patched_rom_data)
|
||||||
|
|
||||||
|
async_start(run_game(comp_path))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
Utils.init_logging("AdventureClient")
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
parser = get_base_parser()
|
||||||
|
parser.add_argument('patch_file', default="", type=str, nargs="?",
|
||||||
|
help='Path to an ADVNTURE.BIN rom file')
|
||||||
|
parser.add_argument('port', default=17242, type=int, nargs="?",
|
||||||
|
help='port for adventure_connector connection')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
ctx = AdventureContext(args.connect, args.password)
|
||||||
|
ctx.server_task = asyncio.create_task(server_loop(ctx), name="ServerLoop")
|
||||||
|
if gui_enabled:
|
||||||
|
ctx.run_gui()
|
||||||
|
ctx.run_cli()
|
||||||
|
ctx.atari_sync_task = asyncio.create_task(atari_sync_task(ctx), name="Adventure Sync")
|
||||||
|
|
||||||
|
if args.patch_file:
|
||||||
|
ext = args.patch_file.split(".")[len(args.patch_file.split(".")) - 1].lower()
|
||||||
|
if ext == "apadvn":
|
||||||
|
logger.info("apadvn file supplied, beginning patching process...")
|
||||||
|
async_start(patch_and_run_game(args.patch_file, ctx))
|
||||||
|
else:
|
||||||
|
logger.warning(f"Unknown patch file extension {ext}")
|
||||||
|
if args.port is int:
|
||||||
|
ctx.lua_connector_port = args.port
|
||||||
|
|
||||||
|
await ctx.exit_event.wait()
|
||||||
|
ctx.server_address = None
|
||||||
|
|
||||||
|
await ctx.shutdown()
|
||||||
|
|
||||||
|
if ctx.atari_sync_task:
|
||||||
|
await ctx.atari_sync_task
|
||||||
|
print("finished atari_sync_task (main)")
|
||||||
|
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
colorama.init()
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
|
colorama.deinit()
|
||||||
@@ -7,9 +7,9 @@ import random
|
|||||||
import secrets
|
import secrets
|
||||||
import typing # this can go away when Python 3.8 support is dropped
|
import typing # this can go away when Python 3.8 support is dropped
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
from collections import OrderedDict, Counter, deque, ChainMap
|
from collections import ChainMap, Counter, OrderedDict, deque
|
||||||
from enum import IntEnum, IntFlag
|
from enum import IntEnum, IntFlag
|
||||||
from typing import List, Dict, Optional, Set, Iterable, Union, Any, Tuple, TypedDict, Callable, NamedTuple
|
from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, TypedDict, Union
|
||||||
|
|
||||||
import NetUtils
|
import NetUtils
|
||||||
import Options
|
import Options
|
||||||
@@ -113,7 +113,6 @@ class MultiWorld():
|
|||||||
self.dark_world_light_cone = False
|
self.dark_world_light_cone = False
|
||||||
self.rupoor_cost = 10
|
self.rupoor_cost = 10
|
||||||
self.aga_randomness = True
|
self.aga_randomness = True
|
||||||
self.lock_aga_door_in_escape = False
|
|
||||||
self.save_and_quit_from_boss = True
|
self.save_and_quit_from_boss = True
|
||||||
self.custom = False
|
self.custom = False
|
||||||
self.customitemarray = []
|
self.customitemarray = []
|
||||||
@@ -122,6 +121,7 @@ class MultiWorld():
|
|||||||
self.early_items = {player: {} for player in self.player_ids}
|
self.early_items = {player: {} for player in self.player_ids}
|
||||||
self.local_early_items = {player: {} for player in self.player_ids}
|
self.local_early_items = {player: {} for player in self.player_ids}
|
||||||
self.indirect_connections = {}
|
self.indirect_connections = {}
|
||||||
|
self.start_inventory_from_pool: Dict[int, Options.StartInventoryPool] = {}
|
||||||
self.fix_trock_doors = self.AttributeProxy(
|
self.fix_trock_doors = self.AttributeProxy(
|
||||||
lambda player: self.shuffle[player] != 'vanilla' or self.mode[player] == 'inverted')
|
lambda player: self.shuffle[player] != 'vanilla' or self.mode[player] == 'inverted')
|
||||||
self.fix_skullwoods_exit = self.AttributeProxy(
|
self.fix_skullwoods_exit = self.AttributeProxy(
|
||||||
@@ -135,7 +135,6 @@ class MultiWorld():
|
|||||||
def set_player_attr(attr, val):
|
def set_player_attr(attr, val):
|
||||||
self.__dict__.setdefault(attr, {})[player] = val
|
self.__dict__.setdefault(attr, {})[player] = val
|
||||||
|
|
||||||
set_player_attr('tech_tree_layout_prerequisites', {})
|
|
||||||
set_player_attr('_region_cache', {})
|
set_player_attr('_region_cache', {})
|
||||||
set_player_attr('shuffle', "vanilla")
|
set_player_attr('shuffle', "vanilla")
|
||||||
set_player_attr('logic', "noglitches")
|
set_player_attr('logic', "noglitches")
|
||||||
@@ -336,7 +335,7 @@ class MultiWorld():
|
|||||||
return self.player_name[player]
|
return self.player_name[player]
|
||||||
|
|
||||||
def get_file_safe_player_name(self, player: int) -> str:
|
def get_file_safe_player_name(self, player: int) -> str:
|
||||||
return ''.join(c for c in self.get_player_name(player) if c not in '<>:"/\\|?*')
|
return Utils.get_file_safe_name(self.get_player_name(player))
|
||||||
|
|
||||||
def get_out_file_name_base(self, player: int) -> str:
|
def get_out_file_name_base(self, player: int) -> str:
|
||||||
""" the base name (without file extension) for each player's output file for a seed """
|
""" the base name (without file extension) for each player's output file for a seed """
|
||||||
@@ -445,7 +444,6 @@ class MultiWorld():
|
|||||||
self.state.collect(item, True)
|
self.state.collect(item, True)
|
||||||
|
|
||||||
def push_item(self, location: Location, item: Item, collect: bool = True):
|
def push_item(self, location: Location, item: Item, collect: bool = True):
|
||||||
assert location.can_fill(self.state, item, False), f"Cannot place {item} into {location}."
|
|
||||||
location.item = item
|
location.item = item
|
||||||
item.location = location
|
item.location = location
|
||||||
if collect:
|
if collect:
|
||||||
@@ -742,9 +740,11 @@ class CollectionState():
|
|||||||
return self.prog_items[item, player] >= count
|
return self.prog_items[item, player] >= count
|
||||||
|
|
||||||
def has_all(self, items: Set[str], player: int) -> bool:
|
def has_all(self, items: Set[str], player: int) -> bool:
|
||||||
|
"""Returns True if each item name of items is in state at least once."""
|
||||||
return all(self.prog_items[item, player] for item in items)
|
return all(self.prog_items[item, player] for item in items)
|
||||||
|
|
||||||
def has_any(self, items: Set[str], player: int) -> bool:
|
def has_any(self, items: Set[str], player: int) -> bool:
|
||||||
|
"""Returns True if at least one item name of items is in state at least once."""
|
||||||
return any(self.prog_items[item, player] for item in items)
|
return any(self.prog_items[item, player] for item in items)
|
||||||
|
|
||||||
def count(self, item: str, player: int) -> int:
|
def count(self, item: str, player: int) -> int:
|
||||||
@@ -836,6 +836,29 @@ class Region:
|
|||||||
for entrance in self.entrances: # BFS might be better here, trying DFS for now.
|
for entrance in self.entrances: # BFS might be better here, trying DFS for now.
|
||||||
return entrance.parent_region.get_connecting_entrance(is_main_entrance)
|
return entrance.parent_region.get_connecting_entrance(is_main_entrance)
|
||||||
|
|
||||||
|
def add_locations(self, locations: Dict[str, Optional[int]], location_type: Optional[typing.Type[Location]] = None) -> None:
|
||||||
|
"""Adds locations to the Region object, where location_type is your Location class and locations is a dict of
|
||||||
|
location names to address."""
|
||||||
|
if location_type is None:
|
||||||
|
location_type = Location
|
||||||
|
for location, address in locations.items():
|
||||||
|
self.locations.append(location_type(self.player, location, address, self))
|
||||||
|
|
||||||
|
def add_exits(self, exits: Dict[str, Optional[str]], rules: Dict[str, Callable[[CollectionState], bool]] = None) -> None:
|
||||||
|
"""
|
||||||
|
Connects current region to regions in exit dictionary. Passed region names must exist first.
|
||||||
|
|
||||||
|
:param exits: exits from the region. format is {"connecting_region", "exit_name"}
|
||||||
|
:param rules: rules for the exits from this region. format is {"connecting_region", rule}
|
||||||
|
"""
|
||||||
|
for exiting_region, name in exits.items():
|
||||||
|
ret = Entrance(self.player, name, self) if name \
|
||||||
|
else Entrance(self.player, f"{self.name} -> {exiting_region}", self)
|
||||||
|
if rules and exiting_region in rules:
|
||||||
|
ret.access_rule = rules[exiting_region]
|
||||||
|
self.exits.append(ret)
|
||||||
|
ret.connect(self.multiworld.get_region(exiting_region, self.player))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
@@ -1208,7 +1231,7 @@ class Spoiler():
|
|||||||
raise RuntimeError(f'Not all required items reachable. Unreachable locations: {required_locations}')
|
raise RuntimeError(f'Not all required items reachable. Unreachable locations: {required_locations}')
|
||||||
|
|
||||||
# we can finally output our playthrough
|
# we can finally output our playthrough
|
||||||
self.playthrough = {"0": sorted([str(item) for item in
|
self.playthrough = {"0": sorted([self.multiworld.get_name_string_for_object(item) for item in
|
||||||
chain.from_iterable(multiworld.precollected_items.values())
|
chain.from_iterable(multiworld.precollected_items.values())
|
||||||
if item.advancement])}
|
if item.advancement])}
|
||||||
|
|
||||||
|
|||||||
@@ -68,14 +68,17 @@ class ClientCommandProcessor(CommandProcessor):
|
|||||||
self.output(f"{self.ctx.item_names[item.item]} from {self.ctx.player_names[item.player]}")
|
self.output(f"{self.ctx.item_names[item.item]} from {self.ctx.player_names[item.player]}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _cmd_missing(self) -> bool:
|
def _cmd_missing(self, filter_text = "") -> bool:
|
||||||
"""List all missing location checks, from your local game state"""
|
"""List all missing location checks, from your local game state.
|
||||||
|
Can be given text, which will be used as filter."""
|
||||||
if not self.ctx.game:
|
if not self.ctx.game:
|
||||||
self.output("No game set, cannot determine missing checks.")
|
self.output("No game set, cannot determine missing checks.")
|
||||||
return False
|
return False
|
||||||
count = 0
|
count = 0
|
||||||
checked_count = 0
|
checked_count = 0
|
||||||
for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items():
|
for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items():
|
||||||
|
if filter_text and filter_text not in location:
|
||||||
|
continue
|
||||||
if location_id < 0:
|
if location_id < 0:
|
||||||
continue
|
continue
|
||||||
if location_id not in self.ctx.locations_checked:
|
if location_id not in self.ctx.locations_checked:
|
||||||
@@ -136,7 +139,7 @@ class CommonContext:
|
|||||||
items_handling: typing.Optional[int] = None
|
items_handling: typing.Optional[int] = None
|
||||||
want_slot_data: bool = True # should slot_data be retrieved via Connect
|
want_slot_data: bool = True # should slot_data be retrieved via Connect
|
||||||
|
|
||||||
# datapackage
|
# data package
|
||||||
# Contents in flux until connection to server is made, to download correct data for this multiworld.
|
# Contents in flux until connection to server is made, to download correct data for this multiworld.
|
||||||
item_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown item (ID:{code})')
|
item_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown item (ID:{code})')
|
||||||
location_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown location (ID:{code})')
|
location_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown location (ID:{code})')
|
||||||
@@ -154,6 +157,7 @@ class CommonContext:
|
|||||||
disconnected_intentionally: bool = False
|
disconnected_intentionally: bool = False
|
||||||
server: typing.Optional[Endpoint] = None
|
server: typing.Optional[Endpoint] = None
|
||||||
server_version: Version = Version(0, 0, 0)
|
server_version: Version = Version(0, 0, 0)
|
||||||
|
generator_version: Version = Version(0, 0, 0)
|
||||||
current_energy_link_value: typing.Optional[int] = None # to display in UI, gets set by server
|
current_energy_link_value: typing.Optional[int] = None # to display in UI, gets set by server
|
||||||
|
|
||||||
last_death_link: float = time.time() # last send/received death link on AP layer
|
last_death_link: float = time.time() # last send/received death link on AP layer
|
||||||
@@ -163,6 +167,7 @@ class CommonContext:
|
|||||||
server_address: typing.Optional[str]
|
server_address: typing.Optional[str]
|
||||||
password: typing.Optional[str]
|
password: typing.Optional[str]
|
||||||
hint_cost: typing.Optional[int]
|
hint_cost: typing.Optional[int]
|
||||||
|
hint_points: typing.Optional[int]
|
||||||
player_names: typing.Dict[int, str]
|
player_names: typing.Dict[int, str]
|
||||||
|
|
||||||
finished_game: bool
|
finished_game: bool
|
||||||
@@ -223,7 +228,7 @@ class CommonContext:
|
|||||||
self.watcher_event = asyncio.Event()
|
self.watcher_event = asyncio.Event()
|
||||||
|
|
||||||
self.jsontotextparser = JSONtoTextParser(self)
|
self.jsontotextparser = JSONtoTextParser(self)
|
||||||
self.update_datapackage(network_data_package)
|
self.update_data_package(network_data_package)
|
||||||
|
|
||||||
# execution
|
# execution
|
||||||
self.keep_alive_task = asyncio.create_task(keep_alive(self), name="Bouncy")
|
self.keep_alive_task = asyncio.create_task(keep_alive(self), name="Bouncy")
|
||||||
@@ -256,6 +261,7 @@ class CommonContext:
|
|||||||
self.items_received = []
|
self.items_received = []
|
||||||
self.locations_info = {}
|
self.locations_info = {}
|
||||||
self.server_version = Version(0, 0, 0)
|
self.server_version = Version(0, 0, 0)
|
||||||
|
self.generator_version = Version(0, 0, 0)
|
||||||
self.server = None
|
self.server = None
|
||||||
self.server_task = None
|
self.server_task = None
|
||||||
self.hint_cost = None
|
self.hint_cost = None
|
||||||
@@ -399,32 +405,40 @@ class CommonContext:
|
|||||||
self.input_task.cancel()
|
self.input_task.cancel()
|
||||||
|
|
||||||
# DataPackage
|
# DataPackage
|
||||||
async def prepare_datapackage(self, relevant_games: typing.Set[str],
|
async def prepare_data_package(self, relevant_games: typing.Set[str],
|
||||||
remote_datepackage_versions: typing.Dict[str, int]):
|
remote_date_package_versions: typing.Dict[str, int],
|
||||||
|
remote_data_package_checksums: typing.Dict[str, str]):
|
||||||
"""Validate that all data is present for the current multiworld.
|
"""Validate that all data is present for the current multiworld.
|
||||||
Download, assimilate and cache missing data from the server."""
|
Download, assimilate and cache missing data from the server."""
|
||||||
# by documentation any game can use Archipelago locations/items -> always relevant
|
# by documentation any game can use Archipelago locations/items -> always relevant
|
||||||
relevant_games.add("Archipelago")
|
relevant_games.add("Archipelago")
|
||||||
|
|
||||||
cache_package = Utils.persistent_load().get("datapackage", {}).get("games", {})
|
|
||||||
needed_updates: typing.Set[str] = set()
|
needed_updates: typing.Set[str] = set()
|
||||||
for game in relevant_games:
|
for game in relevant_games:
|
||||||
if game not in remote_datepackage_versions:
|
if game not in remote_date_package_versions and game not in remote_data_package_checksums:
|
||||||
continue
|
continue
|
||||||
remote_version: int = remote_datepackage_versions[game]
|
|
||||||
|
|
||||||
if remote_version == 0: # custom datapackage for this game
|
remote_version: int = remote_date_package_versions.get(game, 0)
|
||||||
|
remote_checksum: typing.Optional[str] = remote_data_package_checksums.get(game)
|
||||||
|
|
||||||
|
if remote_version == 0 and not remote_checksum: # custom data package and no checksum for this game
|
||||||
needed_updates.add(game)
|
needed_updates.add(game)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
local_version: int = network_data_package["games"].get(game, {}).get("version", 0)
|
local_version: int = network_data_package["games"].get(game, {}).get("version", 0)
|
||||||
|
local_checksum: typing.Optional[str] = network_data_package["games"].get(game, {}).get("checksum")
|
||||||
# no action required if local version is new enough
|
# no action required if local version is new enough
|
||||||
if remote_version > local_version:
|
if (not remote_checksum and (remote_version > local_version or remote_version == 0)) \
|
||||||
cache_version: int = cache_package.get(game, {}).get("version", 0)
|
or remote_checksum != local_checksum:
|
||||||
|
cached_game = Utils.load_data_package_for_checksum(game, remote_checksum)
|
||||||
|
cache_version: int = cached_game.get("version", 0)
|
||||||
|
cache_checksum: typing.Optional[str] = cached_game.get("checksum")
|
||||||
# download remote version if cache is not new enough
|
# download remote version if cache is not new enough
|
||||||
if remote_version > cache_version:
|
if (not remote_checksum and (remote_version > cache_version or remote_version == 0)) \
|
||||||
|
or remote_checksum != cache_checksum:
|
||||||
needed_updates.add(game)
|
needed_updates.add(game)
|
||||||
else:
|
else:
|
||||||
self.update_game(cache_package[game])
|
self.update_game(cached_game)
|
||||||
if needed_updates:
|
if needed_updates:
|
||||||
await self.send_msgs([{"cmd": "GetDataPackage", "games": list(needed_updates)}])
|
await self.send_msgs([{"cmd": "GetDataPackage", "games": list(needed_updates)}])
|
||||||
|
|
||||||
@@ -434,15 +448,17 @@ class CommonContext:
|
|||||||
for location_name, location_id in game_package["location_name_to_id"].items():
|
for location_name, location_id in game_package["location_name_to_id"].items():
|
||||||
self.location_names[location_id] = location_name
|
self.location_names[location_id] = location_name
|
||||||
|
|
||||||
def update_datapackage(self, data_package: dict):
|
def update_data_package(self, data_package: dict):
|
||||||
for game, gamedata in data_package["games"].items():
|
for game, game_data in data_package["games"].items():
|
||||||
self.update_game(gamedata)
|
self.update_game(game_data)
|
||||||
|
|
||||||
def consume_network_datapackage(self, data_package: dict):
|
def consume_network_data_package(self, data_package: dict):
|
||||||
self.update_datapackage(data_package)
|
self.update_data_package(data_package)
|
||||||
current_cache = Utils.persistent_load().get("datapackage", {}).get("games", {})
|
current_cache = Utils.persistent_load().get("datapackage", {}).get("games", {})
|
||||||
current_cache.update(data_package["games"])
|
current_cache.update(data_package["games"])
|
||||||
Utils.persistent_store("datapackage", "games", current_cache)
|
Utils.persistent_store("datapackage", "games", current_cache)
|
||||||
|
for game, game_data in data_package["games"].items():
|
||||||
|
Utils.store_data_package_for_checksum(game, game_data)
|
||||||
|
|
||||||
# DeathLink hooks
|
# DeathLink hooks
|
||||||
|
|
||||||
@@ -632,11 +648,16 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
|
|||||||
logger.info('Room Information:')
|
logger.info('Room Information:')
|
||||||
logger.info('--------------------------------')
|
logger.info('--------------------------------')
|
||||||
version = args["version"]
|
version = args["version"]
|
||||||
ctx.server_version = tuple(version)
|
ctx.server_version = Version(*version)
|
||||||
version = ".".join(str(item) for item in version)
|
|
||||||
|
|
||||||
logger.info(f'Server protocol version: {version}')
|
if "generator_version" in args:
|
||||||
logger.info("Server protocol tags: " + ", ".join(args["tags"]))
|
ctx.generator_version = Version(*args["generator_version"])
|
||||||
|
logger.info(f'Server protocol version: {ctx.server_version.as_simple_string()}, '
|
||||||
|
f'generator version: {ctx.generator_version.as_simple_string()}, '
|
||||||
|
f'tags: {", ".join(args["tags"])}')
|
||||||
|
else:
|
||||||
|
logger.info(f'Server protocol version: {ctx.server_version.as_simple_string()}, '
|
||||||
|
f'tags: {", ".join(args["tags"])}')
|
||||||
if args['password']:
|
if args['password']:
|
||||||
logger.info('Password required')
|
logger.info('Password required')
|
||||||
ctx.update_permissions(args.get("permissions", {}))
|
ctx.update_permissions(args.get("permissions", {}))
|
||||||
@@ -661,14 +682,16 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
|
|||||||
current_team = network_player.team
|
current_team = network_player.team
|
||||||
logger.info(' %s (Player %d)' % (network_player.alias, network_player.slot))
|
logger.info(' %s (Player %d)' % (network_player.alias, network_player.slot))
|
||||||
|
|
||||||
# update datapackage
|
# update data package
|
||||||
await ctx.prepare_datapackage(set(args["games"]), args["datapackage_versions"])
|
data_package_versions = args.get("datapackage_versions", {})
|
||||||
|
data_package_checksums = args.get("datapackage_checksums", {})
|
||||||
|
await ctx.prepare_data_package(set(args["games"]), data_package_versions, data_package_checksums)
|
||||||
|
|
||||||
await ctx.server_auth(args['password'])
|
await ctx.server_auth(args['password'])
|
||||||
|
|
||||||
elif cmd == 'DataPackage':
|
elif cmd == 'DataPackage':
|
||||||
logger.info("Got new ID/Name DataPackage")
|
logger.info("Got new ID/Name DataPackage")
|
||||||
ctx.consume_network_datapackage(args['data'])
|
ctx.consume_network_data_package(args['data'])
|
||||||
|
|
||||||
elif cmd == 'ConnectionRefused':
|
elif cmd == 'ConnectionRefused':
|
||||||
errors = args["errors"]
|
errors = args["errors"]
|
||||||
@@ -696,6 +719,7 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
|
|||||||
ctx.slot = args["slot"]
|
ctx.slot = args["slot"]
|
||||||
# int keys get lost in JSON transfer
|
# int keys get lost in JSON transfer
|
||||||
ctx.slot_info = {int(pid): data for pid, data in args["slot_info"].items()}
|
ctx.slot_info = {int(pid): data for pid, data in args["slot_info"].items()}
|
||||||
|
ctx.hint_points = args.get("hint_points", 0)
|
||||||
ctx.consume_players_package(args["players"])
|
ctx.consume_players_package(args["players"])
|
||||||
msgs = []
|
msgs = []
|
||||||
if ctx.locations_checked:
|
if ctx.locations_checked:
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ from CommonClient import CommonContext, server_loop, gui_enabled, ClientCommandP
|
|||||||
|
|
||||||
SYSTEM_MESSAGE_ID = 0
|
SYSTEM_MESSAGE_ID = 0
|
||||||
|
|
||||||
CONNECTION_TIMING_OUT_STATUS = "Connection timing out. Please restart your emulator, then restart ff1_connector.lua"
|
CONNECTION_TIMING_OUT_STATUS = "Connection timing out. Please restart your emulator, then restart connector_ff1.lua"
|
||||||
CONNECTION_REFUSED_STATUS = "Connection Refused. Please start your emulator and make sure ff1_connector.lua is running"
|
CONNECTION_REFUSED_STATUS = "Connection Refused. Please start your emulator and make sure connector_ff1.lua is running"
|
||||||
CONNECTION_RESET_STATUS = "Connection was reset. Please restart your emulator, then restart ff1_connector.lua"
|
CONNECTION_RESET_STATUS = "Connection was reset. Please restart your emulator, then restart connector_ff1.lua"
|
||||||
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
||||||
CONNECTION_CONNECTED_STATUS = "Connected"
|
CONNECTION_CONNECTED_STATUS = "Connected"
|
||||||
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
||||||
|
|||||||
63
Fill.py
@@ -1,11 +1,10 @@
|
|||||||
import logging
|
|
||||||
import typing
|
|
||||||
import collections
|
import collections
|
||||||
import itertools
|
import itertools
|
||||||
|
import logging
|
||||||
|
import typing
|
||||||
from collections import Counter, deque
|
from collections import Counter, deque
|
||||||
|
|
||||||
from BaseClasses import CollectionState, Location, LocationProgressType, MultiWorld, Item, ItemClassification
|
from BaseClasses import CollectionState, Item, Location, LocationProgressType, MultiWorld
|
||||||
|
|
||||||
from worlds.AutoWorld import call_all
|
from worlds.AutoWorld import call_all
|
||||||
from worlds.generic.Rules import add_item_rule
|
from worlds.generic.Rules import add_item_rule
|
||||||
|
|
||||||
@@ -23,15 +22,27 @@ def sweep_from_pool(base_state: CollectionState, itempool: typing.Sequence[Item]
|
|||||||
|
|
||||||
|
|
||||||
def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations: typing.List[Location],
|
def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations: typing.List[Location],
|
||||||
itempool: typing.List[Item], single_player_placement: bool = False, lock: bool = False,
|
item_pool: typing.List[Item], single_player_placement: bool = False, lock: bool = False,
|
||||||
swap: bool = True, on_place: typing.Optional[typing.Callable[[Location], None]] = None,
|
swap: bool = True, on_place: typing.Optional[typing.Callable[[Location], None]] = None,
|
||||||
allow_partial: bool = False) -> None:
|
allow_partial: bool = False, allow_excluded: bool = False) -> None:
|
||||||
|
"""
|
||||||
|
:param world: Multiworld to be filled.
|
||||||
|
:param base_state: State assumed before fill.
|
||||||
|
:param locations: Locations to be filled with item_pool
|
||||||
|
:param item_pool: Items to fill into the locations
|
||||||
|
:param single_player_placement: if true, can speed up placement if everything belongs to a single player
|
||||||
|
:param lock: locations are set to locked as they are filled
|
||||||
|
:param swap: if true, swaps of already place items are done in the event of a dead end
|
||||||
|
:param on_place: callback that is called when a placement happens
|
||||||
|
:param allow_partial: only place what is possible. Remaining items will be in the item_pool list.
|
||||||
|
:param allow_excluded: if true and placement fails, it is re-attempted while ignoring excluded on Locations
|
||||||
|
"""
|
||||||
unplaced_items: typing.List[Item] = []
|
unplaced_items: typing.List[Item] = []
|
||||||
placements: typing.List[Location] = []
|
placements: typing.List[Location] = []
|
||||||
|
|
||||||
swapped_items: typing.Counter[typing.Tuple[int, str]] = Counter()
|
swapped_items: typing.Counter[typing.Tuple[int, str]] = Counter()
|
||||||
reachable_items: typing.Dict[int, typing.Deque[Item]] = {}
|
reachable_items: typing.Dict[int, typing.Deque[Item]] = {}
|
||||||
for item in itempool:
|
for item in item_pool:
|
||||||
reachable_items.setdefault(item.player, deque()).append(item)
|
reachable_items.setdefault(item.player, deque()).append(item)
|
||||||
|
|
||||||
while any(reachable_items.values()) and locations:
|
while any(reachable_items.values()) and locations:
|
||||||
@@ -39,9 +50,9 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:
|
|||||||
items_to_place = [items.pop()
|
items_to_place = [items.pop()
|
||||||
for items in reachable_items.values() if items]
|
for items in reachable_items.values() if items]
|
||||||
for item in items_to_place:
|
for item in items_to_place:
|
||||||
itempool.remove(item)
|
item_pool.remove(item)
|
||||||
maximum_exploration_state = sweep_from_pool(
|
maximum_exploration_state = sweep_from_pool(
|
||||||
base_state, itempool + unplaced_items)
|
base_state, item_pool + unplaced_items)
|
||||||
|
|
||||||
has_beaten_game = world.has_beaten_game(maximum_exploration_state)
|
has_beaten_game = world.has_beaten_game(maximum_exploration_state)
|
||||||
|
|
||||||
@@ -111,7 +122,7 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:
|
|||||||
|
|
||||||
reachable_items[placed_item.player].appendleft(
|
reachable_items[placed_item.player].appendleft(
|
||||||
placed_item)
|
placed_item)
|
||||||
itempool.append(placed_item)
|
item_pool.append(placed_item)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -133,6 +144,21 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:
|
|||||||
if on_place:
|
if on_place:
|
||||||
on_place(spot_to_fill)
|
on_place(spot_to_fill)
|
||||||
|
|
||||||
|
if allow_excluded:
|
||||||
|
# check if partial fill is the result of excluded locations, in which case retry
|
||||||
|
excluded_locations = [
|
||||||
|
location for location in locations
|
||||||
|
if location.progress_type == location.progress_type.EXCLUDED and not location.item
|
||||||
|
]
|
||||||
|
if excluded_locations:
|
||||||
|
for location in excluded_locations:
|
||||||
|
location.progress_type = location.progress_type.DEFAULT
|
||||||
|
fill_restrictive(world, base_state, excluded_locations, unplaced_items, single_player_placement, lock,
|
||||||
|
swap, on_place, allow_partial, False)
|
||||||
|
for location in excluded_locations:
|
||||||
|
if not location.item:
|
||||||
|
location.progress_type = location.progress_type.EXCLUDED
|
||||||
|
|
||||||
if not allow_partial and len(unplaced_items) > 0 and len(locations) > 0:
|
if not allow_partial and len(unplaced_items) > 0 and len(locations) > 0:
|
||||||
# There are leftover unplaceable items and locations that won't accept them
|
# There are leftover unplaceable items and locations that won't accept them
|
||||||
if world.can_beat_game():
|
if world.can_beat_game():
|
||||||
@@ -142,7 +168,7 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:
|
|||||||
raise FillError(f'No more spots to place {unplaced_items}, locations {locations} are invalid. '
|
raise FillError(f'No more spots to place {unplaced_items}, locations {locations} are invalid. '
|
||||||
f'Already placed {len(placements)}: {", ".join(str(place) for place in placements)}')
|
f'Already placed {len(placements)}: {", ".join(str(place) for place in placements)}')
|
||||||
|
|
||||||
itempool.extend(unplaced_items)
|
item_pool.extend(unplaced_items)
|
||||||
|
|
||||||
|
|
||||||
def remaining_fill(world: MultiWorld,
|
def remaining_fill(world: MultiWorld,
|
||||||
@@ -499,16 +525,16 @@ def balance_multiworld_progression(world: MultiWorld) -> None:
|
|||||||
checked_locations: typing.Set[Location] = set()
|
checked_locations: typing.Set[Location] = set()
|
||||||
unchecked_locations: typing.Set[Location] = set(world.get_locations())
|
unchecked_locations: typing.Set[Location] = set(world.get_locations())
|
||||||
|
|
||||||
reachable_locations_count: typing.Dict[int, int] = {
|
|
||||||
player: 0
|
|
||||||
for player in world.player_ids
|
|
||||||
if len(world.get_filled_locations(player)) != 0
|
|
||||||
}
|
|
||||||
total_locations_count: typing.Counter[int] = Counter(
|
total_locations_count: typing.Counter[int] = Counter(
|
||||||
location.player
|
location.player
|
||||||
for location in world.get_locations()
|
for location in world.get_locations()
|
||||||
if not location.locked
|
if not location.locked
|
||||||
)
|
)
|
||||||
|
reachable_locations_count: typing.Dict[int, int] = {
|
||||||
|
player: 0
|
||||||
|
for player in world.player_ids
|
||||||
|
if total_locations_count[player] and len(world.get_filled_locations(player)) != 0
|
||||||
|
}
|
||||||
balanceable_players = {
|
balanceable_players = {
|
||||||
player: balanceable_players[player]
|
player: balanceable_players[player]
|
||||||
for player in balanceable_players
|
for player in balanceable_players
|
||||||
@@ -525,6 +551,10 @@ def balance_multiworld_progression(world: MultiWorld) -> None:
|
|||||||
def item_percentage(player: int, num: int) -> float:
|
def item_percentage(player: int, num: int) -> float:
|
||||||
return num / total_locations_count[player]
|
return num / total_locations_count[player]
|
||||||
|
|
||||||
|
# If there are no locations that aren't locked, there's no point in attempting to balance progression.
|
||||||
|
if len(total_locations_count) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# Gather non-locked locations.
|
# Gather non-locked locations.
|
||||||
# This ensures that only shuffled locations get counted for progression balancing,
|
# This ensures that only shuffled locations get counted for progression balancing,
|
||||||
@@ -798,7 +828,6 @@ def distribute_planned(world: MultiWorld) -> None:
|
|||||||
for player in worlds:
|
for player in worlds:
|
||||||
locations += non_early_locations[player]
|
locations += non_early_locations[player]
|
||||||
|
|
||||||
|
|
||||||
block['locations'] = locations
|
block['locations'] = locations
|
||||||
|
|
||||||
if not block['count']:
|
if not block['count']:
|
||||||
|
|||||||
894
KH2Client.py
Normal file
@@ -0,0 +1,894 @@
|
|||||||
|
import os
|
||||||
|
import asyncio
|
||||||
|
import ModuleUpdate
|
||||||
|
import json
|
||||||
|
import Utils
|
||||||
|
from pymem import pymem
|
||||||
|
from worlds.kh2.Items import exclusionItem_table, CheckDupingItems
|
||||||
|
from worlds.kh2 import all_locations, item_dictionary_table, exclusion_table
|
||||||
|
|
||||||
|
from worlds.kh2.WorldLocations import *
|
||||||
|
|
||||||
|
from worlds import network_data_package
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Utils.init_logging("KH2Client", exception_logger="Client")
|
||||||
|
|
||||||
|
from NetUtils import ClientStatus
|
||||||
|
from CommonClient import gui_enabled, logger, get_base_parser, ClientCommandProcessor, \
|
||||||
|
CommonContext, server_loop
|
||||||
|
|
||||||
|
ModuleUpdate.update()
|
||||||
|
|
||||||
|
kh2_loc_name_to_id = network_data_package["games"]["Kingdom Hearts 2"]["location_name_to_id"]
|
||||||
|
|
||||||
|
|
||||||
|
# class KH2CommandProcessor(ClientCommandProcessor):
|
||||||
|
|
||||||
|
|
||||||
|
class KH2Context(CommonContext):
|
||||||
|
# command_processor: int = KH2CommandProcessor
|
||||||
|
game = "Kingdom Hearts 2"
|
||||||
|
items_handling = 0b101 # Indicates you get items sent from other worlds.
|
||||||
|
|
||||||
|
def __init__(self, server_address, password):
|
||||||
|
super(KH2Context, self).__init__(server_address, password)
|
||||||
|
self.kh2LocalItems = None
|
||||||
|
self.ability = None
|
||||||
|
self.growthlevel = None
|
||||||
|
self.KH2_sync_task = None
|
||||||
|
self.syncing = False
|
||||||
|
self.kh2connected = False
|
||||||
|
self.serverconneced = False
|
||||||
|
self.item_name_to_data = {name: data for name, data, in item_dictionary_table.items()}
|
||||||
|
self.location_name_to_data = {name: data for name, data, in all_locations.items()}
|
||||||
|
self.lookup_id_to_item: typing.Dict[int, str] = {data.code: item_name for item_name, data in
|
||||||
|
item_dictionary_table.items() if data.code}
|
||||||
|
self.lookup_id_to_Location: typing.Dict[int, str] = {data.code: item_name for item_name, data in
|
||||||
|
all_locations.items() if data.code}
|
||||||
|
self.location_name_to_worlddata = {name: data for name, data, in all_world_locations.items()}
|
||||||
|
|
||||||
|
self.location_table = {}
|
||||||
|
self.collectible_table = {}
|
||||||
|
self.collectible_override_flags_address = 0
|
||||||
|
self.collectible_offsets = {}
|
||||||
|
self.sending = []
|
||||||
|
# list used to keep track of locations+items player has. Used for disoneccting
|
||||||
|
self.kh2seedsave = None
|
||||||
|
self.slotDataProgressionNames = {}
|
||||||
|
self.kh2seedname = None
|
||||||
|
self.kh2slotdata = None
|
||||||
|
self.itemamount = {}
|
||||||
|
# sora equipped, valor equipped, master equipped, final equipped
|
||||||
|
self.keybladeAnchorList = (0x24F0, 0x32F4, 0x339C, 0x33D4)
|
||||||
|
if "localappdata" in os.environ:
|
||||||
|
self.game_communication_path = os.path.expandvars(r"%localappdata%\KH2AP")
|
||||||
|
self.amountOfPieces = 0
|
||||||
|
# hooked object
|
||||||
|
self.kh2 = None
|
||||||
|
self.ItemIsSafe = False
|
||||||
|
self.game_connected = False
|
||||||
|
self.finalxemnas = False
|
||||||
|
self.worldid = {
|
||||||
|
# 1: {}, # world of darkness (story cutscenes)
|
||||||
|
2: TT_Checks,
|
||||||
|
# 3: {}, # destiny island doesn't have checks to ima put tt checks here
|
||||||
|
4: HB_Checks,
|
||||||
|
5: BC_Checks,
|
||||||
|
6: Oc_Checks,
|
||||||
|
7: AG_Checks,
|
||||||
|
8: LoD_Checks,
|
||||||
|
9: HundredAcreChecks,
|
||||||
|
10: PL_Checks,
|
||||||
|
11: DC_Checks, # atlantica isn't a supported world. if you go in atlantica it will check dc
|
||||||
|
12: DC_Checks,
|
||||||
|
13: TR_Checks,
|
||||||
|
14: HT_Checks,
|
||||||
|
15: HB_Checks, # world map, but you only go to the world map while on the way to goa so checking hb
|
||||||
|
16: PR_Checks,
|
||||||
|
17: SP_Checks,
|
||||||
|
18: TWTNW_Checks,
|
||||||
|
# 255: {}, # starting screen
|
||||||
|
}
|
||||||
|
# 0x2A09C00+0x40 is the sve anchor. +1 is the last saved room
|
||||||
|
self.sveroom = 0x2A09C00 + 0x41
|
||||||
|
# 0 not in battle 1 in yellow battle 2 red battle #short
|
||||||
|
self.inBattle = 0x2A0EAC4 + 0x40
|
||||||
|
self.onDeath = 0xAB9078
|
||||||
|
# PC Address anchors
|
||||||
|
self.Now = 0x0714DB8
|
||||||
|
self.Save = 0x09A70B0
|
||||||
|
self.Sys3 = 0x2A59DF0
|
||||||
|
self.Bt10 = 0x2A74880
|
||||||
|
self.BtlEnd = 0x2A0D3E0
|
||||||
|
self.Slot1 = 0x2A20C98
|
||||||
|
|
||||||
|
self.chest_set = set(exclusion_table["Chests"])
|
||||||
|
|
||||||
|
self.keyblade_set = set(CheckDupingItems["Weapons"]["Keyblades"])
|
||||||
|
self.staff_set = set(CheckDupingItems["Weapons"]["Staffs"])
|
||||||
|
self.shield_set = set(CheckDupingItems["Weapons"]["Shields"])
|
||||||
|
|
||||||
|
self.all_weapons = self.keyblade_set.union(self.staff_set).union(self.shield_set)
|
||||||
|
|
||||||
|
self.equipment_categories = CheckDupingItems["Equipment"]
|
||||||
|
self.armor_set = set(self.equipment_categories["Armor"])
|
||||||
|
self.accessories_set = set(self.equipment_categories["Accessories"])
|
||||||
|
self.all_equipment = self.armor_set.union(self.accessories_set)
|
||||||
|
|
||||||
|
self.Equipment_Anchor_Dict = {
|
||||||
|
"Armor": [0x2504, 0x2506, 0x2508, 0x250A],
|
||||||
|
"Accessories": [0x2514, 0x2516, 0x2518, 0x251A]}
|
||||||
|
|
||||||
|
self.AbilityQuantityDict = {}
|
||||||
|
self.ability_categories = CheckDupingItems["Abilities"]
|
||||||
|
|
||||||
|
self.sora_ability_set = set(self.ability_categories["Sora"])
|
||||||
|
self.donald_ability_set = set(self.ability_categories["Donald"])
|
||||||
|
self.goofy_ability_set = set(self.ability_categories["Goofy"])
|
||||||
|
|
||||||
|
self.all_abilities = self.sora_ability_set.union(self.donald_ability_set).union(self.goofy_ability_set)
|
||||||
|
|
||||||
|
self.boost_set = set(CheckDupingItems["Boosts"])
|
||||||
|
self.stat_increase_set = set(CheckDupingItems["Stat Increases"])
|
||||||
|
self.AbilityQuantityDict = {item: self.item_name_to_data[item].quantity for item in self.all_abilities}
|
||||||
|
# Growth:[level 1,level 4,slot]
|
||||||
|
self.growth_values_dict = {"High Jump": [0x05E, 0x061, 0x25DA],
|
||||||
|
"Quick Run": [0x62, 0x65, 0x25DC],
|
||||||
|
"Dodge Roll": [0x234, 0x237, 0x25DE],
|
||||||
|
"Aerial Dodge": [0x066, 0x069, 0x25E0],
|
||||||
|
"Glide": [0x6A, 0x6D, 0x25E2]}
|
||||||
|
self.boost_to_anchor_dict = {
|
||||||
|
"Power Boost": 0x24F9,
|
||||||
|
"Magic Boost": 0x24FA,
|
||||||
|
"Defense Boost": 0x24FB,
|
||||||
|
"AP Boost": 0x24F8}
|
||||||
|
|
||||||
|
self.AbilityCodeList = [self.item_name_to_data[item].code for item in exclusionItem_table["Ability"]]
|
||||||
|
self.master_growth = {"High Jump", "Quick Run", "Dodge Roll", "Aerial Dodge", "Glide"}
|
||||||
|
|
||||||
|
self.bitmask_item_code = [
|
||||||
|
0x130000, 0x130001, 0x130002, 0x130003, 0x130004, 0x130005, 0x130006, 0x130007
|
||||||
|
, 0x130008, 0x130009, 0x13000A, 0x13000B, 0x13000C
|
||||||
|
, 0x13001F, 0x130020, 0x130021, 0x130022, 0x130023
|
||||||
|
, 0x13002A, 0x13002B, 0x13002C, 0x13002D]
|
||||||
|
|
||||||
|
async def server_auth(self, password_requested: bool = False):
|
||||||
|
if password_requested and not self.password:
|
||||||
|
await super(KH2Context, self).server_auth(password_requested)
|
||||||
|
await self.get_username()
|
||||||
|
await self.send_connect()
|
||||||
|
|
||||||
|
async def connection_closed(self):
|
||||||
|
self.kh2connected = False
|
||||||
|
self.serverconneced = False
|
||||||
|
if self.kh2seedname is not None and self.auth is not None:
|
||||||
|
with open(os.path.join(self.game_communication_path, f"kh2save{self.kh2seedname}{self.auth}.json"),
|
||||||
|
'w') as f:
|
||||||
|
f.write(json.dumps(self.kh2seedsave, indent=4))
|
||||||
|
await super(KH2Context, self).connection_closed()
|
||||||
|
|
||||||
|
async def disconnect(self, allow_autoreconnect: bool = False):
|
||||||
|
self.kh2connected = False
|
||||||
|
self.serverconneced = False
|
||||||
|
if self.kh2seedname not in {None} and self.auth not in {None}:
|
||||||
|
with open(os.path.join(self.game_communication_path, f"kh2save{self.kh2seedname}{self.auth}.json"),
|
||||||
|
'w') as f:
|
||||||
|
f.write(json.dumps(self.kh2seedsave, indent=4))
|
||||||
|
await super(KH2Context, self).disconnect()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def endpoints(self):
|
||||||
|
if self.server:
|
||||||
|
return [self.server]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
async def shutdown(self):
|
||||||
|
if self.kh2seedname not in {None} and self.auth not in {None}:
|
||||||
|
with open(os.path.join(self.game_communication_path, f"kh2save{self.kh2seedname}{self.auth}.json"),
|
||||||
|
'w') as f:
|
||||||
|
f.write(json.dumps(self.kh2seedsave, indent=4))
|
||||||
|
await super(KH2Context, self).shutdown()
|
||||||
|
|
||||||
|
def on_package(self, cmd: str, args: dict):
|
||||||
|
if cmd in {"RoomInfo"}:
|
||||||
|
self.kh2seedname = args['seed_name']
|
||||||
|
if not os.path.exists(self.game_communication_path):
|
||||||
|
os.makedirs(self.game_communication_path)
|
||||||
|
if not os.path.exists(self.game_communication_path + f"\kh2save{self.kh2seedname}{self.auth}.json"):
|
||||||
|
self.kh2seedsave = {"itemIndex": -1,
|
||||||
|
# back of soras invo is 0x25E2. Growth should be moved there
|
||||||
|
# Character: [back of invo, front of invo]
|
||||||
|
"SoraInvo": [0x25D8, 0x2546],
|
||||||
|
"DonaldInvo": [0x26F4, 0x2658],
|
||||||
|
"GoofyInvo": [0x280A, 0x276C],
|
||||||
|
"AmountInvo": {
|
||||||
|
"ServerItems": {
|
||||||
|
"Ability": {},
|
||||||
|
"Amount": {},
|
||||||
|
"Growth": {"High Jump": 0, "Quick Run": 0, "Dodge Roll": 0,
|
||||||
|
"Aerial Dodge": 0,
|
||||||
|
"Glide": 0},
|
||||||
|
"Bitmask": [],
|
||||||
|
"Weapon": {"Sora": [], "Donald": [], "Goofy": []},
|
||||||
|
"Equipment": [],
|
||||||
|
"Magic": {},
|
||||||
|
"StatIncrease": {},
|
||||||
|
"Boost": {},
|
||||||
|
},
|
||||||
|
"LocalItems": {
|
||||||
|
"Ability": {},
|
||||||
|
"Amount": {},
|
||||||
|
"Growth": {"High Jump": 0, "Quick Run": 0, "Dodge Roll": 0,
|
||||||
|
"Aerial Dodge": 0, "Glide": 0},
|
||||||
|
"Bitmask": [],
|
||||||
|
"Weapon": {"Sora": [], "Donald": [], "Goofy": []},
|
||||||
|
"Equipment": [],
|
||||||
|
"Magic": {},
|
||||||
|
"StatIncrease": {},
|
||||||
|
"Boost": {},
|
||||||
|
}},
|
||||||
|
# 1,3,255 are in this list in case the player gets locations in those "worlds" and I need to still have them checked
|
||||||
|
"LocationsChecked": [],
|
||||||
|
"Levels": {
|
||||||
|
"SoraLevel": 0,
|
||||||
|
"ValorLevel": 0,
|
||||||
|
"WisdomLevel": 0,
|
||||||
|
"LimitLevel": 0,
|
||||||
|
"MasterLevel": 0,
|
||||||
|
"FinalLevel": 0,
|
||||||
|
},
|
||||||
|
"SoldEquipment": [],
|
||||||
|
"SoldBoosts": {"Power Boost": 0,
|
||||||
|
"Magic Boost": 0,
|
||||||
|
"Defense Boost": 0,
|
||||||
|
"AP Boost": 0}
|
||||||
|
}
|
||||||
|
with open(os.path.join(self.game_communication_path, f"kh2save{self.kh2seedname}{self.auth}.json"),
|
||||||
|
'wt') as f:
|
||||||
|
pass
|
||||||
|
self.locations_checked = set()
|
||||||
|
elif os.path.exists(self.game_communication_path + f"\kh2save{self.kh2seedname}{self.auth}.json"):
|
||||||
|
with open(self.game_communication_path + f"\kh2save{self.kh2seedname}{self.auth}.json", 'r') as f:
|
||||||
|
self.kh2seedsave = json.load(f)
|
||||||
|
self.locations_checked = set(self.kh2seedsave["LocationsChecked"])
|
||||||
|
self.serverconneced = True
|
||||||
|
|
||||||
|
if cmd in {"Connected"}:
|
||||||
|
self.kh2slotdata = args['slot_data']
|
||||||
|
self.kh2LocalItems = {int(location): item for location, item in self.kh2slotdata["LocalItems"].items()}
|
||||||
|
try:
|
||||||
|
self.kh2 = pymem.Pymem(process_name="KINGDOM HEARTS II FINAL MIX")
|
||||||
|
logger.info("You are now auto-tracking")
|
||||||
|
self.kh2connected = True
|
||||||
|
except Exception as e:
|
||||||
|
logger.info("Line 247")
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Connection Lost")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
if cmd in {"ReceivedItems"}:
|
||||||
|
start_index = args["index"]
|
||||||
|
if start_index == 0:
|
||||||
|
# resetting everything that were sent from the server
|
||||||
|
self.kh2seedsave["SoraInvo"][0] = 0x25D8
|
||||||
|
self.kh2seedsave["DonaldInvo"][0] = 0x26F4
|
||||||
|
self.kh2seedsave["GoofyInvo"][0] = 0x280A
|
||||||
|
self.kh2seedsave["itemIndex"] = - 1
|
||||||
|
self.kh2seedsave["AmountInvo"]["ServerItems"] = {
|
||||||
|
"Ability": {},
|
||||||
|
"Amount": {},
|
||||||
|
"Growth": {"High Jump": 0, "Quick Run": 0, "Dodge Roll": 0,
|
||||||
|
"Aerial Dodge": 0,
|
||||||
|
"Glide": 0},
|
||||||
|
"Bitmask": [],
|
||||||
|
"Weapon": {"Sora": [], "Donald": [], "Goofy": []},
|
||||||
|
"Equipment": [],
|
||||||
|
"Magic": {},
|
||||||
|
"StatIncrease": {},
|
||||||
|
"Boost": {},
|
||||||
|
}
|
||||||
|
if start_index > self.kh2seedsave["itemIndex"]:
|
||||||
|
self.kh2seedsave["itemIndex"] = start_index
|
||||||
|
for item in args['items']:
|
||||||
|
asyncio.create_task(self.give_item(item.item))
|
||||||
|
|
||||||
|
if cmd in {"RoomUpdate"}:
|
||||||
|
if "checked_locations" in args:
|
||||||
|
new_locations = set(args["checked_locations"])
|
||||||
|
# TODO: make this take locations from other players on the same slot so proper coop happens
|
||||||
|
# items_to_give = [self.kh2slotdata["LocalItems"][str(location_id)] for location_id in new_locations if
|
||||||
|
# location_id in self.kh2LocalItems.keys()]
|
||||||
|
self.checked_locations |= new_locations
|
||||||
|
|
||||||
|
async def checkWorldLocations(self):
|
||||||
|
try:
|
||||||
|
currentworldint = int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + 0x0714DB8, 1), "big")
|
||||||
|
if currentworldint in self.worldid:
|
||||||
|
curworldid = self.worldid[currentworldint]
|
||||||
|
for location, data in curworldid.items():
|
||||||
|
locationId = kh2_loc_name_to_id[location]
|
||||||
|
if locationId not in self.locations_checked \
|
||||||
|
and (int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + data.addrObtained, 1),
|
||||||
|
"big") & 0x1 << data.bitIndex) > 0:
|
||||||
|
self.sending = self.sending + [(int(locationId))]
|
||||||
|
except Exception as e:
|
||||||
|
logger.info("Line 285")
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
async def checkLevels(self):
|
||||||
|
try:
|
||||||
|
for location, data in SoraLevels.items():
|
||||||
|
currentLevel = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + 0x24FF, 1), "big")
|
||||||
|
locationId = kh2_loc_name_to_id[location]
|
||||||
|
if locationId not in self.locations_checked \
|
||||||
|
and currentLevel >= data.bitIndex:
|
||||||
|
if self.kh2seedsave["Levels"]["SoraLevel"] < currentLevel:
|
||||||
|
self.kh2seedsave["Levels"]["SoraLevel"] = currentLevel
|
||||||
|
self.sending = self.sending + [(int(locationId))]
|
||||||
|
formDict = {
|
||||||
|
0: ["ValorLevel", ValorLevels], 1: ["WisdomLevel", WisdomLevels], 2: ["LimitLevel", LimitLevels],
|
||||||
|
3: ["MasterLevel", MasterLevels], 4: ["FinalLevel", FinalLevels]}
|
||||||
|
for i in range(5):
|
||||||
|
for location, data in formDict[i][1].items():
|
||||||
|
formlevel = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + data.addrObtained, 1), "big")
|
||||||
|
locationId = kh2_loc_name_to_id[location]
|
||||||
|
if locationId not in self.locations_checked \
|
||||||
|
and formlevel >= data.bitIndex:
|
||||||
|
if formlevel > self.kh2seedsave["Levels"][formDict[i][0]]:
|
||||||
|
self.kh2seedsave["Levels"][formDict[i][0]] = formlevel
|
||||||
|
self.sending = self.sending + [(int(locationId))]
|
||||||
|
except Exception as e:
|
||||||
|
logger.info("Line 312")
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
async def checkSlots(self):
|
||||||
|
try:
|
||||||
|
for location, data in weaponSlots.items():
|
||||||
|
locationId = kh2_loc_name_to_id[location]
|
||||||
|
if locationId not in self.locations_checked:
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + data.addrObtained, 1),
|
||||||
|
"big") > 0:
|
||||||
|
self.sending = self.sending + [(int(locationId))]
|
||||||
|
|
||||||
|
for location, data in formSlots.items():
|
||||||
|
locationId = kh2_loc_name_to_id[location]
|
||||||
|
if locationId not in self.locations_checked:
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + data.addrObtained, 1),
|
||||||
|
"big") & 0x1 << data.bitIndex > 0:
|
||||||
|
# self.locations_checked
|
||||||
|
self.sending = self.sending + [(int(locationId))]
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Line 333")
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
async def verifyChests(self):
|
||||||
|
try:
|
||||||
|
for location in self.locations_checked:
|
||||||
|
locationName = self.lookup_id_to_Location[location]
|
||||||
|
if locationName in self.chest_set:
|
||||||
|
if locationName in self.location_name_to_worlddata.keys():
|
||||||
|
locationData = self.location_name_to_worlddata[locationName]
|
||||||
|
if int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + locationData.addrObtained, 1),
|
||||||
|
"big") & 0x1 << locationData.bitIndex == 0:
|
||||||
|
roomData = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + locationData.addrObtained,
|
||||||
|
1), "big")
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + locationData.addrObtained,
|
||||||
|
(roomData | 0x01 << locationData.bitIndex).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Line 350")
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
async def verifyLevel(self):
|
||||||
|
for leveltype, anchor in {"SoraLevel": 0x24FF,
|
||||||
|
"ValorLevel": 0x32F6,
|
||||||
|
"WisdomLevel": 0x332E,
|
||||||
|
"LimitLevel": 0x3366,
|
||||||
|
"MasterLevel": 0x339E,
|
||||||
|
"FinalLevel": 0x33D6}.items():
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + anchor, 1), "big") < \
|
||||||
|
self.kh2seedsave["Levels"][leveltype]:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + anchor,
|
||||||
|
(self.kh2seedsave["Levels"][leveltype]).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
async def give_item(self, item, ItemType="ServerItems"):
|
||||||
|
try:
|
||||||
|
itemname = self.lookup_id_to_item[item]
|
||||||
|
itemcode = self.item_name_to_data[itemname]
|
||||||
|
if itemcode.ability:
|
||||||
|
abilityInvoType = 0
|
||||||
|
TwilightZone = 2
|
||||||
|
if ItemType == "LocalItems":
|
||||||
|
abilityInvoType = 1
|
||||||
|
TwilightZone = -2
|
||||||
|
if itemname in {"High Jump", "Quick Run", "Dodge Roll", "Aerial Dodge", "Glide"}:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Growth"][itemname] += 1
|
||||||
|
return
|
||||||
|
|
||||||
|
if itemname not in self.kh2seedsave["AmountInvo"][ItemType]["Ability"]:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Ability"][itemname] = []
|
||||||
|
# appending the slot that the ability should be in
|
||||||
|
|
||||||
|
if len(self.kh2seedsave["AmountInvo"][ItemType]["Ability"][itemname]) < \
|
||||||
|
self.AbilityQuantityDict[itemname]:
|
||||||
|
if itemname in self.sora_ability_set:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Ability"][itemname].append(
|
||||||
|
self.kh2seedsave["SoraInvo"][abilityInvoType])
|
||||||
|
self.kh2seedsave["SoraInvo"][abilityInvoType] -= TwilightZone
|
||||||
|
elif itemname in self.donald_ability_set:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Ability"][itemname].append(
|
||||||
|
self.kh2seedsave["DonaldInvo"][abilityInvoType])
|
||||||
|
self.kh2seedsave["DonaldInvo"][abilityInvoType] -= TwilightZone
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Ability"][itemname].append(
|
||||||
|
self.kh2seedsave["GoofyInvo"][abilityInvoType])
|
||||||
|
self.kh2seedsave["GoofyInvo"][abilityInvoType] -= TwilightZone
|
||||||
|
|
||||||
|
elif itemcode.code in self.bitmask_item_code:
|
||||||
|
|
||||||
|
if itemname not in self.kh2seedsave["AmountInvo"][ItemType]["Bitmask"]:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Bitmask"].append(itemname)
|
||||||
|
|
||||||
|
elif itemcode.memaddr in {0x3594, 0x3595, 0x3596, 0x3597, 0x35CF, 0x35D0}:
|
||||||
|
|
||||||
|
if itemname in self.kh2seedsave["AmountInvo"][ItemType]["Magic"]:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Magic"][itemname] += 1
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Magic"][itemname] = 1
|
||||||
|
elif itemname in self.all_equipment:
|
||||||
|
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Equipment"].append(itemname)
|
||||||
|
|
||||||
|
elif itemname in self.all_weapons:
|
||||||
|
if itemname in self.keyblade_set:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Weapon"]["Sora"].append(itemname)
|
||||||
|
elif itemname in self.staff_set:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Weapon"]["Donald"].append(itemname)
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Weapon"]["Goofy"].append(itemname)
|
||||||
|
|
||||||
|
elif itemname in self.boost_set:
|
||||||
|
if itemname in self.kh2seedsave["AmountInvo"][ItemType]["Boost"]:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Boost"][itemname] += 1
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Boost"][itemname] = 1
|
||||||
|
|
||||||
|
elif itemname in self.stat_increase_set:
|
||||||
|
|
||||||
|
if itemname in self.kh2seedsave["AmountInvo"][ItemType]["StatIncrease"]:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["StatIncrease"][itemname] += 1
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["StatIncrease"][itemname] = 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
if itemname in self.kh2seedsave["AmountInvo"][ItemType]["Amount"]:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Amount"][itemname] += 1
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["AmountInvo"][ItemType]["Amount"][itemname] = 1
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Line 398")
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
def run_gui(self):
|
||||||
|
"""Import kivy UI system and start running it as self.ui_task."""
|
||||||
|
from kvui import GameManager
|
||||||
|
|
||||||
|
class KH2Manager(GameManager):
|
||||||
|
logging_pairs = [
|
||||||
|
("Client", "Archipelago")
|
||||||
|
]
|
||||||
|
base_title = "Archipelago KH2 Client"
|
||||||
|
|
||||||
|
self.ui = KH2Manager(self)
|
||||||
|
self.ui_task = asyncio.create_task(self.ui.async_run(), name="UI")
|
||||||
|
|
||||||
|
async def IsInShop(self, sellable, master_boost):
|
||||||
|
# journal = 0x741230 shop = 0x741320
|
||||||
|
# if journal=-1 and shop = 5 then in shop
|
||||||
|
# if journam !=-1 and shop = 10 then journal
|
||||||
|
journal = self.kh2.read_short(self.kh2.base_address + 0x741230)
|
||||||
|
shop = self.kh2.read_short(self.kh2.base_address + 0x741320)
|
||||||
|
if (journal == -1 and shop == 5) or (journal != -1 and shop == 10):
|
||||||
|
# print("your in the shop")
|
||||||
|
sellable_dict = {}
|
||||||
|
for itemName in sellable:
|
||||||
|
itemdata = self.item_name_to_data[itemName]
|
||||||
|
amount = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + itemdata.memaddr, 1), "big")
|
||||||
|
sellable_dict[itemName] = amount
|
||||||
|
while (journal == -1 and shop == 5) or (journal != -1 and shop == 10):
|
||||||
|
journal = self.kh2.read_short(self.kh2.base_address + 0x741230)
|
||||||
|
shop = self.kh2.read_short(self.kh2.base_address + 0x741320)
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
|
for item, amount in sellable_dict.items():
|
||||||
|
itemdata = self.item_name_to_data[item]
|
||||||
|
afterShop = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + itemdata.memaddr, 1), "big")
|
||||||
|
if afterShop < amount:
|
||||||
|
if item in master_boost:
|
||||||
|
self.kh2seedsave["SoldBoosts"][item] += (amount - afterShop)
|
||||||
|
else:
|
||||||
|
self.kh2seedsave["SoldEquipment"].append(item)
|
||||||
|
|
||||||
|
async def verifyItems(self):
|
||||||
|
try:
|
||||||
|
local_amount = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Amount"].keys())
|
||||||
|
server_amount = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Amount"].keys())
|
||||||
|
master_amount = local_amount | server_amount
|
||||||
|
|
||||||
|
local_ability = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Ability"].keys())
|
||||||
|
server_ability = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Ability"].keys())
|
||||||
|
master_ability = local_ability | server_ability
|
||||||
|
|
||||||
|
local_bitmask = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Bitmask"])
|
||||||
|
server_bitmask = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Bitmask"])
|
||||||
|
master_bitmask = local_bitmask | server_bitmask
|
||||||
|
|
||||||
|
local_keyblade = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Weapon"]["Sora"])
|
||||||
|
local_staff = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Weapon"]["Donald"])
|
||||||
|
local_shield = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Weapon"]["Goofy"])
|
||||||
|
|
||||||
|
server_keyblade = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Weapon"]["Sora"])
|
||||||
|
server_staff = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Weapon"]["Donald"])
|
||||||
|
server_shield = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Weapon"]["Goofy"])
|
||||||
|
|
||||||
|
master_keyblade = local_keyblade | server_keyblade
|
||||||
|
master_staff = local_staff | server_staff
|
||||||
|
master_shield = local_shield | server_shield
|
||||||
|
|
||||||
|
local_equipment = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Equipment"])
|
||||||
|
server_equipment = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Equipment"])
|
||||||
|
master_equipment = local_equipment | server_equipment
|
||||||
|
|
||||||
|
local_magic = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Magic"].keys())
|
||||||
|
server_magic = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Magic"].keys())
|
||||||
|
master_magic = local_magic | server_magic
|
||||||
|
|
||||||
|
local_stat = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["StatIncrease"].keys())
|
||||||
|
server_stat = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["StatIncrease"].keys())
|
||||||
|
master_stat = local_stat | server_stat
|
||||||
|
|
||||||
|
local_boost = set(self.kh2seedsave["AmountInvo"]["LocalItems"]["Boost"].keys())
|
||||||
|
server_boost = set(self.kh2seedsave["AmountInvo"]["ServerItems"]["Boost"].keys())
|
||||||
|
master_boost = local_boost | server_boost
|
||||||
|
|
||||||
|
master_sell = master_equipment | master_staff | master_shield | master_boost
|
||||||
|
await asyncio.create_task(self.IsInShop(master_sell, master_boost))
|
||||||
|
for itemName in master_amount:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
amountOfItems = 0
|
||||||
|
if itemName in local_amount:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["LocalItems"]["Amount"][itemName]
|
||||||
|
if itemName in server_amount:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["ServerItems"]["Amount"][itemName]
|
||||||
|
|
||||||
|
if itemName == "Torn Page":
|
||||||
|
# Torn Pages are handled differently because they can be consumed.
|
||||||
|
# Will check the progression in 100 acre and - the amount of visits
|
||||||
|
# amountofitems-amount of visits done
|
||||||
|
for location, data in tornPageLocks.items():
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + data.addrObtained, 1),
|
||||||
|
"big") & 0x1 << data.bitIndex > 0:
|
||||||
|
amountOfItems -= 1
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != amountOfItems and amountOfItems >= 0:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
amountOfItems.to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_keyblade:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
# if the inventory slot for that keyblade is less than the amount they should have
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != 1 and int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + 0x1CFF, 1),
|
||||||
|
"big") != 13:
|
||||||
|
# Checking form anchors for the keyblade
|
||||||
|
if self.kh2.read_short(self.kh2.base_address + self.Save + 0x24F0) == itemData.kh2id \
|
||||||
|
or self.kh2.read_short(self.kh2.base_address + self.Save + 0x32F4) == itemData.kh2id \
|
||||||
|
or self.kh2.read_short(self.kh2.base_address + self.Save + 0x339C) == itemData.kh2id \
|
||||||
|
or self.kh2.read_short(self.kh2.base_address + self.Save + 0x33D4) == itemData.kh2id:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(0).to_bytes(1, 'big'), 1)
|
||||||
|
else:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(1).to_bytes(1, 'big'), 1)
|
||||||
|
for itemName in master_staff:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != 1 \
|
||||||
|
and self.kh2.read_short(self.kh2.base_address + self.Save + 0x2604) != itemData.kh2id \
|
||||||
|
and itemName not in self.kh2seedsave["SoldEquipment"]:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(1).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_shield:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != 1 \
|
||||||
|
and self.kh2.read_short(self.kh2.base_address + self.Save + 0x2718) != itemData.kh2id \
|
||||||
|
and itemName not in self.kh2seedsave["SoldEquipment"]:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(1).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_ability:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
ability_slot = []
|
||||||
|
if itemName in local_ability:
|
||||||
|
ability_slot += self.kh2seedsave["AmountInvo"]["LocalItems"]["Ability"][itemName]
|
||||||
|
if itemName in server_ability:
|
||||||
|
ability_slot += self.kh2seedsave["AmountInvo"]["ServerItems"]["Ability"][itemName]
|
||||||
|
for slot in ability_slot:
|
||||||
|
current = self.kh2.read_short(self.kh2.base_address + self.Save + slot)
|
||||||
|
ability = current & 0x0FFF
|
||||||
|
if ability | 0x8000 != (0x8000 + itemData.memaddr):
|
||||||
|
if current - 0x8000 > 0:
|
||||||
|
self.kh2.write_short(self.kh2.base_address + self.Save + slot, (0x8000 + itemData.memaddr))
|
||||||
|
else:
|
||||||
|
self.kh2.write_short(self.kh2.base_address + self.Save + slot, itemData.memaddr)
|
||||||
|
# removes the duped ability if client gave faster than the game.
|
||||||
|
for charInvo in {"SoraInvo", "DonaldInvo", "GoofyInvo"}:
|
||||||
|
if self.kh2.read_short(self.kh2.base_address + self.Save + self.kh2seedsave[charInvo][1]) != 0 and \
|
||||||
|
self.kh2seedsave[charInvo][1] + 2 < self.kh2seedsave[charInvo][0]:
|
||||||
|
self.kh2.write_short(self.kh2.base_address + self.Save + self.kh2seedsave[charInvo][1], 0)
|
||||||
|
# remove the dummy level 1 growths if they are in these invo slots.
|
||||||
|
for inventorySlot in {0x25CE, 0x25D0, 0x25D2, 0x25D4, 0x25D6, 0x25D8}:
|
||||||
|
current = self.kh2.read_short(self.kh2.base_address + self.Save + inventorySlot)
|
||||||
|
ability = current & 0x0FFF
|
||||||
|
if 0x05E <= ability <= 0x06D:
|
||||||
|
self.kh2.write_short(self.kh2.base_address + self.Save + inventorySlot, 0)
|
||||||
|
|
||||||
|
for itemName in self.master_growth:
|
||||||
|
growthLevel = self.kh2seedsave["AmountInvo"]["ServerItems"]["Growth"][itemName] \
|
||||||
|
+ self.kh2seedsave["AmountInvo"]["LocalItems"]["Growth"][itemName]
|
||||||
|
if growthLevel > 0:
|
||||||
|
slot = self.growth_values_dict[itemName][2]
|
||||||
|
min_growth = self.growth_values_dict[itemName][0]
|
||||||
|
max_growth = self.growth_values_dict[itemName][1]
|
||||||
|
if growthLevel > 4:
|
||||||
|
growthLevel = 4
|
||||||
|
current_growth_level = self.kh2.read_short(self.kh2.base_address + self.Save + slot)
|
||||||
|
ability = current_growth_level & 0x0FFF
|
||||||
|
# if the player should be getting a growth ability
|
||||||
|
if ability | 0x8000 != 0x8000 + min_growth - 1 + growthLevel:
|
||||||
|
# if it should be level one of that growth
|
||||||
|
if 0x8000 + min_growth - 1 + growthLevel <= 0x8000 + min_growth or ability < min_growth:
|
||||||
|
self.kh2.write_short(self.kh2.base_address + self.Save + slot, min_growth)
|
||||||
|
# if it is already in the inventory
|
||||||
|
elif ability | 0x8000 < (0x8000 + max_growth):
|
||||||
|
self.kh2.write_short(self.kh2.base_address + self.Save + slot, current_growth_level + 1)
|
||||||
|
|
||||||
|
for itemName in master_bitmask:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
itemMemory = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1), "big")
|
||||||
|
if (int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") & 0x1 << itemData.bitmask) == 0:
|
||||||
|
# when getting a form anti points should be reset to 0 but bit-shift doesn't trigger the game.
|
||||||
|
if itemName in {"Valor Form", "Wisdom Form", "Limit Form", "Master Form", "Final Form"}:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + 0x3410,
|
||||||
|
(0).to_bytes(1, 'big'), 1)
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(itemMemory | 0x01 << itemData.bitmask).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_equipment:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
isThere = False
|
||||||
|
if itemName in self.accessories_set:
|
||||||
|
Equipment_Anchor_List = self.Equipment_Anchor_Dict["Accessories"]
|
||||||
|
else:
|
||||||
|
Equipment_Anchor_List = self.Equipment_Anchor_Dict["Armor"]
|
||||||
|
# Checking form anchors for the equipment
|
||||||
|
for slot in Equipment_Anchor_List:
|
||||||
|
if self.kh2.read_short(self.kh2.base_address + self.Save + slot) == itemData.kh2id:
|
||||||
|
isThere = True
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != 0:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(0).to_bytes(1, 'big'), 1)
|
||||||
|
break
|
||||||
|
if not isThere and itemName not in self.kh2seedsave["SoldEquipment"]:
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != 1:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(1).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_magic:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
amountOfItems = 0
|
||||||
|
if itemName in local_magic:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["LocalItems"]["Magic"][itemName]
|
||||||
|
if itemName in server_magic:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["ServerItems"]["Magic"][itemName]
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != amountOfItems \
|
||||||
|
and int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + 0x741320, 1), "big") in {10, 8}:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
amountOfItems.to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_stat:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
amountOfItems = 0
|
||||||
|
if itemName in local_stat:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["LocalItems"]["StatIncrease"][itemName]
|
||||||
|
if itemName in server_stat:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["ServerItems"]["StatIncrease"][itemName]
|
||||||
|
|
||||||
|
# 0x130293 is Crit_1's location id for touching the computer
|
||||||
|
if int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big") != amountOfItems \
|
||||||
|
and int.from_bytes(self.kh2.read_bytes(self.kh2.base_address + self.Slot1 + 0x1B2, 1),
|
||||||
|
"big") >= 5 and int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + 0x23DF, 1),
|
||||||
|
"big") > 0:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
amountOfItems.to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
for itemName in master_boost:
|
||||||
|
itemData = self.item_name_to_data[itemName]
|
||||||
|
amountOfItems = 0
|
||||||
|
if itemName in local_boost:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["LocalItems"]["Boost"][itemName]
|
||||||
|
if itemName in server_boost:
|
||||||
|
amountOfItems += self.kh2seedsave["AmountInvo"]["ServerItems"]["Boost"][itemName]
|
||||||
|
amountOfBoostsInInvo = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + itemData.memaddr, 1),
|
||||||
|
"big")
|
||||||
|
amountOfUsedBoosts = int.from_bytes(
|
||||||
|
self.kh2.read_bytes(self.kh2.base_address + self.Save + self.boost_to_anchor_dict[itemName], 1),
|
||||||
|
"big")
|
||||||
|
# Ap Boots start at +50 for some reason
|
||||||
|
if itemName == "AP Boost":
|
||||||
|
amountOfUsedBoosts -= 50
|
||||||
|
totalBoosts = (amountOfBoostsInInvo + amountOfUsedBoosts)
|
||||||
|
if totalBoosts <= amountOfItems - self.kh2seedsave["SoldBoosts"][
|
||||||
|
itemName] and amountOfBoostsInInvo < 255:
|
||||||
|
self.kh2.write_bytes(self.kh2.base_address + self.Save + itemData.memaddr,
|
||||||
|
(amountOfBoostsInInvo + 1).to_bytes(1, 'big'), 1)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.info("Line 573")
|
||||||
|
if self.kh2connected:
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
self.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
|
||||||
|
|
||||||
|
def finishedGame(ctx: KH2Context, message):
|
||||||
|
if ctx.kh2slotdata['FinalXemnas'] == 1:
|
||||||
|
if 0x1301ED in message[0]["locations"]:
|
||||||
|
ctx.finalxemnas = True
|
||||||
|
# three proofs
|
||||||
|
if ctx.kh2slotdata['Goal'] == 0:
|
||||||
|
if int.from_bytes(ctx.kh2.read_bytes(ctx.kh2.base_address + ctx.Save + 0x36B2, 1), "big") > 0 \
|
||||||
|
and int.from_bytes(ctx.kh2.read_bytes(ctx.kh2.base_address + ctx.Save + 0x36B3, 1), "big") > 0 \
|
||||||
|
and int.from_bytes(ctx.kh2.read_bytes(ctx.kh2.base_address + ctx.Save + 0x36B4, 1), "big") > 0:
|
||||||
|
if ctx.kh2slotdata['FinalXemnas'] == 1:
|
||||||
|
if ctx.finalxemnas:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
elif ctx.kh2slotdata['Goal'] == 1:
|
||||||
|
if int.from_bytes(ctx.kh2.read_bytes(ctx.kh2.base_address + ctx.Save + 0x3641, 1), "big") >= \
|
||||||
|
ctx.kh2slotdata['LuckyEmblemsRequired']:
|
||||||
|
ctx.kh2.write_bytes(ctx.kh2.base_address + ctx.Save + 0x36B2, (1).to_bytes(1, 'big'), 1)
|
||||||
|
ctx.kh2.write_bytes(ctx.kh2.base_address + ctx.Save + 0x36B3, (1).to_bytes(1, 'big'), 1)
|
||||||
|
ctx.kh2.write_bytes(ctx.kh2.base_address + ctx.Save + 0x36B4, (1).to_bytes(1, 'big'), 1)
|
||||||
|
if ctx.kh2slotdata['FinalXemnas'] == 1:
|
||||||
|
if ctx.finalxemnas:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
elif ctx.kh2slotdata['Goal'] == 2:
|
||||||
|
for boss in ctx.kh2slotdata["hitlist"]:
|
||||||
|
if boss in message[0]["locations"]:
|
||||||
|
ctx.amountOfPieces += 1
|
||||||
|
if ctx.amountOfPieces >= ctx.kh2slotdata["BountyRequired"]:
|
||||||
|
ctx.kh2.write_bytes(ctx.kh2.base_address + ctx.Save + 0x36B2, (1).to_bytes(1, 'big'), 1)
|
||||||
|
ctx.kh2.write_bytes(ctx.kh2.base_address + ctx.Save + 0x36B3, (1).to_bytes(1, 'big'), 1)
|
||||||
|
ctx.kh2.write_bytes(ctx.kh2.base_address + ctx.Save + 0x36B4, (1).to_bytes(1, 'big'), 1)
|
||||||
|
if ctx.kh2slotdata['FinalXemnas'] == 1:
|
||||||
|
if ctx.finalxemnas:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
async def kh2_watcher(ctx: KH2Context):
|
||||||
|
while not ctx.exit_event.is_set():
|
||||||
|
try:
|
||||||
|
if ctx.kh2connected and ctx.serverconneced:
|
||||||
|
ctx.sending = []
|
||||||
|
await asyncio.create_task(ctx.checkWorldLocations())
|
||||||
|
await asyncio.create_task(ctx.checkLevels())
|
||||||
|
await asyncio.create_task(ctx.checkSlots())
|
||||||
|
await asyncio.create_task(ctx.verifyChests())
|
||||||
|
await asyncio.create_task(ctx.verifyItems())
|
||||||
|
await asyncio.create_task(ctx.verifyLevel())
|
||||||
|
message = [{"cmd": 'LocationChecks', "locations": ctx.sending}]
|
||||||
|
if finishedGame(ctx, message):
|
||||||
|
await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}])
|
||||||
|
ctx.finished_game = True
|
||||||
|
location_ids = []
|
||||||
|
location_ids = [location for location in message[0]["locations"] if location not in location_ids]
|
||||||
|
for location in location_ids:
|
||||||
|
if location not in ctx.locations_checked:
|
||||||
|
ctx.locations_checked.add(location)
|
||||||
|
ctx.kh2seedsave["LocationsChecked"].append(location)
|
||||||
|
if location in ctx.kh2LocalItems:
|
||||||
|
item = ctx.kh2slotdata["LocalItems"][str(location)]
|
||||||
|
await asyncio.create_task(ctx.give_item(item, "LocalItems"))
|
||||||
|
await ctx.send_msgs(message)
|
||||||
|
elif not ctx.kh2connected and ctx.serverconneced:
|
||||||
|
logger.info("Game is not open. Disconnecting from Server.")
|
||||||
|
await ctx.disconnect()
|
||||||
|
except Exception as e:
|
||||||
|
logger.info("Line 661")
|
||||||
|
if ctx.kh2connected:
|
||||||
|
logger.info("Connection Lost.")
|
||||||
|
ctx.kh2connected = False
|
||||||
|
logger.info(e)
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
async def main(args):
|
||||||
|
ctx = KH2Context(args.connect, args.password)
|
||||||
|
ctx.server_task = asyncio.create_task(server_loop(ctx), name="server loop")
|
||||||
|
if gui_enabled:
|
||||||
|
ctx.run_gui()
|
||||||
|
ctx.run_cli()
|
||||||
|
progression_watcher = asyncio.create_task(
|
||||||
|
kh2_watcher(ctx), name="KH2ProgressionWatcher")
|
||||||
|
|
||||||
|
await ctx.exit_event.wait()
|
||||||
|
ctx.server_address = None
|
||||||
|
|
||||||
|
await progression_watcher
|
||||||
|
|
||||||
|
await ctx.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
parser = get_base_parser(description="KH2 Client, for text interfacing.")
|
||||||
|
|
||||||
|
args, rest = parser.parse_known_args()
|
||||||
|
colorama.init()
|
||||||
|
asyncio.run(main(args))
|
||||||
|
colorama.deinit()
|
||||||
175
Launcher.py
@@ -11,13 +11,17 @@ Scroll down to components= to add components to the launcher as well as setup.py
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import itertools
|
import itertools
|
||||||
|
import multiprocessing
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from enum import Enum, auto
|
import webbrowser
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
from shutil import which
|
from shutil import which
|
||||||
from typing import Iterable, Sequence, Callable, Union, Optional
|
from typing import Sequence, Union, Optional
|
||||||
|
|
||||||
|
import Utils
|
||||||
|
from worlds.LauncherComponents import Component, components, Type, SuffixIdentifier, icon_paths
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import ModuleUpdate
|
import ModuleUpdate
|
||||||
@@ -37,7 +41,6 @@ def open_host_yaml():
|
|||||||
exe = which("open")
|
exe = which("open")
|
||||||
subprocess.Popen([exe, file])
|
subprocess.Popen([exe, file])
|
||||||
else:
|
else:
|
||||||
import webbrowser
|
|
||||||
webbrowser.open(file)
|
webbrowser.open(file)
|
||||||
|
|
||||||
|
|
||||||
@@ -57,117 +60,38 @@ def open_patch():
|
|||||||
launch([*get_exe(component), file], component.cli)
|
launch([*get_exe(component), file], component.cli)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_yamls():
|
||||||
|
from Options import generate_yaml_templates
|
||||||
|
|
||||||
|
target = Utils.user_path("Players", "Templates")
|
||||||
|
generate_yaml_templates(target, False)
|
||||||
|
open_folder(target)
|
||||||
|
|
||||||
|
|
||||||
def browse_files():
|
def browse_files():
|
||||||
file = user_path()
|
open_folder(user_path())
|
||||||
|
|
||||||
|
|
||||||
|
def open_folder(folder_path):
|
||||||
if is_linux:
|
if is_linux:
|
||||||
exe = which('xdg-open') or which('gnome-open') or which('kde-open')
|
exe = which('xdg-open') or which('gnome-open') or which('kde-open')
|
||||||
subprocess.Popen([exe, file])
|
subprocess.Popen([exe, folder_path])
|
||||||
elif is_macos:
|
elif is_macos:
|
||||||
exe = which("open")
|
exe = which("open")
|
||||||
subprocess.Popen([exe, file])
|
subprocess.Popen([exe, folder_path])
|
||||||
else:
|
else:
|
||||||
import webbrowser
|
webbrowser.open(folder_path)
|
||||||
webbrowser.open(file)
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyArgumentList
|
components.extend([
|
||||||
class Type(Enum):
|
|
||||||
TOOL = auto()
|
|
||||||
FUNC = auto() # not a real component
|
|
||||||
CLIENT = auto()
|
|
||||||
ADJUSTER = auto()
|
|
||||||
|
|
||||||
|
|
||||||
class SuffixIdentifier:
|
|
||||||
suffixes: Iterable[str]
|
|
||||||
|
|
||||||
def __init__(self, *args: str):
|
|
||||||
self.suffixes = args
|
|
||||||
|
|
||||||
def __call__(self, path: str):
|
|
||||||
if isinstance(path, str):
|
|
||||||
for suffix in self.suffixes:
|
|
||||||
if path.endswith(suffix):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Component:
|
|
||||||
display_name: str
|
|
||||||
type: Optional[Type]
|
|
||||||
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,
|
|
||||||
cli: bool = False, icon: str = 'icon', component_type: Type = None, func: Optional[Callable] = None,
|
|
||||||
file_identifier: Optional[Callable[[str], bool]] = None):
|
|
||||||
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
|
|
||||||
self.type = component_type or \
|
|
||||||
None if not display_name else \
|
|
||||||
Type.FUNC if func else \
|
|
||||||
Type.CLIENT if 'Client' in display_name else \
|
|
||||||
Type.ADJUSTER if 'Adjuster' in display_name else Type.TOOL
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
components: Iterable[Component] = (
|
|
||||||
# Launcher
|
|
||||||
Component('', 'Launcher'),
|
|
||||||
# Core
|
|
||||||
Component('Host', 'MultiServer', 'ArchipelagoServer', cli=True,
|
|
||||||
file_identifier=SuffixIdentifier('.archipelago', '.zip')),
|
|
||||||
Component('Generate', 'Generate', cli=True),
|
|
||||||
Component('Text Client', 'CommonClient', 'ArchipelagoTextClient'),
|
|
||||||
# SNI
|
|
||||||
Component('SNI Client', 'SNIClient',
|
|
||||||
file_identifier=SuffixIdentifier('.apz3', '.apm3', '.apsoe', '.aplttp', '.apsm', '.apsmz3', '.apdkc3',
|
|
||||||
'.apsmw', '.apl2ac')),
|
|
||||||
Component('LttP Adjuster', 'LttPAdjuster'),
|
|
||||||
# Factorio
|
|
||||||
Component('Factorio Client', 'FactorioClient'),
|
|
||||||
# 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'),
|
|
||||||
# Pokémon
|
|
||||||
Component('Pokemon Client', 'PokemonClient', file_identifier=SuffixIdentifier('.apred', '.apblue')),
|
|
||||||
# TLoZ
|
|
||||||
Component('Zelda 1 Client', 'Zelda1Client'),
|
|
||||||
# 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')),
|
|
||||||
# Functions
|
# Functions
|
||||||
Component('Open host.yaml', func=open_host_yaml),
|
Component("Open host.yaml", func=open_host_yaml),
|
||||||
Component('Open Patch', func=open_patch),
|
Component("Open Patch", func=open_patch),
|
||||||
Component('Browse Files', func=browse_files),
|
Component("Generate Template Settings", func=generate_yamls),
|
||||||
)
|
Component("Discord Server", icon="discord", func=lambda: webbrowser.open("https://discord.gg/8Z65BR2")),
|
||||||
icon_paths = {
|
Component("18+ Discord Server", icon="discord", func=lambda: webbrowser.open("https://discord.gg/fqvNCCRsu4")),
|
||||||
'icon': local_path('data', 'icon.ico' if is_windows else 'icon.png'),
|
Component("Browse Files", func=browse_files),
|
||||||
'mcicon': local_path('data', 'mcicon.ico')
|
])
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def identify(path: Union[None, str]):
|
def identify(path: Union[None, str]):
|
||||||
@@ -223,6 +147,8 @@ def launch(exe, in_terminal=False):
|
|||||||
|
|
||||||
def run_gui():
|
def run_gui():
|
||||||
from kvui import App, ContainerLayout, GridLayout, Button, Label
|
from kvui import App, ContainerLayout, GridLayout, Button, Label
|
||||||
|
from kivy.uix.image import AsyncImage
|
||||||
|
from kivy.uix.relativelayout import RelativeLayout
|
||||||
|
|
||||||
class Launcher(App):
|
class Launcher(App):
|
||||||
base_title: str = "Archipelago Launcher"
|
base_title: str = "Archipelago Launcher"
|
||||||
@@ -244,24 +170,44 @@ def run_gui():
|
|||||||
self.container = ContainerLayout()
|
self.container = ContainerLayout()
|
||||||
self.grid = GridLayout(cols=2)
|
self.grid = GridLayout(cols=2)
|
||||||
self.container.add_widget(self.grid)
|
self.container.add_widget(self.grid)
|
||||||
|
self.grid.add_widget(Label(text="General"))
|
||||||
|
self.grid.add_widget(Label(text="Clients"))
|
||||||
button_layout = self.grid # make buttons fill the window
|
button_layout = self.grid # make buttons fill the window
|
||||||
|
|
||||||
|
def build_button(component: Component):
|
||||||
|
"""
|
||||||
|
Builds a button widget for a given component.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
component (Component): The component associated with the button.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None. The button is added to the parent grid layout.
|
||||||
|
|
||||||
|
"""
|
||||||
|
button = Button(text=component.display_name)
|
||||||
|
button.component = component
|
||||||
|
button.bind(on_release=self.component_action)
|
||||||
|
if component.icon != "icon":
|
||||||
|
image = AsyncImage(source=icon_paths[component.icon],
|
||||||
|
size=(38, 38), size_hint=(None, 1), pos=(5, 0))
|
||||||
|
box_layout = RelativeLayout()
|
||||||
|
box_layout.add_widget(button)
|
||||||
|
box_layout.add_widget(image)
|
||||||
|
button_layout.add_widget(box_layout)
|
||||||
|
else:
|
||||||
|
button_layout.add_widget(button)
|
||||||
|
|
||||||
for (tool, client) in itertools.zip_longest(itertools.chain(
|
for (tool, client) in itertools.zip_longest(itertools.chain(
|
||||||
self._tools.items(), self._funcs.items(), self._adjusters.items()), self._clients.items()):
|
self._tools.items(), self._funcs.items(), self._adjusters.items()), self._clients.items()):
|
||||||
# column 1
|
# column 1
|
||||||
if tool:
|
if tool:
|
||||||
button = Button(text=tool[0])
|
build_button(tool[1])
|
||||||
button.component = tool[1]
|
|
||||||
button.bind(on_release=self.component_action)
|
|
||||||
button_layout.add_widget(button)
|
|
||||||
else:
|
else:
|
||||||
button_layout.add_widget(Label())
|
button_layout.add_widget(Label())
|
||||||
# column 2
|
# column 2
|
||||||
if client:
|
if client:
|
||||||
button = Button(text=client[0])
|
build_button(client[1])
|
||||||
button.component = client[1]
|
|
||||||
button.bind(on_press=self.component_action)
|
|
||||||
button_layout.add_widget(button)
|
|
||||||
else:
|
else:
|
||||||
button_layout.add_widget(Label())
|
button_layout.add_widget(Label())
|
||||||
|
|
||||||
@@ -300,6 +246,7 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init_logging('Launcher')
|
init_logging('Launcher')
|
||||||
|
multiprocessing.freeze_support()
|
||||||
parser = argparse.ArgumentParser(description='Archipelago Launcher')
|
parser = argparse.ArgumentParser(description='Archipelago Launcher')
|
||||||
parser.add_argument('Patch|Game|Component', type=str, nargs='?',
|
parser.add_argument('Patch|Game|Component', type=str, nargs='?',
|
||||||
help="Pass either a patch file, a generated game or the name of a component to run.")
|
help="Pass either a patch file, a generated game or the name of a component to run.")
|
||||||
|
|||||||
609
LinksAwakeningClient.py
Normal file
@@ -0,0 +1,609 @@
|
|||||||
|
import ModuleUpdate
|
||||||
|
ModuleUpdate.update()
|
||||||
|
|
||||||
|
import Utils
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Utils.init_logging("LinksAwakeningContext", exception_logger="Client")
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import base64
|
||||||
|
import binascii
|
||||||
|
import io
|
||||||
|
import logging
|
||||||
|
import select
|
||||||
|
import socket
|
||||||
|
import time
|
||||||
|
import typing
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
|
||||||
|
from CommonClient import (CommonContext, get_base_parser, gui_enabled, logger,
|
||||||
|
server_loop)
|
||||||
|
from NetUtils import ClientStatus
|
||||||
|
from worlds.ladx.Common import BASE_ID as LABaseID
|
||||||
|
from worlds.ladx.GpsTracker import GpsTracker
|
||||||
|
from worlds.ladx.ItemTracker import ItemTracker
|
||||||
|
from worlds.ladx.LADXR.checkMetadata import checkMetadataTable
|
||||||
|
from worlds.ladx.Locations import get_locations_to_id, meta_to_name
|
||||||
|
from worlds.ladx.Tracker import LocationTracker, MagpieBridge
|
||||||
|
|
||||||
|
class GameboyException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class RetroArchDisconnectError(GameboyException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidEmulatorStateError(GameboyException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BadRetroArchResponse(GameboyException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def magpie_logo():
|
||||||
|
from kivy.uix.image import CoreImage
|
||||||
|
binary_data = """
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAAXN
|
||||||
|
SR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA
|
||||||
|
7DAcdvqGQAAADGSURBVDhPhVLBEcIwDHOYhjHCBuXHj2OTbAL8+
|
||||||
|
MEGZIxOQ1CinOOk0Op0bmo7tlXXeR9FJMYDLOD9mwcLjQK7+hSZ
|
||||||
|
wgcWMZJOAGeGKtChNHFL0j+FZD3jSCuo0w7l03wDrWdg00C4/aW
|
||||||
|
eDEYNenuzPOfPspBnxf0kssE80vN0L8361j10P03DK4x6FHabuV
|
||||||
|
ear8fHme+b17rwSjbAXeUMLb+EVTV2QHm46MWQanmnydA98KsVS
|
||||||
|
XkV+qFpGQXrLhT/fqraQeQLuplpNH5g+WkAAAAASUVORK5CYII="""
|
||||||
|
binary_data = base64.b64decode(binary_data)
|
||||||
|
data = io.BytesIO(binary_data)
|
||||||
|
return CoreImage(data, ext="png").texture
|
||||||
|
|
||||||
|
|
||||||
|
class LAClientConstants:
|
||||||
|
# Connector version
|
||||||
|
VERSION = 0x01
|
||||||
|
#
|
||||||
|
# Memory locations of LADXR
|
||||||
|
ROMGameID = 0x0051 # 4 bytes
|
||||||
|
SlotName = 0x0134
|
||||||
|
# Unused
|
||||||
|
# ROMWorldID = 0x0055
|
||||||
|
# ROMConnectorVersion = 0x0056
|
||||||
|
# RO: We should only act if this is higher then 6, as it indicates that the game is running normally
|
||||||
|
wGameplayType = 0xDB95
|
||||||
|
# RO: Starts at 0, increases every time an item is received from the server and processed
|
||||||
|
wLinkSyncSequenceNumber = 0xDDF6
|
||||||
|
wLinkStatusBits = 0xDDF7 # RW:
|
||||||
|
# Bit0: wLinkGive* contains valid data, set from script cleared from ROM.
|
||||||
|
wLinkHealth = 0xDB5A
|
||||||
|
wLinkGiveItem = 0xDDF8 # RW
|
||||||
|
wLinkGiveItemFrom = 0xDDF9 # RW
|
||||||
|
# All of these six bytes are unused, we can repurpose
|
||||||
|
# wLinkSendItemRoomHigh = 0xDDFA # RO
|
||||||
|
# wLinkSendItemRoomLow = 0xDDFB # RO
|
||||||
|
# wLinkSendItemTarget = 0xDDFC # RO
|
||||||
|
# wLinkSendItemItem = 0xDDFD # RO
|
||||||
|
# wLinkSendShopItem = 0xDDFE # RO, which item to send (1 based, order of the shop items)
|
||||||
|
# RO, which player to send to, but it's just the X position of the NPC used, so 0x18 is player 0
|
||||||
|
# wLinkSendShopTarget = 0xDDFF
|
||||||
|
|
||||||
|
|
||||||
|
wRecvIndex = 0xDDFE # 0xDB58
|
||||||
|
wCheckAddress = 0xC0FF - 0x4
|
||||||
|
WRamCheckSize = 0x4
|
||||||
|
WRamSafetyValue = bytearray([0]*WRamCheckSize)
|
||||||
|
|
||||||
|
MinGameplayValue = 0x06
|
||||||
|
MaxGameplayValue = 0x1A
|
||||||
|
VictoryGameplayAndSub = 0x0102
|
||||||
|
|
||||||
|
|
||||||
|
class RAGameboy():
|
||||||
|
cache = []
|
||||||
|
cache_start = 0
|
||||||
|
cache_size = 0
|
||||||
|
last_cache_read = None
|
||||||
|
socket = None
|
||||||
|
|
||||||
|
def __init__(self, address, port) -> None:
|
||||||
|
self.address = address
|
||||||
|
self.port = port
|
||||||
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
assert (self.socket)
|
||||||
|
self.socket.setblocking(False)
|
||||||
|
|
||||||
|
def get_retroarch_version(self):
|
||||||
|
self.send(b'VERSION\n')
|
||||||
|
select.select([self.socket], [], [])
|
||||||
|
response_str, addr = self.socket.recvfrom(16)
|
||||||
|
return response_str.rstrip()
|
||||||
|
|
||||||
|
def get_retroarch_status(self, timeout):
|
||||||
|
self.send(b'GET_STATUS\n')
|
||||||
|
select.select([self.socket], [], [], timeout)
|
||||||
|
response_str, addr = self.socket.recvfrom(1000, )
|
||||||
|
return response_str.rstrip()
|
||||||
|
|
||||||
|
def set_cache_limits(self, cache_start, cache_size):
|
||||||
|
self.cache_start = cache_start
|
||||||
|
self.cache_size = cache_size
|
||||||
|
|
||||||
|
def send(self, b):
|
||||||
|
if type(b) is str:
|
||||||
|
b = b.encode('ascii')
|
||||||
|
self.socket.sendto(b, (self.address, self.port))
|
||||||
|
|
||||||
|
def recv(self):
|
||||||
|
select.select([self.socket], [], [])
|
||||||
|
response, _ = self.socket.recvfrom(4096)
|
||||||
|
return response
|
||||||
|
|
||||||
|
async def async_recv(self):
|
||||||
|
response = await asyncio.get_event_loop().sock_recv(self.socket, 4096)
|
||||||
|
return response
|
||||||
|
|
||||||
|
async def check_safe_gameplay(self, throw=True):
|
||||||
|
async def check_wram():
|
||||||
|
check_values = await self.async_read_memory(LAClientConstants.wCheckAddress, LAClientConstants.WRamCheckSize)
|
||||||
|
|
||||||
|
if check_values != LAClientConstants.WRamSafetyValue:
|
||||||
|
if throw:
|
||||||
|
raise InvalidEmulatorStateError()
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
if not await check_wram():
|
||||||
|
if throw:
|
||||||
|
raise InvalidEmulatorStateError()
|
||||||
|
return False
|
||||||
|
|
||||||
|
gameplay_value = await self.async_read_memory(LAClientConstants.wGameplayType)
|
||||||
|
gameplay_value = gameplay_value[0]
|
||||||
|
# In gameplay or credits
|
||||||
|
if not (LAClientConstants.MinGameplayValue <= gameplay_value <= LAClientConstants.MaxGameplayValue) and gameplay_value != 0x1:
|
||||||
|
if throw:
|
||||||
|
logger.info("invalid emu state")
|
||||||
|
raise InvalidEmulatorStateError()
|
||||||
|
return False
|
||||||
|
if not await check_wram():
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
# We're sadly unable to update the whole cache at once
|
||||||
|
# as RetroArch only gives back some number of bytes at a time
|
||||||
|
# So instead read as big as chunks at a time as we can manage
|
||||||
|
async def update_cache(self):
|
||||||
|
# First read the safety address - if it's invalid, bail
|
||||||
|
self.cache = []
|
||||||
|
|
||||||
|
if not await self.check_safe_gameplay():
|
||||||
|
return
|
||||||
|
|
||||||
|
cache = []
|
||||||
|
remaining_size = self.cache_size
|
||||||
|
while remaining_size:
|
||||||
|
block = await self.async_read_memory(self.cache_start + len(cache), remaining_size)
|
||||||
|
remaining_size -= len(block)
|
||||||
|
cache += block
|
||||||
|
|
||||||
|
if not await self.check_safe_gameplay():
|
||||||
|
return
|
||||||
|
|
||||||
|
self.cache = cache
|
||||||
|
self.last_cache_read = time.time()
|
||||||
|
|
||||||
|
async def read_memory_cache(self, addresses):
|
||||||
|
# TODO: can we just update once per frame?
|
||||||
|
if not self.last_cache_read or self.last_cache_read + 0.1 < time.time():
|
||||||
|
await self.update_cache()
|
||||||
|
if not self.cache:
|
||||||
|
return None
|
||||||
|
assert (len(self.cache) == self.cache_size)
|
||||||
|
for address in addresses:
|
||||||
|
assert self.cache_start <= address <= self.cache_start + self.cache_size
|
||||||
|
r = {address: self.cache[address - self.cache_start]
|
||||||
|
for address in addresses}
|
||||||
|
return r
|
||||||
|
|
||||||
|
async def async_read_memory_safe(self, address, size=1):
|
||||||
|
# whenever we do a read for a check, we need to make sure that we aren't reading
|
||||||
|
# garbage memory values - we also need to protect against reading a value, then the emulator resetting
|
||||||
|
#
|
||||||
|
# ...actually, we probably _only_ need the post check
|
||||||
|
|
||||||
|
# Check before read
|
||||||
|
if not await self.check_safe_gameplay():
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Do read
|
||||||
|
r = await self.async_read_memory(address, size)
|
||||||
|
|
||||||
|
# Check after read
|
||||||
|
if not await self.check_safe_gameplay():
|
||||||
|
return None
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
|
def read_memory(self, address, size=1):
|
||||||
|
command = "READ_CORE_MEMORY"
|
||||||
|
|
||||||
|
self.send(f'{command} {hex(address)} {size}\n')
|
||||||
|
response = self.recv()
|
||||||
|
|
||||||
|
splits = response.decode().split(" ", 2)
|
||||||
|
|
||||||
|
assert (splits[0] == command)
|
||||||
|
# Ignore the address for now
|
||||||
|
|
||||||
|
# TODO: transform to bytes
|
||||||
|
if splits[2][:2] == "-1" or splits[0] != "READ_CORE_MEMORY":
|
||||||
|
raise BadRetroArchResponse()
|
||||||
|
return bytearray.fromhex(splits[2])
|
||||||
|
|
||||||
|
async def async_read_memory(self, address, size=1):
|
||||||
|
command = "READ_CORE_MEMORY"
|
||||||
|
|
||||||
|
self.send(f'{command} {hex(address)} {size}\n')
|
||||||
|
response = await self.async_recv()
|
||||||
|
response = response[:-1]
|
||||||
|
splits = response.decode().split(" ", 2)
|
||||||
|
|
||||||
|
assert (splits[0] == command)
|
||||||
|
# Ignore the address for now
|
||||||
|
|
||||||
|
# TODO: transform to bytes
|
||||||
|
return bytearray.fromhex(splits[2])
|
||||||
|
|
||||||
|
def write_memory(self, address, bytes):
|
||||||
|
command = "WRITE_CORE_MEMORY"
|
||||||
|
|
||||||
|
self.send(f'{command} {hex(address)} {" ".join(hex(b) for b in bytes)}')
|
||||||
|
select.select([self.socket], [], [])
|
||||||
|
response, _ = self.socket.recvfrom(4096)
|
||||||
|
|
||||||
|
splits = response.decode().split(" ", 3)
|
||||||
|
|
||||||
|
assert (splits[0] == command)
|
||||||
|
|
||||||
|
if splits[2] == "-1":
|
||||||
|
logger.info(splits[3])
|
||||||
|
|
||||||
|
|
||||||
|
class LinksAwakeningClient():
|
||||||
|
socket = None
|
||||||
|
gameboy = None
|
||||||
|
tracker = None
|
||||||
|
auth = None
|
||||||
|
game_crc = None
|
||||||
|
pending_deathlink = False
|
||||||
|
deathlink_debounce = True
|
||||||
|
recvd_checks = {}
|
||||||
|
|
||||||
|
def msg(self, m):
|
||||||
|
logger.info(m)
|
||||||
|
s = f"SHOW_MSG {m}\n"
|
||||||
|
self.gameboy.send(s)
|
||||||
|
|
||||||
|
def __init__(self, retroarch_address="127.0.0.1", retroarch_port=55355):
|
||||||
|
self.gameboy = RAGameboy(retroarch_address, retroarch_port)
|
||||||
|
|
||||||
|
async def wait_for_retroarch_connection(self):
|
||||||
|
logger.info("Waiting on connection to Retroarch...")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
version = self.gameboy.get_retroarch_version()
|
||||||
|
NO_CONTENT = b"GET_STATUS CONTENTLESS"
|
||||||
|
status = NO_CONTENT
|
||||||
|
core_type = None
|
||||||
|
GAME_BOY = b"game_boy"
|
||||||
|
while status == NO_CONTENT or core_type != GAME_BOY:
|
||||||
|
try:
|
||||||
|
status = self.gameboy.get_retroarch_status(0.1)
|
||||||
|
if status.count(b" ") < 2:
|
||||||
|
await asyncio.sleep(1.0)
|
||||||
|
continue
|
||||||
|
|
||||||
|
GET_STATUS, PLAYING, info = status.split(b" ", 2)
|
||||||
|
if status.count(b",") < 2:
|
||||||
|
await asyncio.sleep(1.0)
|
||||||
|
continue
|
||||||
|
core_type, rom_name, self.game_crc = info.split(b",", 2)
|
||||||
|
if core_type != GAME_BOY:
|
||||||
|
logger.info(
|
||||||
|
f"Core type should be '{GAME_BOY}', found {core_type} instead - wrong type of ROM?")
|
||||||
|
await asyncio.sleep(1.0)
|
||||||
|
continue
|
||||||
|
except (BlockingIOError, TimeoutError) as e:
|
||||||
|
await asyncio.sleep(0.1)
|
||||||
|
pass
|
||||||
|
logger.info(f"Connected to Retroarch {version} {info}")
|
||||||
|
self.gameboy.read_memory(0x1000)
|
||||||
|
return
|
||||||
|
except ConnectionResetError:
|
||||||
|
await asyncio.sleep(1.0)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def reset_auth(self):
|
||||||
|
auth = binascii.hexlify(self.gameboy.read_memory(0x0134, 12)).decode()
|
||||||
|
|
||||||
|
if self.auth:
|
||||||
|
assert (auth == self.auth)
|
||||||
|
|
||||||
|
self.auth = auth
|
||||||
|
|
||||||
|
async def wait_and_init_tracker(self):
|
||||||
|
await self.wait_for_game_ready()
|
||||||
|
self.tracker = LocationTracker(self.gameboy)
|
||||||
|
self.item_tracker = ItemTracker(self.gameboy)
|
||||||
|
self.gps_tracker = GpsTracker(self.gameboy)
|
||||||
|
|
||||||
|
async def recved_item_from_ap(self, item_id, from_player, next_index):
|
||||||
|
# Don't allow getting an item until you've got your first check
|
||||||
|
if not self.tracker.has_start_item():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Spin until we either:
|
||||||
|
# get an exception from a bad read (emu shut down or reset)
|
||||||
|
# beat the game
|
||||||
|
# the client handles the last pending item
|
||||||
|
status = (await self.gameboy.async_read_memory_safe(LAClientConstants.wLinkStatusBits))[0]
|
||||||
|
while not (await self.is_victory()) and status & 1 == 1:
|
||||||
|
time.sleep(0.1)
|
||||||
|
status = (await self.gameboy.async_read_memory_safe(LAClientConstants.wLinkStatusBits))[0]
|
||||||
|
|
||||||
|
item_id -= LABaseID
|
||||||
|
# The player name table only goes up to 100, so don't go past that
|
||||||
|
# Even if it didn't, the remote player _index_ byte is just a byte, so 255 max
|
||||||
|
if from_player > 100:
|
||||||
|
from_player = 100
|
||||||
|
|
||||||
|
next_index += 1
|
||||||
|
self.gameboy.write_memory(LAClientConstants.wLinkGiveItem, [
|
||||||
|
item_id, from_player])
|
||||||
|
status |= 1
|
||||||
|
status = self.gameboy.write_memory(LAClientConstants.wLinkStatusBits, [status])
|
||||||
|
self.gameboy.write_memory(LAClientConstants.wRecvIndex, [next_index])
|
||||||
|
|
||||||
|
async def wait_for_game_ready(self):
|
||||||
|
logger.info("Waiting on game to be in valid state...")
|
||||||
|
while not await self.gameboy.check_safe_gameplay(throw=False):
|
||||||
|
pass
|
||||||
|
logger.info("Ready!")
|
||||||
|
last_index = 0
|
||||||
|
|
||||||
|
async def is_victory(self):
|
||||||
|
return (await self.gameboy.read_memory_cache([LAClientConstants.wGameplayType]))[LAClientConstants.wGameplayType] == 1
|
||||||
|
|
||||||
|
async def main_tick(self, item_get_cb, win_cb, deathlink_cb):
|
||||||
|
await self.tracker.readChecks(item_get_cb)
|
||||||
|
await self.item_tracker.readItems()
|
||||||
|
await self.gps_tracker.read_location()
|
||||||
|
|
||||||
|
next_index = self.gameboy.read_memory(LAClientConstants.wRecvIndex)[0]
|
||||||
|
if next_index != self.last_index:
|
||||||
|
self.last_index = next_index
|
||||||
|
# logger.info(f"Got new index {next_index}")
|
||||||
|
|
||||||
|
current_health = (await self.gameboy.read_memory_cache([LAClientConstants.wLinkHealth]))[LAClientConstants.wLinkHealth]
|
||||||
|
if self.deathlink_debounce and current_health != 0:
|
||||||
|
self.deathlink_debounce = False
|
||||||
|
elif not self.deathlink_debounce and current_health == 0:
|
||||||
|
# logger.info("YOU DIED.")
|
||||||
|
await deathlink_cb()
|
||||||
|
self.deathlink_debounce = True
|
||||||
|
|
||||||
|
if self.pending_deathlink:
|
||||||
|
logger.info("Got a deathlink")
|
||||||
|
self.gameboy.write_memory(LAClientConstants.wLinkHealth, [0])
|
||||||
|
self.pending_deathlink = False
|
||||||
|
self.deathlink_debounce = True
|
||||||
|
|
||||||
|
if await self.is_victory():
|
||||||
|
await win_cb()
|
||||||
|
|
||||||
|
recv_index = (await self.gameboy.async_read_memory_safe(LAClientConstants.wRecvIndex))[0]
|
||||||
|
|
||||||
|
# Play back one at a time
|
||||||
|
if recv_index in self.recvd_checks:
|
||||||
|
item = self.recvd_checks[recv_index]
|
||||||
|
await self.recved_item_from_ap(item.item, item.player, recv_index)
|
||||||
|
|
||||||
|
|
||||||
|
all_tasks = set()
|
||||||
|
|
||||||
|
def create_task_log_exception(awaitable) -> asyncio.Task:
|
||||||
|
async def _log_exception(awaitable):
|
||||||
|
try:
|
||||||
|
return await awaitable
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(e)
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
all_tasks.remove(task)
|
||||||
|
task = asyncio.create_task(_log_exception(awaitable))
|
||||||
|
all_tasks.add(task)
|
||||||
|
|
||||||
|
|
||||||
|
class LinksAwakeningContext(CommonContext):
|
||||||
|
tags = {"AP"}
|
||||||
|
game = "Links Awakening DX"
|
||||||
|
items_handling = 0b101
|
||||||
|
want_slot_data = True
|
||||||
|
la_task = None
|
||||||
|
client = None
|
||||||
|
# TODO: does this need to re-read on reset?
|
||||||
|
found_checks = []
|
||||||
|
last_resend = time.time()
|
||||||
|
|
||||||
|
magpie = MagpieBridge()
|
||||||
|
magpie_task = None
|
||||||
|
won = False
|
||||||
|
|
||||||
|
def __init__(self, server_address: typing.Optional[str], password: typing.Optional[str]) -> None:
|
||||||
|
self.client = LinksAwakeningClient()
|
||||||
|
super().__init__(server_address, password)
|
||||||
|
|
||||||
|
def run_gui(self) -> None:
|
||||||
|
import webbrowser
|
||||||
|
import kvui
|
||||||
|
from kvui import Button, GameManager
|
||||||
|
from kivy.uix.image import Image
|
||||||
|
|
||||||
|
class LADXManager(GameManager):
|
||||||
|
logging_pairs = [
|
||||||
|
("Client", "Archipelago"),
|
||||||
|
("Tracker", "Tracker"),
|
||||||
|
]
|
||||||
|
base_title = "Archipelago Links Awakening DX Client"
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
b = super().build()
|
||||||
|
|
||||||
|
button = Button(text="", size=(30, 30), size_hint_x=None,
|
||||||
|
on_press=lambda _: webbrowser.open('https://magpietracker.us/?enable_autotracker=1'))
|
||||||
|
image = Image(size=(16, 16), texture=magpie_logo())
|
||||||
|
button.add_widget(image)
|
||||||
|
|
||||||
|
def set_center(_, center):
|
||||||
|
image.center = center
|
||||||
|
button.bind(center=set_center)
|
||||||
|
|
||||||
|
self.connect_layout.add_widget(button)
|
||||||
|
return b
|
||||||
|
|
||||||
|
self.ui = LADXManager(self)
|
||||||
|
self.ui_task = asyncio.create_task(self.ui.async_run(), name="UI")
|
||||||
|
|
||||||
|
async def send_checks(self):
|
||||||
|
message = [{"cmd": 'LocationChecks', "locations": self.found_checks}]
|
||||||
|
await self.send_msgs(message)
|
||||||
|
|
||||||
|
ENABLE_DEATHLINK = False
|
||||||
|
async def send_deathlink(self):
|
||||||
|
if self.ENABLE_DEATHLINK:
|
||||||
|
message = [{"cmd": 'Deathlink',
|
||||||
|
'time': time.time(),
|
||||||
|
'cause': 'Had a nightmare',
|
||||||
|
# 'source': self.slot_info[self.slot].name,
|
||||||
|
}]
|
||||||
|
await self.send_msgs(message)
|
||||||
|
|
||||||
|
async def send_victory(self):
|
||||||
|
if not self.won:
|
||||||
|
message = [{"cmd": "StatusUpdate",
|
||||||
|
"status": ClientStatus.CLIENT_GOAL}]
|
||||||
|
logger.info("victory!")
|
||||||
|
await self.send_msgs(message)
|
||||||
|
self.won = True
|
||||||
|
|
||||||
|
async def on_deathlink(self, data: typing.Dict[str, typing.Any]) -> None:
|
||||||
|
if self.ENABLE_DEATHLINK:
|
||||||
|
self.client.pending_deathlink = True
|
||||||
|
|
||||||
|
def new_checks(self, item_ids, ladxr_ids):
|
||||||
|
self.found_checks += item_ids
|
||||||
|
create_task_log_exception(self.send_checks())
|
||||||
|
create_task_log_exception(self.magpie.send_new_checks(ladxr_ids))
|
||||||
|
|
||||||
|
async def server_auth(self, password_requested: bool = False):
|
||||||
|
if password_requested and not self.password:
|
||||||
|
await super(LinksAwakeningContext, self).server_auth(password_requested)
|
||||||
|
self.auth = self.client.auth
|
||||||
|
await self.get_username()
|
||||||
|
await self.send_connect()
|
||||||
|
|
||||||
|
def on_package(self, cmd: str, args: dict):
|
||||||
|
if cmd == "Connected":
|
||||||
|
self.game = self.slot_info[self.slot].game
|
||||||
|
# TODO - use watcher_event
|
||||||
|
if cmd == "ReceivedItems":
|
||||||
|
for index, item in enumerate(args["items"], args["index"]):
|
||||||
|
self.client.recvd_checks[index] = item
|
||||||
|
|
||||||
|
item_id_lookup = get_locations_to_id()
|
||||||
|
|
||||||
|
async def run_game_loop(self):
|
||||||
|
def on_item_get(ladxr_checks):
|
||||||
|
checks = [self.item_id_lookup[meta_to_name(
|
||||||
|
checkMetadataTable[check.id])] for check in ladxr_checks]
|
||||||
|
self.new_checks(checks, [check.id for check in ladxr_checks])
|
||||||
|
|
||||||
|
async def victory():
|
||||||
|
await self.send_victory()
|
||||||
|
|
||||||
|
async def deathlink():
|
||||||
|
await self.send_deathlink()
|
||||||
|
|
||||||
|
self.magpie_task = asyncio.create_task(self.magpie.serve())
|
||||||
|
|
||||||
|
# yield to allow UI to start
|
||||||
|
await asyncio.sleep(0)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# TODO: cancel all client tasks
|
||||||
|
logger.info("(Re)Starting game loop")
|
||||||
|
self.found_checks.clear()
|
||||||
|
await self.client.wait_for_retroarch_connection()
|
||||||
|
self.client.reset_auth()
|
||||||
|
await self.client.wait_and_init_tracker()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
await self.client.main_tick(on_item_get, victory, deathlink)
|
||||||
|
await asyncio.sleep(0.1)
|
||||||
|
now = time.time()
|
||||||
|
if self.last_resend + 5.0 < now:
|
||||||
|
self.last_resend = now
|
||||||
|
await self.send_checks()
|
||||||
|
self.magpie.set_checks(self.client.tracker.all_checks)
|
||||||
|
await self.magpie.set_item_tracker(self.client.item_tracker)
|
||||||
|
await self.magpie.send_gps(self.client.gps_tracker)
|
||||||
|
|
||||||
|
except GameboyException:
|
||||||
|
time.sleep(1.0)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
parser = get_base_parser(description="Link's Awakening Client.")
|
||||||
|
parser.add_argument("--url", help="Archipelago connection url")
|
||||||
|
|
||||||
|
parser.add_argument('diff_file', default="", type=str, nargs="?",
|
||||||
|
help='Path to a .apladx Archipelago Binary Patch file')
|
||||||
|
args = parser.parse_args()
|
||||||
|
logger.info(args)
|
||||||
|
|
||||||
|
if args.diff_file:
|
||||||
|
import Patch
|
||||||
|
logger.info("patch file was supplied - creating rom...")
|
||||||
|
meta, rom_file = Patch.create_rom_file(args.diff_file)
|
||||||
|
if "server" in meta:
|
||||||
|
args.url = meta["server"]
|
||||||
|
logger.info(f"wrote rom file to {rom_file}")
|
||||||
|
|
||||||
|
if args.url:
|
||||||
|
url = urllib.parse.urlparse(args.url)
|
||||||
|
args.connect = url.netloc
|
||||||
|
if url.password:
|
||||||
|
args.password = urllib.parse.unquote(url.password)
|
||||||
|
|
||||||
|
ctx = LinksAwakeningContext(args.connect, args.password)
|
||||||
|
|
||||||
|
ctx.server_task = asyncio.create_task(server_loop(ctx), name="server loop")
|
||||||
|
|
||||||
|
# TODO: nothing about the lambda about has to be in a lambda
|
||||||
|
ctx.la_task = create_task_log_exception(ctx.run_game_loop())
|
||||||
|
if gui_enabled:
|
||||||
|
ctx.run_gui()
|
||||||
|
ctx.run_cli()
|
||||||
|
|
||||||
|
await ctx.exit_event.wait()
|
||||||
|
await ctx.shutdown()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
colorama.init()
|
||||||
|
asyncio.run(main())
|
||||||
|
colorama.deinit()
|
||||||
@@ -107,6 +107,12 @@ def main():
|
|||||||
Alternatively, can be a ALttP Rom patched with a Link
|
Alternatively, can be a ALttP Rom patched with a Link
|
||||||
sprite that will be extracted.
|
sprite that will be extracted.
|
||||||
''')
|
''')
|
||||||
|
parser.add_argument('--oof', help='''\
|
||||||
|
Path to a sound effect to replace Link's "oof" sound.
|
||||||
|
Needs to be in a .brr format and have a length of no
|
||||||
|
more than 2673 bytes, created from a 16-bit signed PCM
|
||||||
|
.wav at 12khz. https://github.com/boldowa/snesbrr
|
||||||
|
''')
|
||||||
parser.add_argument('--names', default='', type=str)
|
parser.add_argument('--names', default='', type=str)
|
||||||
parser.add_argument('--update_sprites', action='store_true', help='Update Sprite Database, then exit.')
|
parser.add_argument('--update_sprites', action='store_true', help='Update Sprite Database, then exit.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -126,6 +132,13 @@ def main():
|
|||||||
if args.sprite is not None and not os.path.isfile(args.sprite) and not Sprite.get_sprite_from_name(args.sprite):
|
if args.sprite is not None and not os.path.isfile(args.sprite) and not Sprite.get_sprite_from_name(args.sprite):
|
||||||
input('Could not find link sprite sheet at given location. \nPress Enter to exit.')
|
input('Could not find link sprite sheet at given location. \nPress Enter to exit.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
if args.oof is not None and not os.path.isfile(args.oof):
|
||||||
|
input('Could not find oof sound effect at given location. \nPress Enter to exit.')
|
||||||
|
sys.exit(1)
|
||||||
|
if args.oof is not None and os.path.getsize(args.oof) > 2673:
|
||||||
|
input('"oof" sound effect cannot exceed 2673 bytes. \nPress Enter to exit.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
args, path = adjust(args=args)
|
args, path = adjust(args=args)
|
||||||
if isinstance(args.sprite, Sprite):
|
if isinstance(args.sprite, Sprite):
|
||||||
@@ -165,7 +178,7 @@ def adjust(args):
|
|||||||
world = getattr(args, "world")
|
world = getattr(args, "world")
|
||||||
|
|
||||||
apply_rom_settings(rom, args.heartbeep, args.heartcolor, args.quickswap, args.menuspeed, args.music,
|
apply_rom_settings(rom, args.heartbeep, args.heartcolor, args.quickswap, args.menuspeed, args.music,
|
||||||
args.sprite, palettes_options, reduceflashing=args.reduceflashing or racerom, world=world,
|
args.sprite, args.oof, palettes_options, reduceflashing=args.reduceflashing or racerom, world=world,
|
||||||
deathlink=args.deathlink, allowcollect=args.allowcollect)
|
deathlink=args.deathlink, allowcollect=args.allowcollect)
|
||||||
path = output_path(f'{os.path.basename(args.rom)[:-4]}_adjusted.sfc')
|
path = output_path(f'{os.path.basename(args.rom)[:-4]}_adjusted.sfc')
|
||||||
rom.write_to_file(path)
|
rom.write_to_file(path)
|
||||||
@@ -227,6 +240,7 @@ def adjustGUI():
|
|||||||
guiargs.sprite = rom_vars.sprite
|
guiargs.sprite = rom_vars.sprite
|
||||||
if rom_vars.sprite_pool:
|
if rom_vars.sprite_pool:
|
||||||
guiargs.world = AdjusterWorld(rom_vars.sprite_pool)
|
guiargs.world = AdjusterWorld(rom_vars.sprite_pool)
|
||||||
|
guiargs.oof = rom_vars.oof
|
||||||
|
|
||||||
try:
|
try:
|
||||||
guiargs, path = adjust(args=guiargs)
|
guiargs, path = adjust(args=guiargs)
|
||||||
@@ -265,6 +279,7 @@ def adjustGUI():
|
|||||||
else:
|
else:
|
||||||
guiargs.sprite = rom_vars.sprite
|
guiargs.sprite = rom_vars.sprite
|
||||||
guiargs.sprite_pool = rom_vars.sprite_pool
|
guiargs.sprite_pool = rom_vars.sprite_pool
|
||||||
|
guiargs.oof = rom_vars.oof
|
||||||
persistent_store("adjuster", GAME_ALTTP, guiargs)
|
persistent_store("adjuster", GAME_ALTTP, guiargs)
|
||||||
messagebox.showinfo(title="Success", message="Settings saved to persistent storage")
|
messagebox.showinfo(title="Success", message="Settings saved to persistent storage")
|
||||||
|
|
||||||
@@ -481,6 +496,36 @@ class BackgroundTaskProgressNullWindow(BackgroundTask):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
|
class AttachTooltip(object):
|
||||||
|
|
||||||
|
def __init__(self, parent, text):
|
||||||
|
self._parent = parent
|
||||||
|
self._text = text
|
||||||
|
self._window = None
|
||||||
|
parent.bind('<Enter>', lambda event : self.show())
|
||||||
|
parent.bind('<Leave>', lambda event : self.hide())
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
if self._window or not self._text:
|
||||||
|
return
|
||||||
|
self._window = Toplevel(self._parent)
|
||||||
|
#remove window bar controls
|
||||||
|
self._window.wm_overrideredirect(1)
|
||||||
|
#adjust positioning
|
||||||
|
x, y, *_ = self._parent.bbox("insert")
|
||||||
|
x = x + self._parent.winfo_rootx() + 20
|
||||||
|
y = y + self._parent.winfo_rooty() + 20
|
||||||
|
self._window.wm_geometry("+{0}+{1}".format(x,y))
|
||||||
|
#show text
|
||||||
|
label = Label(self._window, text=self._text, justify=LEFT)
|
||||||
|
label.pack(ipadx=1)
|
||||||
|
|
||||||
|
def hide(self):
|
||||||
|
if self._window:
|
||||||
|
self._window.destroy()
|
||||||
|
self._window = None
|
||||||
|
|
||||||
|
|
||||||
def get_rom_frame(parent=None):
|
def get_rom_frame(parent=None):
|
||||||
adjuster_settings = get_adjuster_settings(GAME_ALTTP)
|
adjuster_settings = get_adjuster_settings(GAME_ALTTP)
|
||||||
if not adjuster_settings:
|
if not adjuster_settings:
|
||||||
@@ -522,6 +567,7 @@ def get_rom_options_frame(parent=None):
|
|||||||
"reduceflashing": True,
|
"reduceflashing": True,
|
||||||
"deathlink": False,
|
"deathlink": False,
|
||||||
"sprite": None,
|
"sprite": None,
|
||||||
|
"oof": None,
|
||||||
"quickswap": True,
|
"quickswap": True,
|
||||||
"menuspeed": 'normal',
|
"menuspeed": 'normal',
|
||||||
"heartcolor": 'red',
|
"heartcolor": 'red',
|
||||||
@@ -598,12 +644,50 @@ def get_rom_options_frame(parent=None):
|
|||||||
spriteEntry.pack(side=LEFT)
|
spriteEntry.pack(side=LEFT)
|
||||||
spriteSelectButton.pack(side=LEFT)
|
spriteSelectButton.pack(side=LEFT)
|
||||||
|
|
||||||
|
oofDialogFrame = Frame(romOptionsFrame)
|
||||||
|
oofDialogFrame.grid(row=1, column=1)
|
||||||
|
baseOofLabel = Label(oofDialogFrame, text='"OOF" Sound:')
|
||||||
|
|
||||||
|
vars.oofNameVar = StringVar()
|
||||||
|
vars.oof = adjuster_settings.oof
|
||||||
|
|
||||||
|
def set_oof(oof_param):
|
||||||
|
nonlocal vars
|
||||||
|
if isinstance(oof_param, str) and os.path.isfile(oof_param) and os.path.getsize(oof_param) <= 2673:
|
||||||
|
vars.oof = oof_param
|
||||||
|
vars.oofNameVar.set(oof_param.rsplit('/',1)[-1])
|
||||||
|
else:
|
||||||
|
vars.oof = None
|
||||||
|
vars.oofNameVar.set('(unchanged)')
|
||||||
|
|
||||||
|
set_oof(adjuster_settings.oof)
|
||||||
|
oofEntry = Label(oofDialogFrame, textvariable=vars.oofNameVar)
|
||||||
|
|
||||||
|
def OofSelect():
|
||||||
|
nonlocal vars
|
||||||
|
oof_file = filedialog.askopenfilename(
|
||||||
|
filetypes=[("BRR files", ".brr"),
|
||||||
|
("All Files", "*")])
|
||||||
|
try:
|
||||||
|
set_oof(oof_file)
|
||||||
|
except Exception:
|
||||||
|
set_oof(None)
|
||||||
|
|
||||||
|
oofSelectButton = Button(oofDialogFrame, text='...', command=OofSelect)
|
||||||
|
AttachTooltip(oofSelectButton,
|
||||||
|
text="Select a .brr file no more than 2673 bytes.\n" + \
|
||||||
|
"This can be created from a <=0.394s 16-bit signed PCM .wav file at 12khz using snesbrr.")
|
||||||
|
|
||||||
|
baseOofLabel.pack(side=LEFT)
|
||||||
|
oofEntry.pack(side=LEFT)
|
||||||
|
oofSelectButton.pack(side=LEFT)
|
||||||
|
|
||||||
vars.quickSwapVar = IntVar(value=adjuster_settings.quickswap)
|
vars.quickSwapVar = IntVar(value=adjuster_settings.quickswap)
|
||||||
quickSwapCheckbutton = Checkbutton(romOptionsFrame, text="L/R Quickswapping", variable=vars.quickSwapVar)
|
quickSwapCheckbutton = Checkbutton(romOptionsFrame, text="L/R Quickswapping", variable=vars.quickSwapVar)
|
||||||
quickSwapCheckbutton.grid(row=1, column=0, sticky=E)
|
quickSwapCheckbutton.grid(row=1, column=0, sticky=E)
|
||||||
|
|
||||||
menuspeedFrame = Frame(romOptionsFrame)
|
menuspeedFrame = Frame(romOptionsFrame)
|
||||||
menuspeedFrame.grid(row=1, column=1, sticky=E)
|
menuspeedFrame.grid(row=6, column=1, sticky=E)
|
||||||
menuspeedLabel = Label(menuspeedFrame, text='Menu speed')
|
menuspeedLabel = Label(menuspeedFrame, text='Menu speed')
|
||||||
menuspeedLabel.pack(side=LEFT)
|
menuspeedLabel.pack(side=LEFT)
|
||||||
vars.menuspeedVar = StringVar()
|
vars.menuspeedVar = StringVar()
|
||||||
@@ -1056,7 +1140,6 @@ class SpriteSelector():
|
|||||||
def custom_sprite_dir(self):
|
def custom_sprite_dir(self):
|
||||||
return user_path("data", "sprites", "custom")
|
return user_path("data", "sprites", "custom")
|
||||||
|
|
||||||
|
|
||||||
def get_image_for_sprite(sprite, gif_only: bool = False):
|
def get_image_for_sprite(sprite, gif_only: bool = False):
|
||||||
if not sprite.valid:
|
if not sprite.valid:
|
||||||
return None
|
return None
|
||||||
|
|||||||
72
Main.py
@@ -1,23 +1,24 @@
|
|||||||
import collections
|
import collections
|
||||||
|
import concurrent.futures
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import zlib
|
|
||||||
import concurrent.futures
|
|
||||||
import pickle
|
import pickle
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
from typing import Dict, List, Tuple, Optional, Set
|
import zlib
|
||||||
|
from typing import Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
from BaseClasses import Item, MultiWorld, CollectionState, Region, LocationProgressType, Location
|
|
||||||
import worlds
|
import worlds
|
||||||
from worlds.alttp.SubClasses import LTTPRegionType
|
from BaseClasses import CollectionState, Item, Location, LocationProgressType, MultiWorld, Region
|
||||||
from worlds.alttp.Regions import is_main_entrance
|
from Fill import balance_multiworld_progression, distribute_items_restrictive, distribute_planned, flood_items
|
||||||
from Fill import distribute_items_restrictive, flood_items, balance_multiworld_progression, distribute_planned
|
from Options import StartInventoryPool
|
||||||
from worlds.alttp.Shops import FillDisabledShopSlots
|
from Utils import __version__, get_options, output_path, version_tuple
|
||||||
from Utils import output_path, get_options, __version__, version_tuple
|
|
||||||
from worlds.generic.Rules import locality_rules, exclusion_rules
|
|
||||||
from worlds import AutoWorld
|
from worlds import AutoWorld
|
||||||
|
from worlds.alttp.Regions import is_main_entrance
|
||||||
|
from worlds.alttp.Shops import FillDisabledShopSlots
|
||||||
|
from worlds.alttp.SubClasses import LTTPRegionType
|
||||||
|
from worlds.generic.Rules import exclusion_rules, locality_rules
|
||||||
|
|
||||||
ordered_areas = (
|
ordered_areas = (
|
||||||
'Light World', 'Dark World', 'Hyrule Castle', 'Agahnims Tower', 'Eastern Palace', 'Desert Palace',
|
'Light World', 'Dark World', 'Hyrule Castle', 'Agahnims Tower', 'Eastern Palace', 'Desert Palace',
|
||||||
@@ -116,6 +117,10 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
|||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
world.push_precollected(world.create_item(item_name, player))
|
world.push_precollected(world.create_item(item_name, player))
|
||||||
|
|
||||||
|
for item_name, count in world.start_inventory_from_pool.setdefault(player, StartInventoryPool({})).value.items():
|
||||||
|
for _ in range(count):
|
||||||
|
world.push_precollected(world.create_item(item_name, player))
|
||||||
|
|
||||||
logger.info('Creating World.')
|
logger.info('Creating World.')
|
||||||
AutoWorld.call_all(world, "create_regions")
|
AutoWorld.call_all(world, "create_regions")
|
||||||
|
|
||||||
@@ -149,6 +154,37 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
|||||||
|
|
||||||
AutoWorld.call_all(world, "generate_basic")
|
AutoWorld.call_all(world, "generate_basic")
|
||||||
|
|
||||||
|
# remove starting inventory from pool items.
|
||||||
|
# Because some worlds don't actually create items during create_items this has to be as late as possible.
|
||||||
|
if any(world.start_inventory_from_pool[player].value for player in world.player_ids):
|
||||||
|
new_items: List[Item] = []
|
||||||
|
depletion_pool: Dict[int, Dict[str, int]] = {
|
||||||
|
player: world.start_inventory_from_pool[player].value.copy() for player in world.player_ids}
|
||||||
|
for player, items in depletion_pool.items():
|
||||||
|
player_world: AutoWorld.World = world.worlds[player]
|
||||||
|
for count in items.values():
|
||||||
|
new_items.append(player_world.create_filler())
|
||||||
|
target: int = sum(sum(items.values()) for items in depletion_pool.values())
|
||||||
|
for i, item in enumerate(world.itempool):
|
||||||
|
if depletion_pool[item.player].get(item.name, 0):
|
||||||
|
target -= 1
|
||||||
|
depletion_pool[item.player][item.name] -= 1
|
||||||
|
# quick abort if we have found all items
|
||||||
|
if not target:
|
||||||
|
new_items.extend(world.itempool[i+1:])
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
new_items.append(item)
|
||||||
|
|
||||||
|
# leftovers?
|
||||||
|
if target:
|
||||||
|
for player, remaining_items in depletion_pool.items():
|
||||||
|
remaining_items = {name: count for name, count in remaining_items.items() if count}
|
||||||
|
if remaining_items:
|
||||||
|
raise Exception(f"{world.get_player_name(player)}"
|
||||||
|
f" is trying to remove items from their pool that don't exist: {remaining_items}")
|
||||||
|
world.itempool[:] = new_items
|
||||||
|
|
||||||
# temporary home for item links, should be moved out of Main
|
# temporary home for item links, should be moved out of Main
|
||||||
for group_id, group in world.groups.items():
|
for group_id, group in world.groups.items():
|
||||||
def find_common_pool(players: Set[int], shared_pool: Set[str]) -> Tuple[
|
def find_common_pool(players: Set[int], shared_pool: Set[str]) -> Tuple[
|
||||||
@@ -355,13 +391,11 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
|||||||
for player in world.groups.get(location.item.player, {}).get("players", [])]):
|
for player in world.groups.get(location.item.player, {}).get("players", [])]):
|
||||||
precollect_hint(location)
|
precollect_hint(location)
|
||||||
|
|
||||||
# custom datapackage
|
# embedded data package
|
||||||
datapackage = {}
|
data_package = {
|
||||||
for game_world in world.worlds.values():
|
game_world.game: worlds.network_data_package["games"][game_world.game]
|
||||||
if game_world.data_version == 0 and game_world.game not in datapackage:
|
for game_world in world.worlds.values()
|
||||||
datapackage[game_world.game] = worlds.network_data_package["games"][game_world.game]
|
}
|
||||||
datapackage[game_world.game]["item_name_groups"] = game_world.item_name_groups
|
|
||||||
datapackage[game_world.game]["location_name_groups"] = game_world.location_name_groups
|
|
||||||
|
|
||||||
multidata = {
|
multidata = {
|
||||||
"slot_data": slot_data,
|
"slot_data": slot_data,
|
||||||
@@ -378,7 +412,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
|||||||
"tags": ["AP"],
|
"tags": ["AP"],
|
||||||
"minimum_versions": minimum_versions,
|
"minimum_versions": minimum_versions,
|
||||||
"seed_name": world.seed_name,
|
"seed_name": world.seed_name,
|
||||||
"datapackage": datapackage,
|
"datapackage": data_package,
|
||||||
}
|
}
|
||||||
AutoWorld.call_all(world, "modify_multidata", multidata)
|
AutoWorld.call_all(world, "modify_multidata", multidata)
|
||||||
|
|
||||||
|
|||||||
@@ -77,49 +77,34 @@ def read_apmc_file(apmc_file):
|
|||||||
return json.loads(b64decode(f.read()))
|
return json.loads(b64decode(f.read()))
|
||||||
|
|
||||||
|
|
||||||
def update_mod(forge_dir, minecraft_version: str, get_prereleases=False):
|
def update_mod(forge_dir, url: str):
|
||||||
"""Check mod version, download new mod from GitHub releases page if needed. """
|
"""Check mod version, download new mod from GitHub releases page if needed. """
|
||||||
ap_randomizer = find_ap_randomizer_jar(forge_dir)
|
ap_randomizer = find_ap_randomizer_jar(forge_dir)
|
||||||
|
os.path.basename(url)
|
||||||
client_releases_endpoint = "https://api.github.com/repos/KonoTyran/Minecraft_AP_Randomizer/releases"
|
if ap_randomizer is not None:
|
||||||
resp = requests.get(client_releases_endpoint)
|
logging.info(f"Your current mod is {ap_randomizer}.")
|
||||||
if resp.status_code == 200: # OK
|
|
||||||
try:
|
|
||||||
latest_release = next(filter(lambda release: (not release['prerelease'] or get_prereleases) and
|
|
||||||
(minecraft_version in release['assets'][0]['name']),
|
|
||||||
resp.json()))
|
|
||||||
if ap_randomizer != latest_release['assets'][0]['name']:
|
|
||||||
logging.info(f"A new release of the Minecraft AP randomizer mod was found: "
|
|
||||||
f"{latest_release['assets'][0]['name']}")
|
|
||||||
if ap_randomizer is not None:
|
|
||||||
logging.info(f"Your current mod is {ap_randomizer}.")
|
|
||||||
else:
|
|
||||||
logging.info(f"You do not have the AP randomizer mod installed.")
|
|
||||||
if prompt_yes_no("Would you like to update?"):
|
|
||||||
old_ap_mod = os.path.join(forge_dir, 'mods', ap_randomizer) if ap_randomizer is not None else None
|
|
||||||
new_ap_mod = os.path.join(forge_dir, 'mods', latest_release['assets'][0]['name'])
|
|
||||||
logging.info("Downloading AP randomizer mod. This may take a moment...")
|
|
||||||
apmod_resp = requests.get(latest_release['assets'][0]['browser_download_url'])
|
|
||||||
if apmod_resp.status_code == 200:
|
|
||||||
with open(new_ap_mod, 'wb') as f:
|
|
||||||
f.write(apmod_resp.content)
|
|
||||||
logging.info(f"Wrote new mod file to {new_ap_mod}")
|
|
||||||
if old_ap_mod is not None:
|
|
||||||
os.remove(old_ap_mod)
|
|
||||||
logging.info(f"Removed old mod file from {old_ap_mod}")
|
|
||||||
else:
|
|
||||||
logging.error(f"Error retrieving the randomizer mod (status code {apmod_resp.status_code}).")
|
|
||||||
logging.error(f"Please report this issue on the Archipelago Discord server.")
|
|
||||||
sys.exit(1)
|
|
||||||
except StopIteration:
|
|
||||||
logging.warning(f"No compatible mod version found for {minecraft_version}.")
|
|
||||||
if not prompt_yes_no("Run server anyway?"):
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
else:
|
||||||
logging.error(f"Error checking for randomizer mod updates (status code {resp.status_code}).")
|
logging.info(f"You do not have the AP randomizer mod installed.")
|
||||||
logging.error(f"If this was not expected, please report this issue on the Archipelago Discord server.")
|
|
||||||
if not prompt_yes_no("Continue anyways?"):
|
if ap_randomizer != os.path.basename(url):
|
||||||
sys.exit(0)
|
logging.info(f"A new release of the Minecraft AP randomizer mod was found: "
|
||||||
|
f"{os.path.basename(url)}")
|
||||||
|
if prompt_yes_no("Would you like to update?"):
|
||||||
|
old_ap_mod = os.path.join(forge_dir, 'mods', ap_randomizer) if ap_randomizer is not None else None
|
||||||
|
new_ap_mod = os.path.join(forge_dir, 'mods', os.path.basename(url))
|
||||||
|
logging.info("Downloading AP randomizer mod. This may take a moment...")
|
||||||
|
apmod_resp = requests.get(url)
|
||||||
|
if apmod_resp.status_code == 200:
|
||||||
|
with open(new_ap_mod, 'wb') as f:
|
||||||
|
f.write(apmod_resp.content)
|
||||||
|
logging.info(f"Wrote new mod file to {new_ap_mod}")
|
||||||
|
if old_ap_mod is not None:
|
||||||
|
os.remove(old_ap_mod)
|
||||||
|
logging.info(f"Removed old mod file from {old_ap_mod}")
|
||||||
|
else:
|
||||||
|
logging.error(f"Error retrieving the randomizer mod (status code {apmod_resp.status_code}).")
|
||||||
|
logging.error(f"Please report this issue on the Archipelago Discord server.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def check_eula(forge_dir):
|
def check_eula(forge_dir):
|
||||||
@@ -264,8 +249,13 @@ def get_minecraft_versions(version, release_channel="release"):
|
|||||||
return next(filter(lambda entry: entry["version"] == version, data[release_channel]))
|
return next(filter(lambda entry: entry["version"] == version, data[release_channel]))
|
||||||
else:
|
else:
|
||||||
return resp.json()[release_channel][0]
|
return resp.json()[release_channel][0]
|
||||||
except StopIteration:
|
except (StopIteration, KeyError):
|
||||||
logging.error(f"No compatible mod version found for client version {version}.")
|
logging.error(f"No compatible mod version found for client version {version} on \"{release_channel}\" channel.")
|
||||||
|
if release_channel != "release":
|
||||||
|
logging.error("Consider switching \"release_channel\" to \"release\" in your Host.yaml file")
|
||||||
|
else:
|
||||||
|
logging.error("No suitable mod found on the \"release\" channel. Please Contact us on discord to report this error.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def is_correct_forge(forge_dir) -> bool:
|
def is_correct_forge(forge_dir) -> bool:
|
||||||
@@ -286,6 +276,8 @@ if __name__ == '__main__':
|
|||||||
help="specify java version.")
|
help="specify java version.")
|
||||||
parser.add_argument('--forge', '-f', metavar='1.18.2-40.1.0', dest='forge', type=str, default=False, action='store',
|
parser.add_argument('--forge', '-f', metavar='1.18.2-40.1.0', dest='forge', type=str, default=False, action='store',
|
||||||
help="specify forge version. (Minecraft Version-Forge Version)")
|
help="specify forge version. (Minecraft Version-Forge Version)")
|
||||||
|
parser.add_argument('--version', '-v', metavar='9', dest='data_version', type=int, action='store',
|
||||||
|
help="specify Mod data version to download.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
apmc_file = os.path.abspath(args.apmc_file) if args.apmc_file else None
|
apmc_file = os.path.abspath(args.apmc_file) if args.apmc_file else None
|
||||||
@@ -296,12 +288,12 @@ if __name__ == '__main__':
|
|||||||
options = Utils.get_options()
|
options = Utils.get_options()
|
||||||
channel = args.channel or options["minecraft_options"]["release_channel"]
|
channel = args.channel or options["minecraft_options"]["release_channel"]
|
||||||
apmc_data = None
|
apmc_data = None
|
||||||
data_version = None
|
data_version = args.data_version or None
|
||||||
|
|
||||||
if apmc_file is None and not args.install:
|
if apmc_file is None and not args.install:
|
||||||
apmc_file = Utils.open_filename('Select APMC file', (('APMC File', ('.apmc',)),))
|
apmc_file = Utils.open_filename('Select APMC file', (('APMC File', ('.apmc',)),))
|
||||||
|
|
||||||
if apmc_file is not None:
|
if apmc_file is not None and data_version is None:
|
||||||
apmc_data = read_apmc_file(apmc_file)
|
apmc_data = read_apmc_file(apmc_file)
|
||||||
data_version = apmc_data.get('client_version', '')
|
data_version = apmc_data.get('client_version', '')
|
||||||
|
|
||||||
@@ -311,6 +303,7 @@ if __name__ == '__main__':
|
|||||||
max_heap = options["minecraft_options"]["max_heap_size"]
|
max_heap = options["minecraft_options"]["max_heap_size"]
|
||||||
forge_version = args.forge or versions["forge"]
|
forge_version = args.forge or versions["forge"]
|
||||||
java_version = args.java or versions["java"]
|
java_version = args.java or versions["java"]
|
||||||
|
mod_url = versions["url"]
|
||||||
java_dir = find_jdk_dir(java_version)
|
java_dir = find_jdk_dir(java_version)
|
||||||
|
|
||||||
if args.install:
|
if args.install:
|
||||||
@@ -344,7 +337,7 @@ if __name__ == '__main__':
|
|||||||
if not max_heap_re.match(max_heap):
|
if not max_heap_re.match(max_heap):
|
||||||
raise Exception(f"Max heap size {max_heap} in incorrect format. Use a number followed by M or G, e.g. 512M or 2G.")
|
raise Exception(f"Max heap size {max_heap} in incorrect format. Use a number followed by M or G, e.g. 512M or 2G.")
|
||||||
|
|
||||||
update_mod(forge_dir, f"MC{forge_version.split('-')[0]}", channel != "release")
|
update_mod(forge_dir, mod_url)
|
||||||
replace_apmc_files(forge_dir, apmc_file)
|
replace_apmc_files(forge_dir, apmc_file)
|
||||||
check_eula(forge_dir)
|
check_eula(forge_dir)
|
||||||
server_process = run_forge_server(forge_dir, java_version, max_heap)
|
server_process = run_forge_server(forge_dir, java_version, max_heap)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import pkg_resources
|
import multiprocessing
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
local_dir = os.path.dirname(__file__)
|
local_dir = os.path.dirname(__file__)
|
||||||
@@ -10,7 +10,8 @@ requirements_files = {os.path.join(local_dir, 'requirements.txt')}
|
|||||||
if sys.version_info < (3, 8, 6):
|
if sys.version_info < (3, 8, 6):
|
||||||
raise RuntimeError("Incompatible Python Version. 3.8.7+ is supported.")
|
raise RuntimeError("Incompatible Python Version. 3.8.7+ is supported.")
|
||||||
|
|
||||||
update_ran = getattr(sys, "frozen", False) # don't run update if environment is frozen/compiled
|
# don't run update if environment is frozen/compiled or if not the parent process (skip in subprocess)
|
||||||
|
update_ran = getattr(sys, "frozen", False) or multiprocessing.parent_process()
|
||||||
|
|
||||||
if not update_ran:
|
if not update_ran:
|
||||||
for entry in os.scandir(os.path.join(local_dir, "worlds")):
|
for entry in os.scandir(os.path.join(local_dir, "worlds")):
|
||||||
@@ -22,18 +23,50 @@ if not update_ran:
|
|||||||
requirements_files.add(req_file)
|
requirements_files.add(req_file)
|
||||||
|
|
||||||
|
|
||||||
|
def check_pip():
|
||||||
|
# detect if pip is available
|
||||||
|
try:
|
||||||
|
import pip # noqa: F401
|
||||||
|
except ImportError:
|
||||||
|
raise RuntimeError("pip not available. Please install pip.")
|
||||||
|
|
||||||
|
|
||||||
|
def confirm(msg: str):
|
||||||
|
try:
|
||||||
|
input(f"\n{msg}")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nAborting")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def update_command():
|
def update_command():
|
||||||
|
check_pip()
|
||||||
for file in requirements_files:
|
for file in requirements_files:
|
||||||
subprocess.call([sys.executable, '-m', 'pip', 'install', '-r', file, '--upgrade'])
|
subprocess.call([sys.executable, "-m", "pip", "install", "-r", file, "--upgrade"])
|
||||||
|
|
||||||
|
|
||||||
|
def install_pkg_resources(yes=False):
|
||||||
|
try:
|
||||||
|
import pkg_resources # noqa: F401
|
||||||
|
except ImportError:
|
||||||
|
check_pip()
|
||||||
|
if not yes:
|
||||||
|
confirm("pkg_resources not found, press enter to install it")
|
||||||
|
subprocess.call([sys.executable, "-m", "pip", "install", "--upgrade", "setuptools"])
|
||||||
|
|
||||||
|
|
||||||
def update(yes=False, force=False):
|
def update(yes=False, force=False):
|
||||||
global update_ran
|
global update_ran
|
||||||
if not update_ran:
|
if not update_ran:
|
||||||
update_ran = True
|
update_ran = True
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
update_command()
|
update_command()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
install_pkg_resources(yes=yes)
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
for req_file in requirements_files:
|
for req_file in requirements_files:
|
||||||
path = os.path.join(os.path.dirname(sys.argv[0]), req_file)
|
path = os.path.join(os.path.dirname(sys.argv[0]), req_file)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
@@ -52,7 +85,7 @@ def update(yes=False, force=False):
|
|||||||
egg = egg.split(";", 1)[0].rstrip()
|
egg = egg.split(";", 1)[0].rstrip()
|
||||||
if any(compare in egg for compare in ("==", ">=", ">", "<", "<=", "!=")):
|
if any(compare in egg for compare in ("==", ">=", ">", "<", "<=", "!=")):
|
||||||
warnings.warn(f"Specifying version as #egg={egg} will become unavailable in pip 25.0. "
|
warnings.warn(f"Specifying version as #egg={egg} will become unavailable in pip 25.0. "
|
||||||
"Use name @ url#version instead.", DeprecationWarning)
|
"Use name @ url#version instead.", DeprecationWarning)
|
||||||
line = egg
|
line = egg
|
||||||
else:
|
else:
|
||||||
egg = ""
|
egg = ""
|
||||||
@@ -79,11 +112,7 @@ def update(yes=False, force=False):
|
|||||||
if not yes:
|
if not yes:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
confirm(f"Requirement {requirement} is not satisfied, press enter to install it")
|
||||||
input(f"\nRequirement {requirement} is not satisfied, press enter to install it")
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("\nAborting")
|
|
||||||
sys.exit(1)
|
|
||||||
update_command()
|
update_command()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
137
MultiServer.py
@@ -3,21 +3,21 @@ from __future__ import annotations
|
|||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import copy
|
import copy
|
||||||
import functools
|
|
||||||
import logging
|
|
||||||
import zlib
|
|
||||||
import collections
|
import collections
|
||||||
import typing
|
|
||||||
import inspect
|
|
||||||
import weakref
|
|
||||||
import datetime
|
import datetime
|
||||||
import threading
|
import functools
|
||||||
import random
|
|
||||||
import pickle
|
|
||||||
import itertools
|
|
||||||
import time
|
|
||||||
import operator
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import inspect
|
||||||
|
import itertools
|
||||||
|
import logging
|
||||||
|
import operator
|
||||||
|
import pickle
|
||||||
|
import random
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import typing
|
||||||
|
import weakref
|
||||||
|
import zlib
|
||||||
|
|
||||||
import ModuleUpdate
|
import ModuleUpdate
|
||||||
|
|
||||||
@@ -159,7 +159,8 @@ class Context:
|
|||||||
read_data: typing.Dict[str, object]
|
read_data: typing.Dict[str, object]
|
||||||
stored_data_notification_clients: typing.Dict[str, typing.Set[Client]]
|
stored_data_notification_clients: typing.Dict[str, typing.Set[Client]]
|
||||||
slot_info: typing.Dict[int, NetworkSlot]
|
slot_info: typing.Dict[int, NetworkSlot]
|
||||||
|
generator_version = Version(0, 0, 0)
|
||||||
|
checksums: typing.Dict[str, str]
|
||||||
item_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown item (ID:{code})')
|
item_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown item (ID:{code})')
|
||||||
item_name_groups: typing.Dict[str, typing.Dict[str, typing.Set[str]]]
|
item_name_groups: typing.Dict[str, typing.Dict[str, typing.Set[str]]]
|
||||||
location_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown location (ID:{code})')
|
location_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown location (ID:{code})')
|
||||||
@@ -222,7 +223,7 @@ class Context:
|
|||||||
self.save_dirty = False
|
self.save_dirty = False
|
||||||
self.tags = ['AP']
|
self.tags = ['AP']
|
||||||
self.games: typing.Dict[int, str] = {}
|
self.games: typing.Dict[int, str] = {}
|
||||||
self.minimum_client_versions: typing.Dict[int, Utils.Version] = {}
|
self.minimum_client_versions: typing.Dict[int, Version] = {}
|
||||||
self.seed_name = ""
|
self.seed_name = ""
|
||||||
self.groups = {}
|
self.groups = {}
|
||||||
self.group_collected: typing.Dict[int, typing.Set[int]] = {}
|
self.group_collected: typing.Dict[int, typing.Set[int]] = {}
|
||||||
@@ -233,6 +234,7 @@ class Context:
|
|||||||
|
|
||||||
# init empty to satisfy linter, I suppose
|
# init empty to satisfy linter, I suppose
|
||||||
self.gamespackage = {}
|
self.gamespackage = {}
|
||||||
|
self.checksums = {}
|
||||||
self.item_name_groups = {}
|
self.item_name_groups = {}
|
||||||
self.location_name_groups = {}
|
self.location_name_groups = {}
|
||||||
self.all_item_and_group_names = {}
|
self.all_item_and_group_names = {}
|
||||||
@@ -241,7 +243,7 @@ class Context:
|
|||||||
|
|
||||||
self._load_game_data()
|
self._load_game_data()
|
||||||
|
|
||||||
# Datapackage retrieval
|
# Data package retrieval
|
||||||
def _load_game_data(self):
|
def _load_game_data(self):
|
||||||
import worlds
|
import worlds
|
||||||
self.gamespackage = worlds.network_data_package["games"]
|
self.gamespackage = worlds.network_data_package["games"]
|
||||||
@@ -255,6 +257,8 @@ class Context:
|
|||||||
|
|
||||||
def _init_game_data(self):
|
def _init_game_data(self):
|
||||||
for game_name, game_package in self.gamespackage.items():
|
for game_name, game_package in self.gamespackage.items():
|
||||||
|
if "checksum" in game_package:
|
||||||
|
self.checksums[game_name] = game_package["checksum"]
|
||||||
for item_name, item_id in game_package["item_name_to_id"].items():
|
for item_name, item_id in game_package["item_name_to_id"].items():
|
||||||
self.item_names[item_id] = item_name
|
self.item_names[item_id] = item_name
|
||||||
for location_name, location_id in game_package["location_name_to_id"].items():
|
for location_name, location_id in game_package["location_name_to_id"].items():
|
||||||
@@ -262,7 +266,7 @@ class Context:
|
|||||||
self.all_item_and_group_names[game_name] = \
|
self.all_item_and_group_names[game_name] = \
|
||||||
set(game_package["item_name_to_id"]) | set(self.item_name_groups[game_name])
|
set(game_package["item_name_to_id"]) | set(self.item_name_groups[game_name])
|
||||||
self.all_location_and_group_names[game_name] = \
|
self.all_location_and_group_names[game_name] = \
|
||||||
set(game_package["location_name_to_id"]) | set(self.location_name_groups[game_name])
|
set(game_package["location_name_to_id"]) | set(self.location_name_groups.get(game_name, []))
|
||||||
|
|
||||||
def item_names_for_game(self, game: str) -> typing.Optional[typing.Dict[str, int]]:
|
def item_names_for_game(self, game: str) -> typing.Optional[typing.Dict[str, int]]:
|
||||||
return self.gamespackage[game]["item_name_to_id"] if game in self.gamespackage else None
|
return self.gamespackage[game]["item_name_to_id"] if game in self.gamespackage else None
|
||||||
@@ -351,7 +355,6 @@ class Context:
|
|||||||
for text in texts]))
|
for text in texts]))
|
||||||
|
|
||||||
# loading
|
# loading
|
||||||
|
|
||||||
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
||||||
if multidatapath.lower().endswith(".zip"):
|
if multidatapath.lower().endswith(".zip"):
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -366,7 +369,7 @@ class Context:
|
|||||||
with open(multidatapath, 'rb') as f:
|
with open(multidatapath, 'rb') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
|
||||||
self._load(self.decompress(data), use_embedded_server_options)
|
self._load(self.decompress(data), {}, use_embedded_server_options)
|
||||||
self.data_filename = multidatapath
|
self.data_filename = multidatapath
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -376,16 +379,19 @@ class Context:
|
|||||||
raise Utils.VersionException("Incompatible multidata.")
|
raise Utils.VersionException("Incompatible multidata.")
|
||||||
return restricted_loads(zlib.decompress(data[1:]))
|
return restricted_loads(zlib.decompress(data[1:]))
|
||||||
|
|
||||||
def _load(self, decoded_obj: dict, use_embedded_server_options: bool):
|
def _load(self, decoded_obj: dict, game_data_packages: typing.Dict[str, typing.Any],
|
||||||
|
use_embedded_server_options: bool):
|
||||||
|
|
||||||
self.read_data = {}
|
self.read_data = {}
|
||||||
mdata_ver = decoded_obj["minimum_versions"]["server"]
|
mdata_ver = decoded_obj["minimum_versions"]["server"]
|
||||||
if mdata_ver > Utils.version_tuple:
|
if mdata_ver > version_tuple:
|
||||||
raise RuntimeError(f"Supplied Multidata (.archipelago) requires a server of at least version {mdata_ver},"
|
raise RuntimeError(f"Supplied Multidata (.archipelago) requires a server of at least version {mdata_ver},"
|
||||||
f"however this server is of version {Utils.version_tuple}")
|
f"however this server is of version {version_tuple}")
|
||||||
|
self.generator_version = Version(*decoded_obj["version"])
|
||||||
clients_ver = decoded_obj["minimum_versions"].get("clients", {})
|
clients_ver = decoded_obj["minimum_versions"].get("clients", {})
|
||||||
self.minimum_client_versions = {}
|
self.minimum_client_versions = {}
|
||||||
for player, version in clients_ver.items():
|
for player, version in clients_ver.items():
|
||||||
self.minimum_client_versions[player] = max(Utils.Version(*version), min_client_version)
|
self.minimum_client_versions[player] = max(Version(*version), min_client_version)
|
||||||
|
|
||||||
self.slot_info = decoded_obj["slot_info"]
|
self.slot_info = decoded_obj["slot_info"]
|
||||||
self.games = {slot: slot_info.game for slot, slot_info in self.slot_info.items()}
|
self.games = {slot: slot_info.game for slot, slot_info in self.slot_info.items()}
|
||||||
@@ -431,14 +437,17 @@ class Context:
|
|||||||
server_options = decoded_obj.get("server_options", {})
|
server_options = decoded_obj.get("server_options", {})
|
||||||
self._set_options(server_options)
|
self._set_options(server_options)
|
||||||
|
|
||||||
# custom datapackage
|
# embedded data package
|
||||||
for game_name, data in decoded_obj.get("datapackage", {}).items():
|
for game_name, data in decoded_obj.get("datapackage", {}).items():
|
||||||
logging.info(f"Loading custom datapackage for game {game_name}")
|
if game_name in game_data_packages:
|
||||||
|
data = game_data_packages[game_name]
|
||||||
|
logging.info(f"Loading embedded data package for game {game_name}")
|
||||||
self.gamespackage[game_name] = data
|
self.gamespackage[game_name] = data
|
||||||
self.item_name_groups[game_name] = data["item_name_groups"]
|
self.item_name_groups[game_name] = data["item_name_groups"]
|
||||||
self.location_name_groups[game_name] = data["location_name_groups"]
|
if "location_name_groups" in data:
|
||||||
del data["item_name_groups"] # remove from datapackage, but keep in self.item_name_groups
|
self.location_name_groups[game_name] = data["location_name_groups"]
|
||||||
del data["location_name_groups"]
|
del data["location_name_groups"]
|
||||||
|
del data["item_name_groups"] # remove from data package, but keep in self.item_name_groups
|
||||||
self._init_game_data()
|
self._init_game_data()
|
||||||
for game_name, data in self.item_name_groups.items():
|
for game_name, data in self.item_name_groups.items():
|
||||||
self.read_data[f"item_name_groups_{game_name}"] = lambda lgame=game_name: self.item_name_groups[lgame]
|
self.read_data[f"item_name_groups_{game_name}"] = lambda lgame=game_name: self.item_name_groups[lgame]
|
||||||
@@ -534,7 +543,7 @@ class Context:
|
|||||||
"stored_data": self.stored_data,
|
"stored_data": self.stored_data,
|
||||||
"game_options": {"hint_cost": self.hint_cost, "location_check_points": self.location_check_points,
|
"game_options": {"hint_cost": self.hint_cost, "location_check_points": self.location_check_points,
|
||||||
"server_password": self.server_password, "password": self.password,
|
"server_password": self.server_password, "password": self.password,
|
||||||
"forfeit_mode": self.release_mode, "release_mode": self.release_mode, # TODO remove forfeit_mode around 0.4
|
"release_mode": self.release_mode,
|
||||||
"remaining_mode": self.remaining_mode, "collect_mode": self.collect_mode,
|
"remaining_mode": self.remaining_mode, "collect_mode": self.collect_mode,
|
||||||
"item_cheat": self.item_cheat, "compatibility": self.compatibility}
|
"item_cheat": self.item_cheat, "compatibility": self.compatibility}
|
||||||
|
|
||||||
@@ -587,7 +596,7 @@ class Context:
|
|||||||
|
|
||||||
def get_hint_cost(self, slot):
|
def get_hint_cost(self, slot):
|
||||||
if self.hint_cost:
|
if self.hint_cost:
|
||||||
return max(0, int(self.hint_cost * 0.01 * len(self.locations[slot])))
|
return max(1, int(self.hint_cost * 0.01 * len(self.locations[slot])))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def recheck_hints(self, team: typing.Optional[int] = None, slot: typing.Optional[int] = None):
|
def recheck_hints(self, team: typing.Optional[int] = None, slot: typing.Optional[int] = None):
|
||||||
@@ -690,6 +699,10 @@ class Context:
|
|||||||
targets: typing.Set[Client] = set(self.stored_data_notification_clients[key])
|
targets: typing.Set[Client] = set(self.stored_data_notification_clients[key])
|
||||||
if targets:
|
if targets:
|
||||||
self.broadcast(targets, [{"cmd": "SetReply", "key": key, "value": self.hints[team, slot]}])
|
self.broadcast(targets, [{"cmd": "SetReply", "key": key, "value": self.hints[team, slot]}])
|
||||||
|
self.broadcast(self.clients[team][slot], [{
|
||||||
|
"cmd": "RoomUpdate",
|
||||||
|
"hint_points": get_slot_points(self, team, slot)
|
||||||
|
}])
|
||||||
|
|
||||||
|
|
||||||
def update_aliases(ctx: Context, team: int):
|
def update_aliases(ctx: Context, team: int):
|
||||||
@@ -735,19 +748,24 @@ async def on_client_connected(ctx: Context, client: Client):
|
|||||||
NetworkPlayer(team, slot,
|
NetworkPlayer(team, slot,
|
||||||
ctx.name_aliases.get((team, slot), name), name)
|
ctx.name_aliases.get((team, slot), name), name)
|
||||||
)
|
)
|
||||||
|
games = {ctx.games[x] for x in range(1, len(ctx.games) + 1)}
|
||||||
|
games.add("Archipelago")
|
||||||
await ctx.send_msgs(client, [{
|
await ctx.send_msgs(client, [{
|
||||||
'cmd': 'RoomInfo',
|
'cmd': 'RoomInfo',
|
||||||
'password': bool(ctx.password),
|
'password': bool(ctx.password),
|
||||||
'games': {ctx.games[x] for x in range(1, len(ctx.games) + 1)},
|
'games': games,
|
||||||
# tags are for additional features in the communication.
|
# tags are for additional features in the communication.
|
||||||
# Name them by feature or fork, as you feel is appropriate.
|
# Name them by feature or fork, as you feel is appropriate.
|
||||||
'tags': ctx.tags,
|
'tags': ctx.tags,
|
||||||
'version': Utils.version_tuple,
|
'version': version_tuple,
|
||||||
|
'generator_version': ctx.generator_version,
|
||||||
'permissions': get_permissions(ctx),
|
'permissions': get_permissions(ctx),
|
||||||
'hint_cost': ctx.hint_cost,
|
'hint_cost': ctx.hint_cost,
|
||||||
'location_check_points': ctx.location_check_points,
|
'location_check_points': ctx.location_check_points,
|
||||||
'datapackage_versions': {game: game_data["version"] for game, game_data
|
'datapackage_versions': {game: game_data["version"] for game, game_data
|
||||||
in ctx.gamespackage.items()},
|
in ctx.gamespackage.items() if game in games},
|
||||||
|
'datapackage_checksums': {game: game_data["checksum"] for game, game_data
|
||||||
|
in ctx.gamespackage.items() if game in games and "checksum" in game_data},
|
||||||
'seed_name': ctx.seed_name,
|
'seed_name': ctx.seed_name,
|
||||||
'time': time.time(),
|
'time': time.time(),
|
||||||
}])
|
}])
|
||||||
@@ -755,7 +773,6 @@ async def on_client_connected(ctx: Context, client: Client):
|
|||||||
|
|
||||||
def get_permissions(ctx) -> typing.Dict[str, Permission]:
|
def get_permissions(ctx) -> typing.Dict[str, Permission]:
|
||||||
return {
|
return {
|
||||||
"forfeit": Permission.from_text(ctx.release_mode), # TODO remove around 0.4
|
|
||||||
"release": Permission.from_text(ctx.release_mode),
|
"release": Permission.from_text(ctx.release_mode),
|
||||||
"remaining": Permission.from_text(ctx.remaining_mode),
|
"remaining": Permission.from_text(ctx.remaining_mode),
|
||||||
"collect": Permission.from_text(ctx.collect_mode)
|
"collect": Permission.from_text(ctx.collect_mode)
|
||||||
@@ -768,7 +785,8 @@ async def on_client_disconnected(ctx: Context, client: Client):
|
|||||||
|
|
||||||
|
|
||||||
async def on_client_joined(ctx: Context, client: Client):
|
async def on_client_joined(ctx: Context, client: Client):
|
||||||
update_client_status(ctx, client, ClientStatus.CLIENT_CONNECTED)
|
if ctx.client_game_state[client.team, client.slot] == ClientStatus.CLIENT_UNKNOWN:
|
||||||
|
update_client_status(ctx, client, ClientStatus.CLIENT_CONNECTED)
|
||||||
version_str = '.'.join(str(x) for x in client.version)
|
version_str = '.'.join(str(x) for x in client.version)
|
||||||
verb = "tracking" if "Tracker" in client.tags else "playing"
|
verb = "tracking" if "Tracker" in client.tags else "playing"
|
||||||
ctx.broadcast_text_all(
|
ctx.broadcast_text_all(
|
||||||
@@ -785,11 +803,12 @@ async def on_client_joined(ctx: Context, client: Client):
|
|||||||
|
|
||||||
|
|
||||||
async def on_client_left(ctx: Context, client: Client):
|
async def on_client_left(ctx: Context, client: Client):
|
||||||
update_client_status(ctx, client, ClientStatus.CLIENT_UNKNOWN)
|
if len(ctx.clients[client.team][client.slot]) < 1:
|
||||||
|
update_client_status(ctx, client, ClientStatus.CLIENT_UNKNOWN)
|
||||||
|
ctx.client_connection_timers[client.team, client.slot] = datetime.datetime.now(datetime.timezone.utc)
|
||||||
ctx.broadcast_text_all(
|
ctx.broadcast_text_all(
|
||||||
"%s (Team #%d) has left the game" % (ctx.get_aliased_name(client.team, client.slot), client.team + 1),
|
"%s (Team #%d) has left the game" % (ctx.get_aliased_name(client.team, client.slot), client.team + 1),
|
||||||
{"type": "Part", "team": client.team, "slot": client.slot})
|
{"type": "Part", "team": client.team, "slot": client.slot})
|
||||||
ctx.client_connection_timers[client.team, client.slot] = datetime.datetime.now(datetime.timezone.utc)
|
|
||||||
|
|
||||||
|
|
||||||
async def countdown(ctx: Context, timer: int):
|
async def countdown(ctx: Context, timer: int):
|
||||||
@@ -1311,27 +1330,41 @@ class ClientMessageProcessor(CommonCommandProcessor):
|
|||||||
"Sorry, !remaining requires you to have beaten the game on this server")
|
"Sorry, !remaining requires you to have beaten the game on this server")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _cmd_missing(self) -> bool:
|
def _cmd_missing(self, filter_text="") -> bool:
|
||||||
"""List all missing location checks from the server's perspective"""
|
"""List all missing location checks from the server's perspective.
|
||||||
|
Can be given text, which will be used as filter."""
|
||||||
|
|
||||||
locations = get_missing_checks(self.ctx, self.client.team, self.client.slot)
|
locations = get_missing_checks(self.ctx, self.client.team, self.client.slot)
|
||||||
|
|
||||||
if locations:
|
if locations:
|
||||||
texts = [f'Missing: {self.ctx.location_names[location]}' for location in locations]
|
names = [self.ctx.location_names[location] for location in locations]
|
||||||
texts.append(f"Found {len(locations)} missing location checks")
|
if filter_text:
|
||||||
|
names = [name for name in names if filter_text in name]
|
||||||
|
texts = [f'Missing: {name}' for name in names]
|
||||||
|
if filter_text:
|
||||||
|
texts.append(f"Found {len(locations)} missing location checks, displaying {len(names)} of them.")
|
||||||
|
else:
|
||||||
|
texts.append(f"Found {len(locations)} missing location checks")
|
||||||
self.output_multiple(texts)
|
self.output_multiple(texts)
|
||||||
else:
|
else:
|
||||||
self.output("No missing location checks found.")
|
self.output("No missing location checks found.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _cmd_checked(self) -> bool:
|
def _cmd_checked(self, filter_text="") -> bool:
|
||||||
"""List all done location checks from the server's perspective"""
|
"""List all done location checks from the server's perspective.
|
||||||
|
Can be given text, which will be used as filter."""
|
||||||
|
|
||||||
locations = get_checked_checks(self.ctx, self.client.team, self.client.slot)
|
locations = get_checked_checks(self.ctx, self.client.team, self.client.slot)
|
||||||
|
|
||||||
if locations:
|
if locations:
|
||||||
texts = [f'Checked: {self.ctx.location_names[location]}' for location in locations]
|
names = [self.ctx.location_names[location] for location in locations]
|
||||||
texts.append(f"Found {len(locations)} done location checks")
|
if filter_text:
|
||||||
|
names = [name for name in names if filter_text in name]
|
||||||
|
texts = [f'Checked: {name}' for name in names]
|
||||||
|
if filter_text:
|
||||||
|
texts.append(f"Found {len(locations)} done location checks, displaying {len(names)} of them.")
|
||||||
|
else:
|
||||||
|
texts.append(f"Found {len(locations)} done location checks")
|
||||||
self.output_multiple(texts)
|
self.output_multiple(texts)
|
||||||
else:
|
else:
|
||||||
self.output("No done location checks found.")
|
self.output("No done location checks found.")
|
||||||
@@ -1610,7 +1643,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
|
|||||||
"players": ctx.get_players_package(),
|
"players": ctx.get_players_package(),
|
||||||
"missing_locations": get_missing_checks(ctx, team, slot),
|
"missing_locations": get_missing_checks(ctx, team, slot),
|
||||||
"checked_locations": get_checked_checks(ctx, team, slot),
|
"checked_locations": get_checked_checks(ctx, team, slot),
|
||||||
"slot_info": ctx.slot_info
|
"slot_info": ctx.slot_info,
|
||||||
|
"hint_points": get_slot_points(ctx, team, slot),
|
||||||
}
|
}
|
||||||
reply = [connected_packet]
|
reply = [connected_packet]
|
||||||
start_inventory = get_start_inventory(ctx, slot, client.remote_start_inventory)
|
start_inventory = get_start_inventory(ctx, slot, client.remote_start_inventory)
|
||||||
@@ -1712,6 +1746,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
|
|||||||
hints.extend(collect_hint_location_id(ctx, client.team, client.slot, location))
|
hints.extend(collect_hint_location_id(ctx, client.team, client.slot, location))
|
||||||
locs.append(NetworkItem(target_item, location, target_player, flags))
|
locs.append(NetworkItem(target_item, location, target_player, flags))
|
||||||
ctx.notify_hints(client.team, hints, only_new=create_as_hint == 2)
|
ctx.notify_hints(client.team, hints, only_new=create_as_hint == 2)
|
||||||
|
if locs and create_as_hint:
|
||||||
|
ctx.save()
|
||||||
await ctx.send_msgs(client, [{'cmd': 'LocationInfo', 'locations': locs}])
|
await ctx.send_msgs(client, [{'cmd': 'LocationInfo', 'locations': locs}])
|
||||||
|
|
||||||
elif cmd == 'StatusUpdate':
|
elif cmd == 'StatusUpdate':
|
||||||
@@ -1770,6 +1806,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
|
|||||||
targets.add(client)
|
targets.add(client)
|
||||||
if targets:
|
if targets:
|
||||||
ctx.broadcast(targets, [args])
|
ctx.broadcast(targets, [args])
|
||||||
|
ctx.save()
|
||||||
|
|
||||||
elif cmd == "SetNotify":
|
elif cmd == "SetNotify":
|
||||||
if "keys" not in args or type(args["keys"]) != list:
|
if "keys" not in args or type(args["keys"]) != list:
|
||||||
@@ -1787,6 +1824,7 @@ def update_client_status(ctx: Context, client: Client, new_status: ClientStatus)
|
|||||||
ctx.on_goal_achieved(client)
|
ctx.on_goal_achieved(client)
|
||||||
|
|
||||||
ctx.client_game_state[client.team, client.slot] = new_status
|
ctx.client_game_state[client.team, client.slot] = new_status
|
||||||
|
ctx.save()
|
||||||
|
|
||||||
|
|
||||||
class ServerCommandProcessor(CommonCommandProcessor):
|
class ServerCommandProcessor(CommonCommandProcessor):
|
||||||
@@ -1827,7 +1865,7 @@ class ServerCommandProcessor(CommonCommandProcessor):
|
|||||||
|
|
||||||
def _cmd_exit(self) -> bool:
|
def _cmd_exit(self) -> bool:
|
||||||
"""Shutdown the server"""
|
"""Shutdown the server"""
|
||||||
async_start(self.ctx.server.ws_server._close())
|
self.ctx.server.ws_server.close()
|
||||||
if self.ctx.shutdown_task:
|
if self.ctx.shutdown_task:
|
||||||
self.ctx.shutdown_task.cancel()
|
self.ctx.shutdown_task.cancel()
|
||||||
self.ctx.exit_event.set()
|
self.ctx.exit_event.set()
|
||||||
@@ -2168,7 +2206,7 @@ async def auto_shutdown(ctx, to_cancel=None):
|
|||||||
await asyncio.sleep(ctx.auto_shutdown)
|
await asyncio.sleep(ctx.auto_shutdown)
|
||||||
while not ctx.exit_event.is_set():
|
while not ctx.exit_event.is_set():
|
||||||
if not ctx.client_activity_timers.values():
|
if not ctx.client_activity_timers.values():
|
||||||
async_start(ctx.server.ws_server._close())
|
ctx.server.ws_server.close()
|
||||||
ctx.exit_event.set()
|
ctx.exit_event.set()
|
||||||
if to_cancel:
|
if to_cancel:
|
||||||
for task in to_cancel:
|
for task in to_cancel:
|
||||||
@@ -2179,7 +2217,7 @@ async def auto_shutdown(ctx, to_cancel=None):
|
|||||||
delta = datetime.datetime.now(datetime.timezone.utc) - newest_activity
|
delta = datetime.datetime.now(datetime.timezone.utc) - newest_activity
|
||||||
seconds = ctx.auto_shutdown - delta.total_seconds()
|
seconds = ctx.auto_shutdown - delta.total_seconds()
|
||||||
if seconds < 0:
|
if seconds < 0:
|
||||||
async_start(ctx.server.ws_server._close())
|
ctx.server.ws_server.close()
|
||||||
ctx.exit_event.set()
|
ctx.exit_event.set()
|
||||||
if to_cancel:
|
if to_cancel:
|
||||||
for task in to_cancel:
|
for task in to_cancel:
|
||||||
@@ -2234,8 +2272,7 @@ async def main(args: argparse.Namespace):
|
|||||||
|
|
||||||
ssl_context = load_server_cert(args.cert, args.cert_key) if args.cert else None
|
ssl_context = load_server_cert(args.cert, args.cert_key) if args.cert else None
|
||||||
|
|
||||||
ctx.server = websockets.serve(functools.partial(server, ctx=ctx), host=ctx.host, port=ctx.port, ping_timeout=None,
|
ctx.server = websockets.serve(functools.partial(server, ctx=ctx), host=ctx.host, port=ctx.port, ssl=ssl_context)
|
||||||
ping_interval=None, ssl=ssl_context)
|
|
||||||
ip = args.host if args.host else Utils.get_public_ipv4()
|
ip = args.host if args.host else Utils.get_public_ipv4()
|
||||||
logging.info('Hosting game at %s:%d (%s)' % (ip, ctx.port,
|
logging.info('Hosting game at %s:%d (%s)' % (ip, ctx.port,
|
||||||
'No password' if not ctx.password else 'Password: %s' % ctx.password))
|
'No password' if not ctx.password else 'Password: %s' % ctx.password))
|
||||||
|
|||||||
10
NetUtils.py
@@ -6,7 +6,7 @@ from json import JSONEncoder, JSONDecoder
|
|||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
from Utils import Version
|
from Utils import ByValue, Version
|
||||||
|
|
||||||
|
|
||||||
class JSONMessagePart(typing.TypedDict, total=False):
|
class JSONMessagePart(typing.TypedDict, total=False):
|
||||||
@@ -20,7 +20,7 @@ class JSONMessagePart(typing.TypedDict, total=False):
|
|||||||
flags: int
|
flags: int
|
||||||
|
|
||||||
|
|
||||||
class ClientStatus(enum.IntEnum):
|
class ClientStatus(ByValue, enum.IntEnum):
|
||||||
CLIENT_UNKNOWN = 0
|
CLIENT_UNKNOWN = 0
|
||||||
CLIENT_CONNECTED = 5
|
CLIENT_CONNECTED = 5
|
||||||
CLIENT_READY = 10
|
CLIENT_READY = 10
|
||||||
@@ -28,18 +28,18 @@ class ClientStatus(enum.IntEnum):
|
|||||||
CLIENT_GOAL = 30
|
CLIENT_GOAL = 30
|
||||||
|
|
||||||
|
|
||||||
class SlotType(enum.IntFlag):
|
class SlotType(ByValue, enum.IntFlag):
|
||||||
spectator = 0b00
|
spectator = 0b00
|
||||||
player = 0b01
|
player = 0b01
|
||||||
group = 0b10
|
group = 0b10
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def always_goal(self) -> bool:
|
def always_goal(self) -> bool:
|
||||||
"""Mark this slot has having reached its goal instantly."""
|
"""Mark this slot as having reached its goal instantly."""
|
||||||
return self.value != 0b01
|
return self.value != 0b01
|
||||||
|
|
||||||
|
|
||||||
class Permission(enum.IntFlag):
|
class Permission(ByValue, enum.IntFlag):
|
||||||
disabled = 0b000 # 0, completely disables access
|
disabled = 0b000 # 0, completely disables access
|
||||||
enabled = 0b001 # 1, allows manual use
|
enabled = 0b001 # 1, allows manual use
|
||||||
goal = 0b010 # 2, allows manual use after goal completion
|
goal = 0b010 # 2, allows manual use after goal completion
|
||||||
|
|||||||
30
OoTClient.py
@@ -17,9 +17,9 @@ from worlds.oot.N64Patch import apply_patch_file
|
|||||||
from worlds.oot.Utils import data_path
|
from worlds.oot.Utils import data_path
|
||||||
|
|
||||||
|
|
||||||
CONNECTION_TIMING_OUT_STATUS = "Connection timing out. Please restart your emulator, then restart oot_connector.lua"
|
CONNECTION_TIMING_OUT_STATUS = "Connection timing out. Please restart your emulator, then restart connector_oot.lua"
|
||||||
CONNECTION_REFUSED_STATUS = "Connection refused. Please start your emulator and make sure oot_connector.lua is running"
|
CONNECTION_REFUSED_STATUS = "Connection refused. Please start your emulator and make sure connector_oot.lua is running"
|
||||||
CONNECTION_RESET_STATUS = "Connection was reset. Please restart your emulator, then restart oot_connector.lua"
|
CONNECTION_RESET_STATUS = "Connection was reset. Please restart your emulator, then restart connector_oot.lua"
|
||||||
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
||||||
CONNECTION_CONNECTED_STATUS = "Connected"
|
CONNECTION_CONNECTED_STATUS = "Connected"
|
||||||
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
||||||
@@ -179,6 +179,12 @@ async def parse_payload(payload: dict, ctx: OoTContext, force: bool):
|
|||||||
locations = payload['locations']
|
locations = payload['locations']
|
||||||
collectibles = payload['collectibles']
|
collectibles = payload['collectibles']
|
||||||
|
|
||||||
|
# The Lua JSON library serializes an empty table into a list instead of a dict. Verify types for safety:
|
||||||
|
if isinstance(locations, list):
|
||||||
|
locations = {}
|
||||||
|
if isinstance(collectibles, list):
|
||||||
|
collectibles = {}
|
||||||
|
|
||||||
if ctx.location_table != locations or ctx.collectible_table != collectibles:
|
if ctx.location_table != locations or ctx.collectible_table != collectibles:
|
||||||
ctx.location_table = locations
|
ctx.location_table = locations
|
||||||
ctx.collectible_table = collectibles
|
ctx.collectible_table = collectibles
|
||||||
@@ -289,11 +295,19 @@ async def patch_and_run_game(apz5_file):
|
|||||||
decomp_path = base_name + '-decomp.z64'
|
decomp_path = base_name + '-decomp.z64'
|
||||||
comp_path = base_name + '.z64'
|
comp_path = base_name + '.z64'
|
||||||
# Load vanilla ROM, patch file, compress ROM
|
# Load vanilla ROM, patch file, compress ROM
|
||||||
rom = Rom(Utils.local_path(Utils.get_options()["oot_options"]["rom_file"]))
|
rom_file_name = Utils.get_options()["oot_options"]["rom_file"]
|
||||||
apply_patch_file(rom, apz5_file,
|
if not os.path.exists(rom_file_name):
|
||||||
sub_file=(os.path.basename(base_name) + '.zpf'
|
rom_file_name = Utils.user_path(rom_file_name)
|
||||||
if zipfile.is_zipfile(apz5_file)
|
rom = Rom(rom_file_name)
|
||||||
else None))
|
|
||||||
|
sub_file = None
|
||||||
|
if zipfile.is_zipfile(apz5_file):
|
||||||
|
for name in zipfile.ZipFile(apz5_file).namelist():
|
||||||
|
if name.endswith('.zpf'):
|
||||||
|
sub_file = name
|
||||||
|
break
|
||||||
|
|
||||||
|
apply_patch_file(rom, apz5_file, sub_file=sub_file)
|
||||||
rom.write_to_file(decomp_path)
|
rom.write_to_file(decomp_path)
|
||||||
os.chdir(data_path("Compress"))
|
os.chdir(data_path("Compress"))
|
||||||
compress_rom_file(decomp_path, comp_path)
|
compress_rom_file(decomp_path, comp_path)
|
||||||
|
|||||||
87
Options.py
@@ -13,6 +13,7 @@ from Utils import get_fuzzy_results
|
|||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from BaseClasses import PlandoOptions
|
from BaseClasses import PlandoOptions
|
||||||
from worlds.AutoWorld import World
|
from worlds.AutoWorld import World
|
||||||
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
class AssembleOptions(abc.ABCMeta):
|
class AssembleOptions(abc.ABCMeta):
|
||||||
@@ -715,8 +716,16 @@ class SpecialRange(Range):
|
|||||||
f"random-range-high-<min>-<max>, or random-range-<min>-<max>.")
|
f"random-range-high-<min>-<max>, or random-range-<min>-<max>.")
|
||||||
|
|
||||||
|
|
||||||
class VerifyKeys:
|
class FreezeValidKeys(AssembleOptions):
|
||||||
valid_keys = frozenset()
|
def __new__(mcs, name, bases, attrs):
|
||||||
|
if "valid_keys" in attrs:
|
||||||
|
attrs["_valid_keys"] = frozenset(attrs["valid_keys"])
|
||||||
|
return super(FreezeValidKeys, mcs).__new__(mcs, name, bases, attrs)
|
||||||
|
|
||||||
|
|
||||||
|
class VerifyKeys(metaclass=FreezeValidKeys):
|
||||||
|
valid_keys: typing.Iterable = []
|
||||||
|
_valid_keys: frozenset # gets created by AssembleOptions from valid_keys
|
||||||
valid_keys_casefold: bool = False
|
valid_keys_casefold: bool = False
|
||||||
convert_name_groups: bool = False
|
convert_name_groups: bool = False
|
||||||
verify_item_name: bool = False
|
verify_item_name: bool = False
|
||||||
@@ -728,10 +737,10 @@ class VerifyKeys:
|
|||||||
if cls.valid_keys:
|
if cls.valid_keys:
|
||||||
data = set(data)
|
data = set(data)
|
||||||
dataset = set(word.casefold() for word in data) if cls.valid_keys_casefold else set(data)
|
dataset = set(word.casefold() for word in data) if cls.valid_keys_casefold else set(data)
|
||||||
extra = dataset - cls.valid_keys
|
extra = dataset - cls._valid_keys
|
||||||
if extra:
|
if extra:
|
||||||
raise Exception(f"Found unexpected key {', '.join(extra)} in {cls}. "
|
raise Exception(f"Found unexpected key {', '.join(extra)} in {cls}. "
|
||||||
f"Allowed keys: {cls.valid_keys}.")
|
f"Allowed keys: {cls._valid_keys}.")
|
||||||
|
|
||||||
def verify(self, world: typing.Type[World], player_name: str, plando_options: "PlandoOptions") -> None:
|
def verify(self, world: typing.Type[World], player_name: str, plando_options: "PlandoOptions") -> None:
|
||||||
if self.convert_name_groups and self.verify_item_name:
|
if self.convert_name_groups and self.verify_item_name:
|
||||||
@@ -792,6 +801,10 @@ class ItemDict(OptionDict):
|
|||||||
|
|
||||||
|
|
||||||
class OptionList(Option[typing.List[typing.Any]], VerifyKeys):
|
class OptionList(Option[typing.List[typing.Any]], VerifyKeys):
|
||||||
|
# Supports duplicate entries and ordering.
|
||||||
|
# If only unique entries are needed and input order of elements does not matter, OptionSet should be used instead.
|
||||||
|
# Not a docstring so it doesn't get grabbed by the options system.
|
||||||
|
|
||||||
default: typing.List[typing.Any] = []
|
default: typing.List[typing.Any] = []
|
||||||
supports_weighting = False
|
supports_weighting = False
|
||||||
|
|
||||||
@@ -897,6 +910,13 @@ class StartInventory(ItemDict):
|
|||||||
display_name = "Start Inventory"
|
display_name = "Start Inventory"
|
||||||
|
|
||||||
|
|
||||||
|
class StartInventoryPool(StartInventory):
|
||||||
|
"""Start with these items and don't place them in the world.
|
||||||
|
The game decides what the replacement items will be."""
|
||||||
|
verify_item_name = True
|
||||||
|
display_name = "Start Inventory from Pool"
|
||||||
|
|
||||||
|
|
||||||
class StartHints(ItemSet):
|
class StartHints(ItemSet):
|
||||||
"""Start with these item's locations prefilled into the !hint command."""
|
"""Start with these item's locations prefilled into the !hint command."""
|
||||||
display_name = "Start Hints"
|
display_name = "Start Hints"
|
||||||
@@ -904,6 +924,7 @@ class StartHints(ItemSet):
|
|||||||
|
|
||||||
class LocationSet(OptionSet):
|
class LocationSet(OptionSet):
|
||||||
verify_location_name = True
|
verify_location_name = True
|
||||||
|
convert_name_groups = True
|
||||||
|
|
||||||
|
|
||||||
class StartLocationHints(LocationSet):
|
class StartLocationHints(LocationSet):
|
||||||
@@ -1002,6 +1023,64 @@ per_game_common_options = {
|
|||||||
"item_links": ItemLinks
|
"item_links": ItemLinks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def generate_yaml_templates(target_folder: typing.Union[str, "pathlib.Path"], generate_hidden: bool = True):
|
||||||
|
import os
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
from jinja2 import Template
|
||||||
|
|
||||||
|
from worlds import AutoWorldRegister
|
||||||
|
from Utils import local_path, __version__
|
||||||
|
|
||||||
|
full_path: str
|
||||||
|
|
||||||
|
os.makedirs(target_folder, exist_ok=True)
|
||||||
|
|
||||||
|
# clean out old
|
||||||
|
for file in os.listdir(target_folder):
|
||||||
|
full_path = os.path.join(target_folder, file)
|
||||||
|
if os.path.isfile(full_path) and full_path.endswith(".yaml"):
|
||||||
|
os.unlink(full_path)
|
||||||
|
|
||||||
|
def dictify_range(option: typing.Union[Range, SpecialRange]):
|
||||||
|
data = {option.default: 50}
|
||||||
|
for sub_option in ["random", "random-low", "random-high"]:
|
||||||
|
if sub_option != option.default:
|
||||||
|
data[sub_option] = 0
|
||||||
|
|
||||||
|
notes = {}
|
||||||
|
for name, number in getattr(option, "special_range_names", {}).items():
|
||||||
|
notes[name] = f"equivalent to {number}"
|
||||||
|
if number in data:
|
||||||
|
data[name] = data[number]
|
||||||
|
del data[number]
|
||||||
|
else:
|
||||||
|
data[name] = 0
|
||||||
|
|
||||||
|
return data, notes
|
||||||
|
|
||||||
|
for game_name, world in AutoWorldRegister.world_types.items():
|
||||||
|
if not world.hidden or generate_hidden:
|
||||||
|
all_options: typing.Dict[str, AssembleOptions] = {
|
||||||
|
**per_game_common_options,
|
||||||
|
**world.option_definitions
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(local_path("data", "options.yaml")) as f:
|
||||||
|
file_data = f.read()
|
||||||
|
res = Template(file_data).render(
|
||||||
|
options=all_options,
|
||||||
|
__version__=__version__, game=game_name, yaml_dump=yaml.dump,
|
||||||
|
dictify_range=dictify_range,
|
||||||
|
)
|
||||||
|
|
||||||
|
del file_data
|
||||||
|
|
||||||
|
with open(os.path.join(target_folder, game_name + ".yaml"), "w", encoding="utf-8-sig") as f:
|
||||||
|
f.write(res)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
from worlds.alttp.Options import Logic
|
from worlds.alttp.Options import Logic
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ Currently, the following games are supported:
|
|||||||
* Stardew Valley
|
* Stardew Valley
|
||||||
* The Legend of Zelda
|
* The Legend of Zelda
|
||||||
* The Messenger
|
* The Messenger
|
||||||
|
* Kingdom Hearts 2
|
||||||
|
* The Legend of Zelda: Link's Awakening DX
|
||||||
|
* Clique
|
||||||
|
* Adventure
|
||||||
|
* DLC Quest
|
||||||
|
* Noita
|
||||||
|
|
||||||
For setup and instructions check out our [tutorials page](https://archipelago.gg/tutorial/).
|
For setup and instructions check out our [tutorials page](https://archipelago.gg/tutorial/).
|
||||||
Downloads can be found at [Releases](https://github.com/ArchipelagoMW/Archipelago/releases), including compiled
|
Downloads can be found at [Releases](https://github.com/ArchipelagoMW/Archipelago/releases), including compiled
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ class SNIClientCommandProcessor(ClientCommandProcessor):
|
|||||||
|
|
||||||
class SNIContext(CommonContext):
|
class SNIContext(CommonContext):
|
||||||
command_processor: typing.Type[SNIClientCommandProcessor] = SNIClientCommandProcessor
|
command_processor: typing.Type[SNIClientCommandProcessor] = SNIClientCommandProcessor
|
||||||
game = None # set in validate_rom
|
game: typing.Optional[str] = None # set in validate_rom
|
||||||
items_handling = None # set in game_watcher
|
items_handling: typing.Optional[int] = None # set in game_watcher
|
||||||
snes_connect_task: "typing.Optional[asyncio.Task[None]]" = None
|
snes_connect_task: "typing.Optional[asyncio.Task[None]]" = None
|
||||||
snes_autoreconnect_task: typing.Optional["asyncio.Task[None]"] = None
|
snes_autoreconnect_task: typing.Optional["asyncio.Task[None]"] = None
|
||||||
|
|
||||||
|
|||||||
81
Utils.py
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
import typing
|
import typing
|
||||||
import builtins
|
import builtins
|
||||||
import os
|
import os
|
||||||
@@ -37,8 +38,11 @@ class Version(typing.NamedTuple):
|
|||||||
minor: int
|
minor: int
|
||||||
build: int
|
build: int
|
||||||
|
|
||||||
|
def as_simple_string(self) -> str:
|
||||||
|
return ".".join(str(item) for item in self)
|
||||||
|
|
||||||
__version__ = "0.3.9"
|
|
||||||
|
__version__ = "0.4.1"
|
||||||
version_tuple = tuplize_version(__version__)
|
version_tuple = tuplize_version(__version__)
|
||||||
|
|
||||||
is_linux = sys.platform.startswith("linux")
|
is_linux = sys.platform.startswith("linux")
|
||||||
@@ -87,7 +91,10 @@ def is_frozen() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def local_path(*path: str) -> str:
|
def local_path(*path: str) -> str:
|
||||||
"""Returns path to a file in the local Archipelago installation or source."""
|
"""
|
||||||
|
Returns path to a file in the local Archipelago installation or source.
|
||||||
|
This might be read-only and user_path should be used instead for ROMs, configuration, etc.
|
||||||
|
"""
|
||||||
if hasattr(local_path, 'cached_path'):
|
if hasattr(local_path, 'cached_path'):
|
||||||
pass
|
pass
|
||||||
elif is_frozen():
|
elif is_frozen():
|
||||||
@@ -142,6 +149,17 @@ def user_path(*path: str) -> str:
|
|||||||
return os.path.join(user_path.cached_path, *path)
|
return os.path.join(user_path.cached_path, *path)
|
||||||
|
|
||||||
|
|
||||||
|
def cache_path(*path: str) -> str:
|
||||||
|
"""Returns path to a file in the user's Archipelago cache directory."""
|
||||||
|
if hasattr(cache_path, "cached_path"):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
import platformdirs
|
||||||
|
cache_path.cached_path = platformdirs.user_cache_dir("Archipelago", False)
|
||||||
|
|
||||||
|
return os.path.join(cache_path.cached_path, *path)
|
||||||
|
|
||||||
|
|
||||||
def output_path(*path: str) -> str:
|
def output_path(*path: str) -> str:
|
||||||
if hasattr(output_path, 'cached_path'):
|
if hasattr(output_path, 'cached_path'):
|
||||||
return os.path.join(output_path.cached_path, *path)
|
return os.path.join(output_path.cached_path, *path)
|
||||||
@@ -248,6 +266,9 @@ def get_default_options() -> OptionsType:
|
|||||||
"lttp_options": {
|
"lttp_options": {
|
||||||
"rom_file": "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc",
|
"rom_file": "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc",
|
||||||
},
|
},
|
||||||
|
"ladx_options": {
|
||||||
|
"rom_file": "Legend of Zelda, The - Link's Awakening DX (USA, Europe) (SGB Enhanced).gbc",
|
||||||
|
},
|
||||||
"server_options": {
|
"server_options": {
|
||||||
"host": None,
|
"host": None,
|
||||||
"port": 38281,
|
"port": 38281,
|
||||||
@@ -317,7 +338,13 @@ def get_default_options() -> OptionsType:
|
|||||||
},
|
},
|
||||||
"wargroove_options": {
|
"wargroove_options": {
|
||||||
"root_directory": "C:/Program Files (x86)/Steam/steamapps/common/Wargroove"
|
"root_directory": "C:/Program Files (x86)/Steam/steamapps/common/Wargroove"
|
||||||
}
|
},
|
||||||
|
"adventure_options": {
|
||||||
|
"rom_file": "ADVNTURE.BIN",
|
||||||
|
"display_msgs": True,
|
||||||
|
"rom_start": True,
|
||||||
|
"rom_args": ""
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
|
|
||||||
@@ -385,6 +412,45 @@ def persistent_load() -> typing.Dict[str, dict]:
|
|||||||
return storage
|
return storage
|
||||||
|
|
||||||
|
|
||||||
|
def get_file_safe_name(name: str) -> str:
|
||||||
|
return "".join(c for c in name if c not in '<>:"/\\|?*')
|
||||||
|
|
||||||
|
|
||||||
|
def load_data_package_for_checksum(game: str, checksum: typing.Optional[str]) -> Dict[str, Any]:
|
||||||
|
if checksum and game:
|
||||||
|
if checksum != get_file_safe_name(checksum):
|
||||||
|
raise ValueError(f"Bad symbols in checksum: {checksum}")
|
||||||
|
path = cache_path("datapackage", get_file_safe_name(game), f"{checksum}.json")
|
||||||
|
if os.path.exists(path):
|
||||||
|
try:
|
||||||
|
with open(path, "r", encoding="utf-8-sig") as f:
|
||||||
|
return json.load(f)
|
||||||
|
except Exception as e:
|
||||||
|
logging.debug(f"Could not load data package: {e}")
|
||||||
|
|
||||||
|
# fall back to old cache
|
||||||
|
cache = persistent_load().get("datapackage", {}).get("games", {}).get(game, {})
|
||||||
|
if cache.get("checksum") == checksum:
|
||||||
|
return cache
|
||||||
|
|
||||||
|
# cache does not match
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def store_data_package_for_checksum(game: str, data: typing.Dict[str, Any]) -> None:
|
||||||
|
checksum = data.get("checksum")
|
||||||
|
if checksum and game:
|
||||||
|
if checksum != get_file_safe_name(checksum):
|
||||||
|
raise ValueError(f"Bad symbols in checksum: {checksum}")
|
||||||
|
game_folder = cache_path("datapackage", get_file_safe_name(game))
|
||||||
|
os.makedirs(game_folder, exist_ok=True)
|
||||||
|
try:
|
||||||
|
with open(os.path.join(game_folder, f"{checksum}.json"), "w", encoding="utf-8-sig") as f:
|
||||||
|
json.dump(data, f, ensure_ascii=False, separators=(",", ":"))
|
||||||
|
except Exception as e:
|
||||||
|
logging.debug(f"Could not store data package: {e}")
|
||||||
|
|
||||||
|
|
||||||
def get_adjuster_settings(game_name: str) -> typing.Dict[str, typing.Any]:
|
def get_adjuster_settings(game_name: str) -> typing.Dict[str, typing.Any]:
|
||||||
adjuster_settings = persistent_load().get("adjuster", {}).get(game_name, {})
|
adjuster_settings = persistent_load().get("adjuster", {}).get(game_name, {})
|
||||||
return adjuster_settings
|
return adjuster_settings
|
||||||
@@ -442,6 +508,15 @@ def restricted_loads(s):
|
|||||||
return RestrictedUnpickler(io.BytesIO(s)).load()
|
return RestrictedUnpickler(io.BytesIO(s)).load()
|
||||||
|
|
||||||
|
|
||||||
|
class ByValue:
|
||||||
|
"""
|
||||||
|
Mixin for enums to pickle value instead of name (restores pre-3.11 behavior). Use as left-most parent.
|
||||||
|
See https://github.com/python/cpython/pull/26658 for why this exists.
|
||||||
|
"""
|
||||||
|
def __reduce_ex__(self, prot):
|
||||||
|
return self.__class__, (self._value_, )
|
||||||
|
|
||||||
|
|
||||||
class KeyedDefaultDict(collections.defaultdict):
|
class KeyedDefaultDict(collections.defaultdict):
|
||||||
"""defaultdict variant that uses the missing key as argument to default_factory"""
|
"""defaultdict variant that uses the missing key as argument to default_factory"""
|
||||||
default_factory: typing.Callable[[typing.Any], typing.Any]
|
default_factory: typing.Callable[[typing.Any], typing.Any]
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ app.config['MAX_CONTENT_LENGTH'] = 64 * 1024 * 1024 # 64 megabyte limit
|
|||||||
# if you want to deploy, make sure you have a non-guessable secret key
|
# if you want to deploy, make sure you have a non-guessable secret key
|
||||||
app.config["SECRET_KEY"] = bytes(socket.gethostname(), encoding="utf-8")
|
app.config["SECRET_KEY"] = bytes(socket.gethostname(), encoding="utf-8")
|
||||||
# at what amount of worlds should scheduling be used, instead of rolling in the web-thread
|
# at what amount of worlds should scheduling be used, instead of rolling in the web-thread
|
||||||
app.config["JOB_THRESHOLD"] = 2
|
app.config["JOB_THRESHOLD"] = 1
|
||||||
# after what time in seconds should generation be aborted, freeing the queue slot. Can be set to None to disable.
|
# after what time in seconds should generation be aborted, freeing the queue slot. Can be set to None to disable.
|
||||||
app.config["JOB_TIME"] = 600
|
app.config["JOB_TIME"] = 600
|
||||||
app.config['SESSION_PERMANENT'] = True
|
app.config['SESSION_PERMANENT'] = True
|
||||||
|
|||||||
@@ -39,12 +39,21 @@ def get_datapackage():
|
|||||||
|
|
||||||
@api_endpoints.route('/datapackage_version')
|
@api_endpoints.route('/datapackage_version')
|
||||||
@cache.cached()
|
@cache.cached()
|
||||||
|
|
||||||
def get_datapackage_versions():
|
def get_datapackage_versions():
|
||||||
from worlds import network_data_package, AutoWorldRegister
|
from worlds import AutoWorldRegister
|
||||||
|
|
||||||
version_package = {game: world.data_version for game, world in AutoWorldRegister.world_types.items()}
|
version_package = {game: world.data_version for game, world in AutoWorldRegister.world_types.items()}
|
||||||
return version_package
|
return version_package
|
||||||
|
|
||||||
|
|
||||||
|
@api_endpoints.route('/datapackage_checksum')
|
||||||
|
@cache.cached()
|
||||||
|
def get_datapackage_checksums():
|
||||||
|
from worlds import network_data_package
|
||||||
|
version_package = {
|
||||||
|
game: game_data["checksum"] for game, game_data in network_data_package["games"].items()
|
||||||
|
}
|
||||||
|
return version_package
|
||||||
|
|
||||||
|
|
||||||
from . import generate, user # trigger registration
|
from . import generate, user # trigger registration
|
||||||
|
|||||||
@@ -48,9 +48,8 @@ def generate_api():
|
|||||||
if len(options) > app.config["MAX_ROLL"]:
|
if len(options) > app.config["MAX_ROLL"]:
|
||||||
return {"text": "Max size of multiworld exceeded",
|
return {"text": "Max size of multiworld exceeded",
|
||||||
"detail": app.config["MAX_ROLL"]}, 409
|
"detail": app.config["MAX_ROLL"]}, 409
|
||||||
meta = get_meta(meta_options_source)
|
meta = get_meta(meta_options_source, race)
|
||||||
meta["race"] = race
|
results, gen_options = roll_options(options, set(meta["plando_options"]))
|
||||||
results, gen_options = roll_options(options, meta["plando_options"])
|
|
||||||
if any(type(result) == str for result in results.values()):
|
if any(type(result) == str for result in results.values()):
|
||||||
return {"text": str(results),
|
return {"text": str(results),
|
||||||
"detail": results}, 400
|
"detail": results}, 400
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ def autogen(config: dict):
|
|||||||
with Locker("autogen"):
|
with Locker("autogen"):
|
||||||
|
|
||||||
with multiprocessing.Pool(config["GENERATORS"], initializer=init_db,
|
with multiprocessing.Pool(config["GENERATORS"], initializer=init_db,
|
||||||
initargs=(config["PONY"],)) as generator_pool:
|
initargs=(config["PONY"],), maxtasksperchild=10) as generator_pool:
|
||||||
with db_session:
|
with db_session:
|
||||||
to_start = select(generation for generation in Generation if generation.state == STATE_STARTED)
|
to_start = select(generation for generation in Generation if generation.state == STATE_STARTED)
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,12 @@ def get_yaml_data(file) -> Union[Dict[str, str], str, Markup]:
|
|||||||
|
|
||||||
if any(file.filename.endswith(".archipelago") for file in infolist):
|
if any(file.filename.endswith(".archipelago") for file in infolist):
|
||||||
return Markup("Error: Your .zip file contains an .archipelago file. "
|
return Markup("Error: Your .zip file contains an .archipelago file. "
|
||||||
'Did you mean to <a href="/uploads">host a game</a>?')
|
'Did you mean to <a href="/uploads">host a game</a>?')
|
||||||
|
|
||||||
for file in infolist:
|
for file in infolist:
|
||||||
if file.filename.endswith(banned_zip_contents):
|
if file.filename.endswith(banned_zip_contents):
|
||||||
return "Uploaded data contained a rom file, which is likely to contain copyrighted material. Your file was deleted."
|
return "Uploaded data contained a rom file, which is likely to contain copyrighted material. " \
|
||||||
|
"Your file was deleted."
|
||||||
elif file.filename.endswith((".yaml", ".json", ".yml", ".txt")):
|
elif file.filename.endswith((".yaml", ".json", ".yml", ".txt")):
|
||||||
options[file.filename] = zfile.open(file, "r").read()
|
options[file.filename] = zfile.open(file, "r").read()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import Utils
|
|||||||
|
|
||||||
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor, ClientMessageProcessor, load_server_cert
|
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor, ClientMessageProcessor, load_server_cert
|
||||||
from Utils import get_public_ipv4, get_public_ipv6, restricted_loads, cache_argsless
|
from Utils import get_public_ipv4, get_public_ipv6, restricted_loads, cache_argsless
|
||||||
from .models import Room, Command, db
|
from .models import Command, GameDataPackage, Room, db
|
||||||
|
|
||||||
|
|
||||||
class CustomClientMessageProcessor(ClientMessageProcessor):
|
class CustomClientMessageProcessor(ClientMessageProcessor):
|
||||||
@@ -92,7 +92,21 @@ class WebHostContext(Context):
|
|||||||
else:
|
else:
|
||||||
self.port = get_random_port()
|
self.port = get_random_port()
|
||||||
|
|
||||||
return self._load(self.decompress(room.seed.multidata), True)
|
multidata = self.decompress(room.seed.multidata)
|
||||||
|
game_data_packages = {}
|
||||||
|
for game in list(multidata.get("datapackage", {})):
|
||||||
|
game_data = multidata["datapackage"][game]
|
||||||
|
if "checksum" in game_data:
|
||||||
|
if self.gamespackage.get(game, {}).get("checksum") == game_data["checksum"]:
|
||||||
|
# non-custom. remove from multidata
|
||||||
|
# games package could be dropped from static data once all rooms embed data package
|
||||||
|
del multidata["datapackage"][game]
|
||||||
|
else:
|
||||||
|
row = GameDataPackage.get(checksum=game_data["checksum"])
|
||||||
|
if row: # None if rolled on >= 0.3.9 but uploaded to <= 0.3.8. multidata should be complete
|
||||||
|
game_data_packages[game] = Utils.restricted_loads(row.data)
|
||||||
|
|
||||||
|
return self._load(multidata, game_data_packages, True)
|
||||||
|
|
||||||
@db_session
|
@db_session
|
||||||
def init_save(self, enabled: bool = True):
|
def init_save(self, enabled: bool = True):
|
||||||
@@ -190,6 +204,11 @@ def run_server_process(room_id, ponyconfig: dict, static_server_data: dict,
|
|||||||
with Locker(room_id):
|
with Locker(room_id):
|
||||||
try:
|
try:
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
with db_session:
|
||||||
|
room = Room.get(id=room_id)
|
||||||
|
# ensure the Room does not spin up again on its own, minute of safety buffer
|
||||||
|
room.last_activity = datetime.datetime.utcnow() - datetime.timedelta(minutes=1, seconds=room.timeout)
|
||||||
except:
|
except:
|
||||||
with db_session:
|
with db_session:
|
||||||
room = Room.get(id=room_id)
|
room = Room.get(id=room_id)
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ def download_slot_file(room_id, player_id: int):
|
|||||||
fname = f"AP_{app.jinja_env.filters['suuid'](room_id)}_SP.apsm64ex"
|
fname = f"AP_{app.jinja_env.filters['suuid'](room_id)}_SP.apsm64ex"
|
||||||
elif slot_data.game == "Dark Souls III":
|
elif slot_data.game == "Dark Souls III":
|
||||||
fname = f"AP_{app.jinja_env.filters['suuid'](room_id)}.json"
|
fname = f"AP_{app.jinja_env.filters['suuid'](room_id)}.json"
|
||||||
|
elif slot_data.game == "Kingdom Hearts 2":
|
||||||
|
fname = f"AP_{app.jinja_env.filters['suuid'](room_id)}_P{slot_data.player_id}_{slot_data.player_name}.zip"
|
||||||
else:
|
else:
|
||||||
return "Game download not supported."
|
return "Game download not supported."
|
||||||
return send_file(io.BytesIO(slot_data.data), as_attachment=True, download_name=fname)
|
return send_file(io.BytesIO(slot_data.data), as_attachment=True, download_name=fname)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import tempfile
|
|||||||
import zipfile
|
import zipfile
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from typing import Dict, Optional, Any
|
from typing import Dict, Optional, Any, Union, List
|
||||||
|
|
||||||
from flask import request, flash, redirect, url_for, session, render_template
|
from flask import request, flash, redirect, url_for, session, render_template
|
||||||
from pony.orm import commit, db_session
|
from pony.orm import commit, db_session
|
||||||
@@ -22,7 +22,7 @@ from .models import Generation, STATE_ERROR, STATE_QUEUED, Seed, UUID
|
|||||||
from .upload import upload_zip_to_db
|
from .upload import upload_zip_to_db
|
||||||
|
|
||||||
|
|
||||||
def get_meta(options_source: dict) -> dict:
|
def get_meta(options_source: dict, race: bool = False) -> Dict[str, Union[List[str], Dict[str, Any]]]:
|
||||||
plando_options = {
|
plando_options = {
|
||||||
options_source.get("plando_bosses", ""),
|
options_source.get("plando_bosses", ""),
|
||||||
options_source.get("plando_items", ""),
|
options_source.get("plando_items", ""),
|
||||||
@@ -39,7 +39,21 @@ def get_meta(options_source: dict) -> dict:
|
|||||||
"item_cheat": bool(int(options_source.get("item_cheat", 1))),
|
"item_cheat": bool(int(options_source.get("item_cheat", 1))),
|
||||||
"server_password": options_source.get("server_password", None),
|
"server_password": options_source.get("server_password", None),
|
||||||
}
|
}
|
||||||
return {"server_options": server_options, "plando_options": list(plando_options)}
|
generator_options = {
|
||||||
|
"spoiler": int(options_source.get("spoiler", 0)),
|
||||||
|
"race": race
|
||||||
|
}
|
||||||
|
|
||||||
|
if race:
|
||||||
|
server_options["item_cheat"] = False
|
||||||
|
server_options["remaining_mode"] = "disabled"
|
||||||
|
generator_options["spoiler"] = 0
|
||||||
|
|
||||||
|
return {
|
||||||
|
"server_options": server_options,
|
||||||
|
"plando_options": list(plando_options),
|
||||||
|
"generator_options": generator_options,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.route('/generate', methods=['GET', 'POST'])
|
@app.route('/generate', methods=['GET', 'POST'])
|
||||||
@@ -55,13 +69,8 @@ def generate(race=False):
|
|||||||
if isinstance(options, str):
|
if isinstance(options, str):
|
||||||
flash(options)
|
flash(options)
|
||||||
else:
|
else:
|
||||||
meta = get_meta(request.form)
|
meta = get_meta(request.form, race)
|
||||||
meta["race"] = race
|
results, gen_options = roll_options(options, set(meta["plando_options"]))
|
||||||
results, gen_options = roll_options(options, meta["plando_options"])
|
|
||||||
|
|
||||||
if race:
|
|
||||||
meta["server_options"]["item_cheat"] = False
|
|
||||||
meta["server_options"]["remaining_mode"] = "disabled"
|
|
||||||
|
|
||||||
if any(type(result) == str for result in results.values()):
|
if any(type(result) == str for result in results.values()):
|
||||||
return render_template("checkResult.html", results=results)
|
return render_template("checkResult.html", results=results)
|
||||||
@@ -97,7 +106,7 @@ def gen_game(gen_options: dict, meta: Optional[Dict[str, Any]] = None, owner=Non
|
|||||||
meta: Dict[str, Any] = {}
|
meta: Dict[str, Any] = {}
|
||||||
|
|
||||||
meta.setdefault("server_options", {}).setdefault("hint_cost", 10)
|
meta.setdefault("server_options", {}).setdefault("hint_cost", 10)
|
||||||
race = meta.setdefault("race", False)
|
race = meta["generator_options"].setdefault("race", False)
|
||||||
|
|
||||||
def task():
|
def task():
|
||||||
target = tempfile.TemporaryDirectory()
|
target = tempfile.TemporaryDirectory()
|
||||||
@@ -114,13 +123,13 @@ def gen_game(gen_options: dict, meta: Optional[Dict[str, Any]] = None, owner=Non
|
|||||||
erargs = parse_arguments(['--multi', str(playercount)])
|
erargs = parse_arguments(['--multi', str(playercount)])
|
||||||
erargs.seed = seed
|
erargs.seed = seed
|
||||||
erargs.name = {x: "" for x in range(1, playercount + 1)} # only so it can be overwritten in mystery
|
erargs.name = {x: "" for x in range(1, playercount + 1)} # only so it can be overwritten in mystery
|
||||||
erargs.spoiler = 0 if race else 3
|
erargs.spoiler = meta["generator_options"]["spoiler"]
|
||||||
erargs.race = race
|
erargs.race = race
|
||||||
erargs.outputname = seedname
|
erargs.outputname = seedname
|
||||||
erargs.outputpath = target.name
|
erargs.outputpath = target.name
|
||||||
erargs.teams = 1
|
erargs.teams = 1
|
||||||
erargs.plando_options = PlandoOptions.from_set(meta.setdefault("plando_options",
|
erargs.plando_options = PlandoOptions.from_set(meta.setdefault("plando_options",
|
||||||
{"bosses", "items", "connections", "texts"}))
|
{"bosses", "items", "connections", "texts"}))
|
||||||
|
|
||||||
name_counter = Counter()
|
name_counter = Counter()
|
||||||
for player, (playerfile, settings) in enumerate(gen_options.items(), 1):
|
for player, (playerfile, settings) in enumerate(gen_options.items(), 1):
|
||||||
|
|||||||
@@ -116,7 +116,11 @@ def display_log(room: UUID):
|
|||||||
if room is None:
|
if room is None:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
if room.owner == session["_id"]:
|
if room.owner == session["_id"]:
|
||||||
return Response(_read_log(os.path.join("logs", str(room.id) + ".txt")), mimetype="text/plain;charset=UTF-8")
|
file_path = os.path.join("logs", str(room.id) + ".txt")
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
return Response(_read_log(file_path), mimetype="text/plain;charset=UTF-8")
|
||||||
|
return "Log File does not exist."
|
||||||
|
|
||||||
return "Access Denied", 403
|
return "Access Denied", 403
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,3 +56,8 @@ class Generation(db.Entity):
|
|||||||
options = Required(buffer, lazy=True)
|
options = Required(buffer, lazy=True)
|
||||||
meta = Required(LongStr, default=lambda: "{\"race\": false}")
|
meta = Required(LongStr, default=lambda: "{\"race\": false}")
|
||||||
state = Required(int, default=0, index=True)
|
state = Required(int, default=0, index=True)
|
||||||
|
|
||||||
|
|
||||||
|
class GameDataPackage(db.Entity):
|
||||||
|
checksum = PrimaryKey(str)
|
||||||
|
data = Required(bytes)
|
||||||
|
|||||||
@@ -11,35 +11,14 @@ from Utils import __version__, local_path
|
|||||||
from worlds.AutoWorld import AutoWorldRegister
|
from worlds.AutoWorld import AutoWorldRegister
|
||||||
|
|
||||||
handled_in_js = {"start_inventory", "local_items", "non_local_items", "start_hints", "start_location_hints",
|
handled_in_js = {"start_inventory", "local_items", "non_local_items", "start_hints", "start_location_hints",
|
||||||
"exclude_locations"}
|
"exclude_locations", "priority_locations"}
|
||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
target_folder = local_path("WebHostLib", "static", "generated")
|
target_folder = local_path("WebHostLib", "static", "generated")
|
||||||
yaml_folder = os.path.join(target_folder, "configs")
|
yaml_folder = os.path.join(target_folder, "configs")
|
||||||
os.makedirs(yaml_folder, exist_ok=True)
|
|
||||||
|
|
||||||
for file in os.listdir(yaml_folder):
|
Options.generate_yaml_templates(yaml_folder)
|
||||||
full_path: str = os.path.join(yaml_folder, file)
|
|
||||||
if os.path.isfile(full_path):
|
|
||||||
os.unlink(full_path)
|
|
||||||
|
|
||||||
def dictify_range(option: typing.Union[Options.Range, Options.SpecialRange]):
|
|
||||||
data = {option.default: 50}
|
|
||||||
for sub_option in ["random", "random-low", "random-high"]:
|
|
||||||
if sub_option != option.default:
|
|
||||||
data[sub_option] = 0
|
|
||||||
|
|
||||||
notes = {}
|
|
||||||
for name, number in getattr(option, "special_range_names", {}).items():
|
|
||||||
notes[name] = f"equivalent to {number}"
|
|
||||||
if number in data:
|
|
||||||
data[name] = data[number]
|
|
||||||
del data[number]
|
|
||||||
else:
|
|
||||||
data[name] = 0
|
|
||||||
|
|
||||||
return data, notes
|
|
||||||
|
|
||||||
def get_html_doc(option_type: type(Options.Option)) -> str:
|
def get_html_doc(option_type: type(Options.Option)) -> str:
|
||||||
if not option_type.__doc__:
|
if not option_type.__doc__:
|
||||||
@@ -61,18 +40,6 @@ def create():
|
|||||||
**Options.per_game_common_options,
|
**Options.per_game_common_options,
|
||||||
**world.option_definitions
|
**world.option_definitions
|
||||||
}
|
}
|
||||||
with open(local_path("WebHostLib", "templates", "options.yaml")) as f:
|
|
||||||
file_data = f.read()
|
|
||||||
res = Template(file_data).render(
|
|
||||||
options=all_options,
|
|
||||||
__version__=__version__, game=game_name, yaml_dump=yaml.dump,
|
|
||||||
dictify_range=dictify_range,
|
|
||||||
)
|
|
||||||
|
|
||||||
del file_data
|
|
||||||
|
|
||||||
with open(os.path.join(target_folder, "configs", game_name + ".yaml"), "w", encoding="utf-8") as f:
|
|
||||||
f.write(res)
|
|
||||||
|
|
||||||
# Generate JSON files for player-settings pages
|
# Generate JSON files for player-settings pages
|
||||||
player_settings = {
|
player_settings = {
|
||||||
@@ -88,7 +55,7 @@ def create():
|
|||||||
if option_name in handled_in_js:
|
if option_name in handled_in_js:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif option.options:
|
elif issubclass(option, Options.Choice) or issubclass(option, Options.Toggle):
|
||||||
game_options[option_name] = this_option = {
|
game_options[option_name] = this_option = {
|
||||||
"type": "select",
|
"type": "select",
|
||||||
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
||||||
@@ -98,15 +65,15 @@ def create():
|
|||||||
}
|
}
|
||||||
|
|
||||||
for sub_option_id, sub_option_name in option.name_lookup.items():
|
for sub_option_id, sub_option_name in option.name_lookup.items():
|
||||||
this_option["options"].append({
|
if sub_option_name != "random":
|
||||||
"name": option.get_option_name(sub_option_id),
|
this_option["options"].append({
|
||||||
"value": sub_option_name,
|
"name": option.get_option_name(sub_option_id),
|
||||||
})
|
"value": sub_option_name,
|
||||||
|
})
|
||||||
if sub_option_id == option.default:
|
if sub_option_id == option.default:
|
||||||
this_option["defaultValue"] = sub_option_name
|
this_option["defaultValue"] = sub_option_name
|
||||||
|
|
||||||
if option.default == "random":
|
if not this_option["defaultValue"]:
|
||||||
this_option["defaultValue"] = "random"
|
this_option["defaultValue"] = "random"
|
||||||
|
|
||||||
elif issubclass(option, Options.Range):
|
elif issubclass(option, Options.Range):
|
||||||
@@ -126,27 +93,30 @@ def create():
|
|||||||
for key, val in option.special_range_names.items():
|
for key, val in option.special_range_names.items():
|
||||||
game_options[option_name]["value_names"][key] = val
|
game_options[option_name]["value_names"][key] = val
|
||||||
|
|
||||||
elif getattr(option, "verify_item_name", False):
|
elif issubclass(option, Options.ItemSet):
|
||||||
game_options[option_name] = {
|
game_options[option_name] = {
|
||||||
"type": "items-list",
|
"type": "items-list",
|
||||||
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
||||||
"description": get_html_doc(option),
|
"description": get_html_doc(option),
|
||||||
|
"defaultValue": list(option.default)
|
||||||
}
|
}
|
||||||
|
|
||||||
elif getattr(option, "verify_location_name", False):
|
elif issubclass(option, Options.LocationSet):
|
||||||
game_options[option_name] = {
|
game_options[option_name] = {
|
||||||
"type": "locations-list",
|
"type": "locations-list",
|
||||||
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
||||||
"description": get_html_doc(option),
|
"description": get_html_doc(option),
|
||||||
|
"defaultValue": list(option.default)
|
||||||
}
|
}
|
||||||
|
|
||||||
elif issubclass(option, Options.OptionList) or issubclass(option, Options.OptionSet):
|
elif issubclass(option, Options.VerifyKeys) and not issubclass(option, Options.OptionDict):
|
||||||
if option.valid_keys:
|
if option.valid_keys:
|
||||||
game_options[option_name] = {
|
game_options[option_name] = {
|
||||||
"type": "custom-list",
|
"type": "custom-list",
|
||||||
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
"displayName": option.display_name if hasattr(option, "display_name") else option_name,
|
||||||
"description": get_html_doc(option),
|
"description": get_html_doc(option),
|
||||||
"options": list(option.valid_keys),
|
"options": list(option.valid_keys),
|
||||||
|
"defaultValue": list(option.default) if hasattr(option, "default") else []
|
||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -160,6 +130,14 @@ def create():
|
|||||||
json.dump(player_settings, f, indent=2, separators=(',', ': '))
|
json.dump(player_settings, f, indent=2, separators=(',', ': '))
|
||||||
|
|
||||||
if not world.hidden and world.web.settings_page is True:
|
if not world.hidden and world.web.settings_page is True:
|
||||||
|
# Add the random option to Choice, TextChoice, and Toggle settings
|
||||||
|
for option in game_options.values():
|
||||||
|
if option["type"] == "select":
|
||||||
|
option["options"].append({"name": "Random", "value": "random"})
|
||||||
|
|
||||||
|
if not option["defaultValue"]:
|
||||||
|
option["defaultValue"] = "random"
|
||||||
|
|
||||||
weighted_settings["baseOptions"]["game"][game_name] = 0
|
weighted_settings["baseOptions"]["game"][game_name] = 0
|
||||||
weighted_settings["games"][game_name] = {}
|
weighted_settings["games"][game_name] = {}
|
||||||
weighted_settings["games"][game_name]["gameSettings"] = game_options
|
weighted_settings["games"][game_name]["gameSettings"] = game_options
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
|
// Mobile menu handling
|
||||||
const menuButton = document.getElementById('base-header-mobile-menu-button');
|
const menuButton = document.getElementById('base-header-mobile-menu-button');
|
||||||
const mobileMenu = document.getElementById('base-header-mobile-menu');
|
const mobileMenu = document.getElementById('base-header-mobile-menu');
|
||||||
|
|
||||||
menuButton.addEventListener('click', (evt) => {
|
menuButton.addEventListener('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
|
||||||
if (!mobileMenu.style.display || mobileMenu.style.display === 'none') {
|
if (!mobileMenu.style.display || mobileMenu.style.display === 'none') {
|
||||||
return mobileMenu.style.display = 'flex';
|
return mobileMenu.style.display = 'flex';
|
||||||
@@ -15,4 +17,24 @@ window.addEventListener('load', () => {
|
|||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
mobileMenu.style.display = 'none';
|
mobileMenu.style.display = 'none';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Popover handling
|
||||||
|
const popoverText = document.getElementById('base-header-popover-text');
|
||||||
|
const popoverMenu = document.getElementById('base-header-popover-menu');
|
||||||
|
|
||||||
|
popoverText.addEventListener('click', (evt) => {
|
||||||
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
|
||||||
|
if (!popoverMenu.style.display || popoverMenu.style.display === 'none') {
|
||||||
|
return popoverMenu.style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
|
popoverMenu.style.display = 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
document.body.addEventListener('click', () => {
|
||||||
|
mobileMenu.style.display = 'none';
|
||||||
|
popoverMenu.style.display = 'none';
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ const createDefaultSettings = (settingData) => {
|
|||||||
break;
|
break;
|
||||||
case 'range':
|
case 'range':
|
||||||
case 'special_range':
|
case 'special_range':
|
||||||
newSettings[game][gameSetting][setting.min] = 0;
|
|
||||||
newSettings[game][gameSetting][setting.max] = 0;
|
|
||||||
newSettings[game][gameSetting]['random'] = 0;
|
newSettings[game][gameSetting]['random'] = 0;
|
||||||
newSettings[game][gameSetting]['random-low'] = 0;
|
newSettings[game][gameSetting]['random-low'] = 0;
|
||||||
newSettings[game][gameSetting]['random-high'] = 0;
|
newSettings[game][gameSetting]['random-high'] = 0;
|
||||||
@@ -93,7 +91,7 @@ const createDefaultSettings = (settingData) => {
|
|||||||
case 'items-list':
|
case 'items-list':
|
||||||
case 'locations-list':
|
case 'locations-list':
|
||||||
case 'custom-list':
|
case 'custom-list':
|
||||||
newSettings[game][gameSetting] = [];
|
newSettings[game][gameSetting] = setting.defaultValue;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -103,6 +101,7 @@ const createDefaultSettings = (settingData) => {
|
|||||||
|
|
||||||
newSettings[game].start_inventory = {};
|
newSettings[game].start_inventory = {};
|
||||||
newSettings[game].exclude_locations = [];
|
newSettings[game].exclude_locations = [];
|
||||||
|
newSettings[game].priority_locations = [];
|
||||||
newSettings[game].local_items = [];
|
newSettings[game].local_items = [];
|
||||||
newSettings[game].non_local_items = [];
|
newSettings[game].non_local_items = [];
|
||||||
newSettings[game].start_hints = [];
|
newSettings[game].start_hints = [];
|
||||||
@@ -138,21 +137,28 @@ const buildUI = (settingData) => {
|
|||||||
expandButton.classList.add('invisible');
|
expandButton.classList.add('invisible');
|
||||||
gameDiv.appendChild(expandButton);
|
gameDiv.appendChild(expandButton);
|
||||||
|
|
||||||
const weightedSettingsDiv = buildWeightedSettingsDiv(game, settingData.games[game].gameSettings);
|
settingData.games[game].gameItems.sort((a, b) => (a > b ? 1 : (a < b ? -1 : 0)));
|
||||||
|
settingData.games[game].gameLocations.sort((a, b) => (a > b ? 1 : (a < b ? -1 : 0)));
|
||||||
|
|
||||||
|
const weightedSettingsDiv = buildWeightedSettingsDiv(game, settingData.games[game].gameSettings,
|
||||||
|
settingData.games[game].gameItems, settingData.games[game].gameLocations);
|
||||||
gameDiv.appendChild(weightedSettingsDiv);
|
gameDiv.appendChild(weightedSettingsDiv);
|
||||||
|
|
||||||
const itemsDiv = buildItemsDiv(game, settingData.games[game].gameItems);
|
const itemPoolDiv = buildItemsDiv(game, settingData.games[game].gameItems);
|
||||||
gameDiv.appendChild(itemsDiv);
|
gameDiv.appendChild(itemPoolDiv);
|
||||||
|
|
||||||
const hintsDiv = buildHintsDiv(game, settingData.games[game].gameItems, settingData.games[game].gameLocations);
|
const hintsDiv = buildHintsDiv(game, settingData.games[game].gameItems, settingData.games[game].gameLocations);
|
||||||
gameDiv.appendChild(hintsDiv);
|
gameDiv.appendChild(hintsDiv);
|
||||||
|
|
||||||
|
const locationsDiv = buildLocationsDiv(game, settingData.games[game].gameLocations);
|
||||||
|
gameDiv.appendChild(locationsDiv);
|
||||||
|
|
||||||
gamesWrapper.appendChild(gameDiv);
|
gamesWrapper.appendChild(gameDiv);
|
||||||
|
|
||||||
collapseButton.addEventListener('click', () => {
|
collapseButton.addEventListener('click', () => {
|
||||||
collapseButton.classList.add('invisible');
|
collapseButton.classList.add('invisible');
|
||||||
weightedSettingsDiv.classList.add('invisible');
|
weightedSettingsDiv.classList.add('invisible');
|
||||||
itemsDiv.classList.add('invisible');
|
itemPoolDiv.classList.add('invisible');
|
||||||
hintsDiv.classList.add('invisible');
|
hintsDiv.classList.add('invisible');
|
||||||
expandButton.classList.remove('invisible');
|
expandButton.classList.remove('invisible');
|
||||||
});
|
});
|
||||||
@@ -160,7 +166,7 @@ const buildUI = (settingData) => {
|
|||||||
expandButton.addEventListener('click', () => {
|
expandButton.addEventListener('click', () => {
|
||||||
collapseButton.classList.remove('invisible');
|
collapseButton.classList.remove('invisible');
|
||||||
weightedSettingsDiv.classList.remove('invisible');
|
weightedSettingsDiv.classList.remove('invisible');
|
||||||
itemsDiv.classList.remove('invisible');
|
itemPoolDiv.classList.remove('invisible');
|
||||||
hintsDiv.classList.remove('invisible');
|
hintsDiv.classList.remove('invisible');
|
||||||
expandButton.classList.add('invisible');
|
expandButton.classList.add('invisible');
|
||||||
});
|
});
|
||||||
@@ -228,7 +234,7 @@ const buildGameChoice = (games) => {
|
|||||||
gameChoiceDiv.appendChild(table);
|
gameChoiceDiv.appendChild(table);
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildWeightedSettingsDiv = (game, settings) => {
|
const buildWeightedSettingsDiv = (game, settings, gameItems, gameLocations) => {
|
||||||
const currentSettings = JSON.parse(localStorage.getItem('weighted-settings'));
|
const currentSettings = JSON.parse(localStorage.getItem('weighted-settings'));
|
||||||
const settingsWrapper = document.createElement('div');
|
const settingsWrapper = document.createElement('div');
|
||||||
settingsWrapper.classList.add('settings-wrapper');
|
settingsWrapper.classList.add('settings-wrapper');
|
||||||
@@ -270,7 +276,7 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
range.setAttribute('data-type', setting.type);
|
range.setAttribute('data-type', setting.type);
|
||||||
range.setAttribute('min', 0);
|
range.setAttribute('min', 0);
|
||||||
range.setAttribute('max', 50);
|
range.setAttribute('max', 50);
|
||||||
range.addEventListener('change', updateGameSetting);
|
range.addEventListener('change', updateRangeSetting);
|
||||||
range.value = currentSettings[game][settingName][option.value];
|
range.value = currentSettings[game][settingName][option.value];
|
||||||
tdMiddle.appendChild(range);
|
tdMiddle.appendChild(range);
|
||||||
tr.appendChild(tdMiddle);
|
tr.appendChild(tdMiddle);
|
||||||
@@ -296,33 +302,33 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
if (((setting.max - setting.min) + 1) < 11) {
|
if (((setting.max - setting.min) + 1) < 11) {
|
||||||
for (let i=setting.min; i <= setting.max; ++i) {
|
for (let i=setting.min; i <= setting.max; ++i) {
|
||||||
const tr = document.createElement('tr');
|
const tr = document.createElement('tr');
|
||||||
const tdLeft = document.createElement('td');
|
const tdLeft = document.createElement('td');
|
||||||
tdLeft.classList.add('td-left');
|
tdLeft.classList.add('td-left');
|
||||||
tdLeft.innerText = i;
|
tdLeft.innerText = i;
|
||||||
tr.appendChild(tdLeft);
|
tr.appendChild(tdLeft);
|
||||||
|
|
||||||
const tdMiddle = document.createElement('td');
|
const tdMiddle = document.createElement('td');
|
||||||
tdMiddle.classList.add('td-middle');
|
tdMiddle.classList.add('td-middle');
|
||||||
const range = document.createElement('input');
|
const range = document.createElement('input');
|
||||||
range.setAttribute('type', 'range');
|
range.setAttribute('type', 'range');
|
||||||
range.setAttribute('id', `${game}-${settingName}-${i}-range`);
|
range.setAttribute('id', `${game}-${settingName}-${i}-range`);
|
||||||
range.setAttribute('data-game', game);
|
range.setAttribute('data-game', game);
|
||||||
range.setAttribute('data-setting', settingName);
|
range.setAttribute('data-setting', settingName);
|
||||||
range.setAttribute('data-option', i);
|
range.setAttribute('data-option', i);
|
||||||
range.setAttribute('min', 0);
|
range.setAttribute('min', 0);
|
||||||
range.setAttribute('max', 50);
|
range.setAttribute('max', 50);
|
||||||
range.addEventListener('change', updateGameSetting);
|
range.addEventListener('change', updateRangeSetting);
|
||||||
range.value = currentSettings[game][settingName][i];
|
range.value = currentSettings[game][settingName][i] || 0;
|
||||||
tdMiddle.appendChild(range);
|
tdMiddle.appendChild(range);
|
||||||
tr.appendChild(tdMiddle);
|
tr.appendChild(tdMiddle);
|
||||||
|
|
||||||
const tdRight = document.createElement('td');
|
const tdRight = document.createElement('td');
|
||||||
tdRight.setAttribute('id', `${game}-${settingName}-${i}`)
|
tdRight.setAttribute('id', `${game}-${settingName}-${i}`)
|
||||||
tdRight.classList.add('td-right');
|
tdRight.classList.add('td-right');
|
||||||
tdRight.innerText = range.value;
|
tdRight.innerText = range.value;
|
||||||
tr.appendChild(tdRight);
|
tr.appendChild(tdRight);
|
||||||
|
|
||||||
rangeTbody.appendChild(tr);
|
rangeTbody.appendChild(tr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const hintText = document.createElement('p');
|
const hintText = document.createElement('p');
|
||||||
@@ -379,7 +385,7 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
range.setAttribute('data-option', option);
|
range.setAttribute('data-option', option);
|
||||||
range.setAttribute('min', 0);
|
range.setAttribute('min', 0);
|
||||||
range.setAttribute('max', 50);
|
range.setAttribute('max', 50);
|
||||||
range.addEventListener('change', updateGameSetting);
|
range.addEventListener('change', updateRangeSetting);
|
||||||
range.value = currentSettings[game][settingName][parseInt(option, 10)];
|
range.value = currentSettings[game][settingName][parseInt(option, 10)];
|
||||||
tdMiddle.appendChild(range);
|
tdMiddle.appendChild(range);
|
||||||
tr.appendChild(tdMiddle);
|
tr.appendChild(tdMiddle);
|
||||||
@@ -430,7 +436,7 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
range.setAttribute('data-option', option);
|
range.setAttribute('data-option', option);
|
||||||
range.setAttribute('min', 0);
|
range.setAttribute('min', 0);
|
||||||
range.setAttribute('max', 50);
|
range.setAttribute('max', 50);
|
||||||
range.addEventListener('change', updateGameSetting);
|
range.addEventListener('change', updateRangeSetting);
|
||||||
range.value = currentSettings[game][settingName][parseInt(option, 10)];
|
range.value = currentSettings[game][settingName][parseInt(option, 10)];
|
||||||
tdMiddle.appendChild(range);
|
tdMiddle.appendChild(range);
|
||||||
tr.appendChild(tdMiddle);
|
tr.appendChild(tdMiddle);
|
||||||
@@ -464,7 +470,17 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
const tr = document.createElement('tr');
|
const tr = document.createElement('tr');
|
||||||
const tdLeft = document.createElement('td');
|
const tdLeft = document.createElement('td');
|
||||||
tdLeft.classList.add('td-left');
|
tdLeft.classList.add('td-left');
|
||||||
tdLeft.innerText = option;
|
switch(option){
|
||||||
|
case 'random':
|
||||||
|
tdLeft.innerText = 'Random';
|
||||||
|
break;
|
||||||
|
case 'random-low':
|
||||||
|
tdLeft.innerText = "Random (Low)";
|
||||||
|
break;
|
||||||
|
case 'random-high':
|
||||||
|
tdLeft.innerText = "Random (High)";
|
||||||
|
break;
|
||||||
|
}
|
||||||
tr.appendChild(tdLeft);
|
tr.appendChild(tdLeft);
|
||||||
|
|
||||||
const tdMiddle = document.createElement('td');
|
const tdMiddle = document.createElement('td');
|
||||||
@@ -477,7 +493,7 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
range.setAttribute('data-option', option);
|
range.setAttribute('data-option', option);
|
||||||
range.setAttribute('min', 0);
|
range.setAttribute('min', 0);
|
||||||
range.setAttribute('max', 50);
|
range.setAttribute('max', 50);
|
||||||
range.addEventListener('change', updateGameSetting);
|
range.addEventListener('change', updateRangeSetting);
|
||||||
range.value = currentSettings[game][settingName][option];
|
range.value = currentSettings[game][settingName][option];
|
||||||
tdMiddle.appendChild(range);
|
tdMiddle.appendChild(range);
|
||||||
tr.appendChild(tdMiddle);
|
tr.appendChild(tdMiddle);
|
||||||
@@ -495,15 +511,108 @@ const buildWeightedSettingsDiv = (game, settings) => {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'items-list':
|
case 'items-list':
|
||||||
// TODO
|
const itemsList = document.createElement('div');
|
||||||
|
itemsList.classList.add('simple-list');
|
||||||
|
|
||||||
|
Object.values(gameItems).forEach((item) => {
|
||||||
|
const itemRow = document.createElement('div');
|
||||||
|
itemRow.classList.add('list-row');
|
||||||
|
|
||||||
|
const itemLabel = document.createElement('label');
|
||||||
|
itemLabel.setAttribute('for', `${game}-${settingName}-${item}`)
|
||||||
|
|
||||||
|
const itemCheckbox = document.createElement('input');
|
||||||
|
itemCheckbox.setAttribute('id', `${game}-${settingName}-${item}`);
|
||||||
|
itemCheckbox.setAttribute('type', 'checkbox');
|
||||||
|
itemCheckbox.setAttribute('data-game', game);
|
||||||
|
itemCheckbox.setAttribute('data-setting', settingName);
|
||||||
|
itemCheckbox.setAttribute('data-option', item.toString());
|
||||||
|
itemCheckbox.addEventListener('change', updateListSetting);
|
||||||
|
if (currentSettings[game][settingName].includes(item)) {
|
||||||
|
itemCheckbox.setAttribute('checked', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
const itemName = document.createElement('span');
|
||||||
|
itemName.innerText = item.toString();
|
||||||
|
|
||||||
|
itemLabel.appendChild(itemCheckbox);
|
||||||
|
itemLabel.appendChild(itemName);
|
||||||
|
|
||||||
|
itemRow.appendChild(itemLabel);
|
||||||
|
itemsList.appendChild((itemRow));
|
||||||
|
});
|
||||||
|
|
||||||
|
settingWrapper.appendChild(itemsList);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'locations-list':
|
case 'locations-list':
|
||||||
// TODO
|
const locationsList = document.createElement('div');
|
||||||
|
locationsList.classList.add('simple-list');
|
||||||
|
|
||||||
|
Object.values(gameLocations).forEach((location) => {
|
||||||
|
const locationRow = document.createElement('div');
|
||||||
|
locationRow.classList.add('list-row');
|
||||||
|
|
||||||
|
const locationLabel = document.createElement('label');
|
||||||
|
locationLabel.setAttribute('for', `${game}-${settingName}-${location}`)
|
||||||
|
|
||||||
|
const locationCheckbox = document.createElement('input');
|
||||||
|
locationCheckbox.setAttribute('id', `${game}-${settingName}-${location}`);
|
||||||
|
locationCheckbox.setAttribute('type', 'checkbox');
|
||||||
|
locationCheckbox.setAttribute('data-game', game);
|
||||||
|
locationCheckbox.setAttribute('data-setting', settingName);
|
||||||
|
locationCheckbox.setAttribute('data-option', location.toString());
|
||||||
|
locationCheckbox.addEventListener('change', updateListSetting);
|
||||||
|
if (currentSettings[game][settingName].includes(location)) {
|
||||||
|
locationCheckbox.setAttribute('checked', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
const locationName = document.createElement('span');
|
||||||
|
locationName.innerText = location.toString();
|
||||||
|
|
||||||
|
locationLabel.appendChild(locationCheckbox);
|
||||||
|
locationLabel.appendChild(locationName);
|
||||||
|
|
||||||
|
locationRow.appendChild(locationLabel);
|
||||||
|
locationsList.appendChild((locationRow));
|
||||||
|
});
|
||||||
|
|
||||||
|
settingWrapper.appendChild(locationsList);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'custom-list':
|
case 'custom-list':
|
||||||
// TODO
|
const customList = document.createElement('div');
|
||||||
|
customList.classList.add('simple-list');
|
||||||
|
|
||||||
|
Object.values(settings[settingName].options).forEach((listItem) => {
|
||||||
|
const customListRow = document.createElement('div');
|
||||||
|
customListRow.classList.add('list-row');
|
||||||
|
|
||||||
|
const customItemLabel = document.createElement('label');
|
||||||
|
customItemLabel.setAttribute('for', `${game}-${settingName}-${listItem}`)
|
||||||
|
|
||||||
|
const customItemCheckbox = document.createElement('input');
|
||||||
|
customItemCheckbox.setAttribute('id', `${game}-${settingName}-${listItem}`);
|
||||||
|
customItemCheckbox.setAttribute('type', 'checkbox');
|
||||||
|
customItemCheckbox.setAttribute('data-game', game);
|
||||||
|
customItemCheckbox.setAttribute('data-setting', settingName);
|
||||||
|
customItemCheckbox.setAttribute('data-option', listItem.toString());
|
||||||
|
customItemCheckbox.addEventListener('change', updateListSetting);
|
||||||
|
if (currentSettings[game][settingName].includes(listItem)) {
|
||||||
|
customItemCheckbox.setAttribute('checked', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
const customItemName = document.createElement('span');
|
||||||
|
customItemName.innerText = listItem.toString();
|
||||||
|
|
||||||
|
customItemLabel.appendChild(customItemCheckbox);
|
||||||
|
customItemLabel.appendChild(customItemName);
|
||||||
|
|
||||||
|
customListRow.appendChild(customItemLabel);
|
||||||
|
customList.appendChild((customListRow));
|
||||||
|
});
|
||||||
|
|
||||||
|
settingWrapper.appendChild(customList);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -729,21 +838,22 @@ const buildHintsDiv = (game, items, locations) => {
|
|||||||
const hintsDescription = document.createElement('p');
|
const hintsDescription = document.createElement('p');
|
||||||
hintsDescription.classList.add('setting-description');
|
hintsDescription.classList.add('setting-description');
|
||||||
hintsDescription.innerText = 'Choose any items or locations to begin the game with the knowledge of where those ' +
|
hintsDescription.innerText = 'Choose any items or locations to begin the game with the knowledge of where those ' +
|
||||||
' items are, or what those locations contain. Excluded locations will not contain progression items.';
|
' items are, or what those locations contain.';
|
||||||
hintsDiv.appendChild(hintsDescription);
|
hintsDiv.appendChild(hintsDescription);
|
||||||
|
|
||||||
const itemHintsContainer = document.createElement('div');
|
const itemHintsContainer = document.createElement('div');
|
||||||
itemHintsContainer.classList.add('hints-container');
|
itemHintsContainer.classList.add('hints-container');
|
||||||
|
|
||||||
|
// Item Hints
|
||||||
const itemHintsWrapper = document.createElement('div');
|
const itemHintsWrapper = document.createElement('div');
|
||||||
itemHintsWrapper.classList.add('hints-wrapper');
|
itemHintsWrapper.classList.add('hints-wrapper');
|
||||||
itemHintsWrapper.innerText = 'Starting Item Hints';
|
itemHintsWrapper.innerText = 'Starting Item Hints';
|
||||||
|
|
||||||
const itemHintsDiv = document.createElement('div');
|
const itemHintsDiv = document.createElement('div');
|
||||||
itemHintsDiv.classList.add('item-container');
|
itemHintsDiv.classList.add('simple-list');
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
const itemDiv = document.createElement('div');
|
const itemRow = document.createElement('div');
|
||||||
itemDiv.classList.add('hint-div');
|
itemRow.classList.add('list-row');
|
||||||
|
|
||||||
const itemLabel = document.createElement('label');
|
const itemLabel = document.createElement('label');
|
||||||
itemLabel.setAttribute('for', `${game}-start_hints-${item}`);
|
itemLabel.setAttribute('for', `${game}-start_hints-${item}`);
|
||||||
@@ -757,29 +867,30 @@ const buildHintsDiv = (game, items, locations) => {
|
|||||||
if (currentSettings[game].start_hints.includes(item)) {
|
if (currentSettings[game].start_hints.includes(item)) {
|
||||||
itemCheckbox.setAttribute('checked', 'true');
|
itemCheckbox.setAttribute('checked', 'true');
|
||||||
}
|
}
|
||||||
itemCheckbox.addEventListener('change', hintChangeHandler);
|
itemCheckbox.addEventListener('change', updateListSetting);
|
||||||
itemLabel.appendChild(itemCheckbox);
|
itemLabel.appendChild(itemCheckbox);
|
||||||
|
|
||||||
const itemName = document.createElement('span');
|
const itemName = document.createElement('span');
|
||||||
itemName.innerText = item;
|
itemName.innerText = item;
|
||||||
itemLabel.appendChild(itemName);
|
itemLabel.appendChild(itemName);
|
||||||
|
|
||||||
itemDiv.appendChild(itemLabel);
|
itemRow.appendChild(itemLabel);
|
||||||
itemHintsDiv.appendChild(itemDiv);
|
itemHintsDiv.appendChild(itemRow);
|
||||||
});
|
});
|
||||||
|
|
||||||
itemHintsWrapper.appendChild(itemHintsDiv);
|
itemHintsWrapper.appendChild(itemHintsDiv);
|
||||||
itemHintsContainer.appendChild(itemHintsWrapper);
|
itemHintsContainer.appendChild(itemHintsWrapper);
|
||||||
|
|
||||||
|
// Starting Location Hints
|
||||||
const locationHintsWrapper = document.createElement('div');
|
const locationHintsWrapper = document.createElement('div');
|
||||||
locationHintsWrapper.classList.add('hints-wrapper');
|
locationHintsWrapper.classList.add('hints-wrapper');
|
||||||
locationHintsWrapper.innerText = 'Starting Location Hints';
|
locationHintsWrapper.innerText = 'Starting Location Hints';
|
||||||
|
|
||||||
const locationHintsDiv = document.createElement('div');
|
const locationHintsDiv = document.createElement('div');
|
||||||
locationHintsDiv.classList.add('item-container');
|
locationHintsDiv.classList.add('simple-list');
|
||||||
locations.forEach((location) => {
|
locations.forEach((location) => {
|
||||||
const locationDiv = document.createElement('div');
|
const locationRow = document.createElement('div');
|
||||||
locationDiv.classList.add('hint-div');
|
locationRow.classList.add('list-row');
|
||||||
|
|
||||||
const locationLabel = document.createElement('label');
|
const locationLabel = document.createElement('label');
|
||||||
locationLabel.setAttribute('for', `${game}-start_location_hints-${location}`);
|
locationLabel.setAttribute('for', `${game}-start_location_hints-${location}`);
|
||||||
@@ -793,29 +904,89 @@ const buildHintsDiv = (game, items, locations) => {
|
|||||||
if (currentSettings[game].start_location_hints.includes(location)) {
|
if (currentSettings[game].start_location_hints.includes(location)) {
|
||||||
locationCheckbox.setAttribute('checked', '1');
|
locationCheckbox.setAttribute('checked', '1');
|
||||||
}
|
}
|
||||||
locationCheckbox.addEventListener('change', hintChangeHandler);
|
locationCheckbox.addEventListener('change', updateListSetting);
|
||||||
locationLabel.appendChild(locationCheckbox);
|
locationLabel.appendChild(locationCheckbox);
|
||||||
|
|
||||||
const locationName = document.createElement('span');
|
const locationName = document.createElement('span');
|
||||||
locationName.innerText = location;
|
locationName.innerText = location;
|
||||||
locationLabel.appendChild(locationName);
|
locationLabel.appendChild(locationName);
|
||||||
|
|
||||||
locationDiv.appendChild(locationLabel);
|
locationRow.appendChild(locationLabel);
|
||||||
locationHintsDiv.appendChild(locationDiv);
|
locationHintsDiv.appendChild(locationRow);
|
||||||
});
|
});
|
||||||
|
|
||||||
locationHintsWrapper.appendChild(locationHintsDiv);
|
locationHintsWrapper.appendChild(locationHintsDiv);
|
||||||
itemHintsContainer.appendChild(locationHintsWrapper);
|
itemHintsContainer.appendChild(locationHintsWrapper);
|
||||||
|
|
||||||
|
hintsDiv.appendChild(itemHintsContainer);
|
||||||
|
return hintsDiv;
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildLocationsDiv = (game, locations) => {
|
||||||
|
const currentSettings = JSON.parse(localStorage.getItem('weighted-settings'));
|
||||||
|
locations.sort(); // Sort alphabetical, in-place
|
||||||
|
|
||||||
|
const locationsDiv = document.createElement('div');
|
||||||
|
locationsDiv.classList.add('locations-div');
|
||||||
|
const locationsHeader = document.createElement('h3');
|
||||||
|
locationsHeader.innerText = 'Priority & Exclusion Locations';
|
||||||
|
locationsDiv.appendChild(locationsHeader);
|
||||||
|
const locationsDescription = document.createElement('p');
|
||||||
|
locationsDescription.classList.add('setting-description');
|
||||||
|
locationsDescription.innerText = 'Priority locations guarantee a progression item will be placed there while ' +
|
||||||
|
'excluded locations will not contain progression or useful items.';
|
||||||
|
locationsDiv.appendChild(locationsDescription);
|
||||||
|
|
||||||
|
const locationsContainer = document.createElement('div');
|
||||||
|
locationsContainer.classList.add('locations-container');
|
||||||
|
|
||||||
|
// Priority Locations
|
||||||
|
const priorityLocationsWrapper = document.createElement('div');
|
||||||
|
priorityLocationsWrapper.classList.add('locations-wrapper');
|
||||||
|
priorityLocationsWrapper.innerText = 'Priority Locations';
|
||||||
|
|
||||||
|
const priorityLocationsDiv = document.createElement('div');
|
||||||
|
priorityLocationsDiv.classList.add('simple-list');
|
||||||
|
locations.forEach((location) => {
|
||||||
|
const locationRow = document.createElement('div');
|
||||||
|
locationRow.classList.add('list-row');
|
||||||
|
|
||||||
|
const locationLabel = document.createElement('label');
|
||||||
|
locationLabel.setAttribute('for', `${game}-priority_locations-${location}`);
|
||||||
|
|
||||||
|
const locationCheckbox = document.createElement('input');
|
||||||
|
locationCheckbox.setAttribute('type', 'checkbox');
|
||||||
|
locationCheckbox.setAttribute('id', `${game}-priority_locations-${location}`);
|
||||||
|
locationCheckbox.setAttribute('data-game', game);
|
||||||
|
locationCheckbox.setAttribute('data-setting', 'priority_locations');
|
||||||
|
locationCheckbox.setAttribute('data-option', location);
|
||||||
|
if (currentSettings[game].priority_locations.includes(location)) {
|
||||||
|
locationCheckbox.setAttribute('checked', '1');
|
||||||
|
}
|
||||||
|
locationCheckbox.addEventListener('change', updateListSetting);
|
||||||
|
locationLabel.appendChild(locationCheckbox);
|
||||||
|
|
||||||
|
const locationName = document.createElement('span');
|
||||||
|
locationName.innerText = location;
|
||||||
|
locationLabel.appendChild(locationName);
|
||||||
|
|
||||||
|
locationRow.appendChild(locationLabel);
|
||||||
|
priorityLocationsDiv.appendChild(locationRow);
|
||||||
|
});
|
||||||
|
|
||||||
|
priorityLocationsWrapper.appendChild(priorityLocationsDiv);
|
||||||
|
locationsContainer.appendChild(priorityLocationsWrapper);
|
||||||
|
|
||||||
|
// Exclude Locations
|
||||||
const excludeLocationsWrapper = document.createElement('div');
|
const excludeLocationsWrapper = document.createElement('div');
|
||||||
excludeLocationsWrapper.classList.add('hints-wrapper');
|
excludeLocationsWrapper.classList.add('locations-wrapper');
|
||||||
excludeLocationsWrapper.innerText = 'Exclude Locations';
|
excludeLocationsWrapper.innerText = 'Exclude Locations';
|
||||||
|
|
||||||
const excludeLocationsDiv = document.createElement('div');
|
const excludeLocationsDiv = document.createElement('div');
|
||||||
excludeLocationsDiv.classList.add('item-container');
|
excludeLocationsDiv.classList.add('simple-list');
|
||||||
locations.forEach((location) => {
|
locations.forEach((location) => {
|
||||||
const locationDiv = document.createElement('div');
|
const locationRow = document.createElement('div');
|
||||||
locationDiv.classList.add('hint-div');
|
locationRow.classList.add('list-row');
|
||||||
|
|
||||||
const locationLabel = document.createElement('label');
|
const locationLabel = document.createElement('label');
|
||||||
locationLabel.setAttribute('for', `${game}-exclude_locations-${location}`);
|
locationLabel.setAttribute('for', `${game}-exclude_locations-${location}`);
|
||||||
@@ -829,40 +1000,22 @@ const buildHintsDiv = (game, items, locations) => {
|
|||||||
if (currentSettings[game].exclude_locations.includes(location)) {
|
if (currentSettings[game].exclude_locations.includes(location)) {
|
||||||
locationCheckbox.setAttribute('checked', '1');
|
locationCheckbox.setAttribute('checked', '1');
|
||||||
}
|
}
|
||||||
locationCheckbox.addEventListener('change', hintChangeHandler);
|
locationCheckbox.addEventListener('change', updateListSetting);
|
||||||
locationLabel.appendChild(locationCheckbox);
|
locationLabel.appendChild(locationCheckbox);
|
||||||
|
|
||||||
const locationName = document.createElement('span');
|
const locationName = document.createElement('span');
|
||||||
locationName.innerText = location;
|
locationName.innerText = location;
|
||||||
locationLabel.appendChild(locationName);
|
locationLabel.appendChild(locationName);
|
||||||
|
|
||||||
locationDiv.appendChild(locationLabel);
|
locationRow.appendChild(locationLabel);
|
||||||
excludeLocationsDiv.appendChild(locationDiv);
|
excludeLocationsDiv.appendChild(locationRow);
|
||||||
});
|
});
|
||||||
|
|
||||||
excludeLocationsWrapper.appendChild(excludeLocationsDiv);
|
excludeLocationsWrapper.appendChild(excludeLocationsDiv);
|
||||||
itemHintsContainer.appendChild(excludeLocationsWrapper);
|
locationsContainer.appendChild(excludeLocationsWrapper);
|
||||||
|
|
||||||
hintsDiv.appendChild(itemHintsContainer);
|
locationsDiv.appendChild(locationsContainer);
|
||||||
return hintsDiv;
|
return locationsDiv;
|
||||||
};
|
|
||||||
|
|
||||||
const hintChangeHandler = (evt) => {
|
|
||||||
const currentSettings = JSON.parse(localStorage.getItem('weighted-settings'));
|
|
||||||
const game = evt.target.getAttribute('data-game');
|
|
||||||
const setting = evt.target.getAttribute('data-setting');
|
|
||||||
const option = evt.target.getAttribute('data-option');
|
|
||||||
|
|
||||||
if (evt.target.checked) {
|
|
||||||
if (!currentSettings[game][setting].includes(option)) {
|
|
||||||
currentSettings[game][setting].push(option);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (currentSettings[game][setting].includes(option)) {
|
|
||||||
currentSettings[game][setting].splice(currentSettings[game][setting].indexOf(option), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
localStorage.setItem('weighted-settings', JSON.stringify(currentSettings));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateVisibleGames = () => {
|
const updateVisibleGames = () => {
|
||||||
@@ -908,13 +1061,12 @@ const updateBaseSetting = (event) => {
|
|||||||
localStorage.setItem('weighted-settings', JSON.stringify(settings));
|
localStorage.setItem('weighted-settings', JSON.stringify(settings));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateGameSetting = (evt) => {
|
const updateRangeSetting = (evt) => {
|
||||||
const options = JSON.parse(localStorage.getItem('weighted-settings'));
|
const options = JSON.parse(localStorage.getItem('weighted-settings'));
|
||||||
const game = evt.target.getAttribute('data-game');
|
const game = evt.target.getAttribute('data-game');
|
||||||
const setting = evt.target.getAttribute('data-setting');
|
const setting = evt.target.getAttribute('data-setting');
|
||||||
const option = evt.target.getAttribute('data-option');
|
const option = evt.target.getAttribute('data-option');
|
||||||
document.getElementById(`${game}-${setting}-${option}`).innerText = evt.target.value;
|
document.getElementById(`${game}-${setting}-${option}`).innerText = evt.target.value;
|
||||||
console.log(event);
|
|
||||||
if (evt.action && evt.action === 'rangeDelete') {
|
if (evt.action && evt.action === 'rangeDelete') {
|
||||||
delete options[game][setting][option];
|
delete options[game][setting][option];
|
||||||
} else {
|
} else {
|
||||||
@@ -923,6 +1075,26 @@ const updateGameSetting = (evt) => {
|
|||||||
localStorage.setItem('weighted-settings', JSON.stringify(options));
|
localStorage.setItem('weighted-settings', JSON.stringify(options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateListSetting = (evt) => {
|
||||||
|
const options = JSON.parse(localStorage.getItem('weighted-settings'));
|
||||||
|
const game = evt.target.getAttribute('data-game');
|
||||||
|
const setting = evt.target.getAttribute('data-setting');
|
||||||
|
const option = evt.target.getAttribute('data-option');
|
||||||
|
|
||||||
|
if (evt.target.checked) {
|
||||||
|
// If the option is to be enabled and it is already enabled, do nothing
|
||||||
|
if (options[game][setting].includes(option)) { return; }
|
||||||
|
|
||||||
|
options[game][setting].push(option);
|
||||||
|
} else {
|
||||||
|
// If the option is to be disabled and it is already disabled, do nothing
|
||||||
|
if (!options[game][setting].includes(option)) { return; }
|
||||||
|
|
||||||
|
options[game][setting].splice(options[game][setting].indexOf(option), 1);
|
||||||
|
}
|
||||||
|
localStorage.setItem('weighted-settings', JSON.stringify(options));
|
||||||
|
};
|
||||||
|
|
||||||
const updateItemSetting = (evt) => {
|
const updateItemSetting = (evt) => {
|
||||||
const options = JSON.parse(localStorage.getItem('weighted-settings'));
|
const options = JSON.parse(localStorage.getItem('weighted-settings'));
|
||||||
const game = evt.target.getAttribute('data-game');
|
const game = evt.target.getAttribute('data-game');
|
||||||
|
|||||||
BIN
WebHostLib/static/static/button-images/popover.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
@@ -15,3 +15,33 @@
|
|||||||
padding-left: 0.5rem;
|
padding-left: 0.5rem;
|
||||||
color: #dfedc6;
|
color: #dfedc6;
|
||||||
}
|
}
|
||||||
|
@media all and (max-width: 900px) {
|
||||||
|
#island-footer{
|
||||||
|
font-size: 17px;
|
||||||
|
font-size: 2vw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media all and (max-width: 768px) {
|
||||||
|
#island-footer{
|
||||||
|
font-size: 15px;
|
||||||
|
font-size: 2vw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media all and (max-width: 650px) {
|
||||||
|
#island-footer{
|
||||||
|
font-size: 13px;
|
||||||
|
font-size: 2vw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media all and (max-width: 580px) {
|
||||||
|
#island-footer{
|
||||||
|
font-size: 11px;
|
||||||
|
font-size: 2vw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media all and (max-width: 512px) {
|
||||||
|
#island-footer{
|
||||||
|
font-size: 9px;
|
||||||
|
font-size: 2vw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ html{
|
|||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
height: 140px;
|
height: 140px;
|
||||||
z-index: 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#landing-header h4{
|
#landing-header h4{
|
||||||
@@ -223,7 +222,7 @@ html{
|
|||||||
}
|
}
|
||||||
|
|
||||||
#landing{
|
#landing{
|
||||||
width: 700px;
|
max-width: 700px;
|
||||||
min-height: 280px;
|
min-height: 280px;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ html{
|
|||||||
}
|
}
|
||||||
|
|
||||||
#base-header-right{
|
#base-header-right{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ html{
|
|||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#base-header a, #base-header-mobile-menu a{
|
#base-header a, #base-header-mobile-menu a, #base-header-popover-text{
|
||||||
color: #2f6b83;
|
color: #2f6b83;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -72,22 +74,92 @@ html{
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 7rem;
|
top: 7rem;
|
||||||
right: 0;
|
right: 0;
|
||||||
padding-top: 1rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#base-header-mobile-menu a{
|
#base-header-mobile-menu a{
|
||||||
padding: 4rem 2rem;
|
padding: 3rem 1.5rem;
|
||||||
font-size: 5rem;
|
font-size: 4rem;
|
||||||
line-height: 5rem;
|
line-height: 5rem;
|
||||||
color: #699ca8;
|
color: #699ca8;
|
||||||
border-top: 1px solid #d3d3d3;
|
border-top: 1px solid #d3d3d3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#base-header-mobile-menu :first-child, #base-header-popover-menu :first-child{
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
#base-header-right-mobile img{
|
#base-header-right-mobile img{
|
||||||
height: 3rem;
|
height: 3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media all and (max-width: 1580px){
|
#base-header-popover-menu{
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
position: absolute;
|
||||||
|
background-color: #fff;
|
||||||
|
margin-left: -108px;
|
||||||
|
margin-top: 2.25rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
border-left: 2px solid #d0ebe6;
|
||||||
|
border-bottom: 2px solid #d0ebe6;
|
||||||
|
border-right: 1px solid #d0ebe6;
|
||||||
|
filter: drop-shadow(-6px 6px 2px #2e3e83);
|
||||||
|
}
|
||||||
|
|
||||||
|
#base-header-popover-menu a{
|
||||||
|
color: #699ca8;
|
||||||
|
border-top: 1px solid #d3d3d3;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
line-height: 3rem;
|
||||||
|
margin-right: 2px;
|
||||||
|
padding: 0.25rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#base-header-popover-icon {
|
||||||
|
width: 14px;
|
||||||
|
margin-bottom: 3px;
|
||||||
|
margin-left: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and (max-width: 960px), only screen and (max-device-width: 768px) {
|
||||||
|
#base-header-right{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#base-header-right-mobile{
|
||||||
|
display: unset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and (max-width: 960px){
|
||||||
|
#base-header-right-mobile{
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#base-header-right-mobile img{
|
||||||
|
height: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#base-header-mobile-menu{
|
||||||
|
top: 3.3rem;
|
||||||
|
width: unset;
|
||||||
|
border-left: 2px solid #d0ebe6;
|
||||||
|
border-bottom: 2px solid #d0ebe6;
|
||||||
|
filter: drop-shadow(-6px 6px 2px #2e3e83);
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#base-header-mobile-menu a{
|
||||||
|
font-size: 1.5rem;
|
||||||
|
line-height: 3rem;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.25rem 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-device-width: 768px){
|
||||||
html{
|
html{
|
||||||
padding-top: 260px;
|
padding-top: 260px;
|
||||||
scroll-padding-top: 230px;
|
scroll-padding-top: 230px;
|
||||||
@@ -103,12 +175,4 @@ html{
|
|||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#base-header-right{
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#base-header-right-mobile{
|
|
||||||
display: unset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,41 +157,29 @@ html{
|
|||||||
background-color: rgba(0, 0, 0, 0.1);
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#weighted-settings .hints-div{
|
#weighted-settings .hints-div, #weighted-settings .locations-div{
|
||||||
margin-top: 2rem;
|
margin-top: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#weighted-settings .hints-div h3{
|
#weighted-settings .hints-div h3, #weighted-settings .locations-div h3{
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#weighted-settings .hints-div .hints-container{
|
#weighted-settings .hints-container, #weighted-settings .locations-container{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
#weighted-settings .hints-wrapper, #weighted-settings .locations-wrapper{
|
||||||
|
width: calc(50% - 0.5rem);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#weighted-settings .hints-div .hints-wrapper{
|
#weighted-settings .hints-wrapper .simple-list, #weighted-settings .locations-wrapper .simple-list{
|
||||||
width: 32.5%;
|
margin-top: 0.25rem;
|
||||||
}
|
height: 300px;
|
||||||
|
font-weight: normal;
|
||||||
#weighted-settings .hints-div .hints-wrapper .hint-div{
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
cursor: pointer;
|
|
||||||
user-select: none;
|
|
||||||
-moz-user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#weighted-settings .hints-div .hints-wrapper .hint-div:hover{
|
|
||||||
background-color: rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#weighted-settings .hints-div .hints-wrapper .hint-div label{
|
|
||||||
flex-grow: 1;
|
|
||||||
padding: 0.125rem 0.5rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#weighted-settings #weighted-settings-button-row{
|
#weighted-settings #weighted-settings-button-row{
|
||||||
@@ -280,6 +268,30 @@ html{
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#weighted-settings .simple-list{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: auto;
|
||||||
|
border: 1px solid #ffffff;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#weighted-settings .simple-list .list-row label{
|
||||||
|
display: block;
|
||||||
|
width: calc(100% - 0.5rem);
|
||||||
|
padding: 0.0625rem 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#weighted-settings .simple-list .list-row label:hover{
|
||||||
|
background-color: rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#weighted-settings .simple-list .list-row label input[type=checkbox]{
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
#weighted-settings .invisible{
|
#weighted-settings .invisible{
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,28 @@
|
|||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="spoiler">Spoiler Log:
|
||||||
|
<span class="interactive" data-tooltip="Generates a text listing all randomized elements.
|
||||||
|
Warning: playthrough can take a significant amount of time for larger multiworlds.">
|
||||||
|
(?)
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="spoiler" id="spoiler">
|
||||||
|
{% if race -%}
|
||||||
|
<option value="0">Disabled in Race mode</option>
|
||||||
|
{%- else -%}
|
||||||
|
<option value="3">Enabled with playthrough and traversal</option>
|
||||||
|
<option value="2">Enabled with playthrough</option>
|
||||||
|
<option value="1">Enabled</option>
|
||||||
|
<option value="0">Disabled</option>
|
||||||
|
{%- endif -%}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,10 +11,18 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="base-header-right">
|
<div id="base-header-right">
|
||||||
<a href="/games">supported games</a>
|
<div id="base-header-popover-text">
|
||||||
<a href="/tutorial">setup guides</a>
|
<img id="base-header-popover-icon" src="/static/static/button-images/popover.png" alt="Popover Menu" />
|
||||||
<a href="/start-playing">start playing</a>
|
get started
|
||||||
<a href="/faq/en">f.a.q.</a>
|
</div>
|
||||||
|
<div id="base-header-popover-menu">
|
||||||
|
<a href="/games">supported games</a>
|
||||||
|
<a href="/tutorial">setup guides</a>
|
||||||
|
<a href="/generate">generate game</a>
|
||||||
|
<a href="/uploads">host game</a>
|
||||||
|
<a href="/user-content">user content</a>
|
||||||
|
</div>
|
||||||
|
<a href="/faq/en">f.a.q</a>
|
||||||
<a href="https://discord.gg/8Z65BR2" target="_blank">discord</a>
|
<a href="https://discord.gg/8Z65BR2" target="_blank">discord</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="base-header-right-mobile">
|
<div id="base-header-right-mobile">
|
||||||
@@ -22,12 +30,14 @@
|
|||||||
<img src="/static/static/button-images/hamburger-menu-icon.png" alt="Menu" />
|
<img src="/static/static/button-images/hamburger-menu-icon.png" alt="Menu" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="base-header-mobile-menu">
|
||||||
|
<a href="/games">supported games</a>
|
||||||
|
<a href="/tutorial">setup guides</a>
|
||||||
|
<a href="/faq/en">f.a.q.</a>
|
||||||
|
<a href="/generate">generate game</a>
|
||||||
|
<a href="/uploads">host game</a>
|
||||||
|
<a href="/user-content">user content</a>
|
||||||
|
<a href="https://discord.gg/8Z65BR2" target="_blank">discord</a>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div id="base-header-mobile-menu">
|
|
||||||
<a href="/games">supported games</a>
|
|
||||||
<a href="/tutorial">setup guides</a>
|
|
||||||
<a href="/start-playing">start playing</a>
|
|
||||||
<a href="/faq/en">f.a.q.</a>
|
|
||||||
<a href="https://discord.gg/8Z65BR2" target="_blank">discord</a>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -32,13 +32,18 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{ macros.list_patches_room(room) }}
|
{{ macros.list_patches_room(room) }}
|
||||||
{% if room.owner == session["_id"] %}
|
{% if room.owner == session["_id"] %}
|
||||||
<form method=post>
|
<div style="display: flex; align-items: center;">
|
||||||
<div class="form-group">
|
<form method=post style="flex-grow: 1; margin-right: 1em;">
|
||||||
<label for="cmd"></label>
|
<div class="form-group">
|
||||||
<input class="form-control" type="text" id="cmd" name="cmd"
|
<label for="cmd"></label>
|
||||||
placeholder="Server Command. /help to list them, list gets appended to log.">
|
<input class="form-control" type="text" id="cmd" name="cmd"
|
||||||
</div>
|
placeholder="Server Command. /help to list them, list gets appended to log.">
|
||||||
</form>
|
</div>
|
||||||
|
</form>
|
||||||
|
<a href="{{ url_for("display_log", room=room.id) }}">
|
||||||
|
Open Log File...
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div id="logger"></div>
|
<div id="logger"></div>
|
||||||
<script type="application/ecmascript">
|
<script type="application/ecmascript">
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|||||||
@@ -25,27 +25,34 @@
|
|||||||
<td data-tooltip="Connect via TextClient"><a href="archipelago://{{ patch.player_name | e}}:@{{ config['HOST_ADDRESS'] }}:{{ room.last_port }}">{{ patch.player_name }}</a></td>
|
<td data-tooltip="Connect via TextClient"><a href="archipelago://{{ patch.player_name | e}}:@{{ config['HOST_ADDRESS'] }}:{{ room.last_port }}">{{ patch.player_name }}</a></td>
|
||||||
<td>{{ patch.game }}</td>
|
<td>{{ patch.game }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if patch.game == "Minecraft" %}
|
{% if patch.data %}
|
||||||
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
{% if patch.game == "Minecraft" %}
|
||||||
Download APMC File...</a>
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
{% elif patch.game == "Factorio" %}
|
Download APMC File...</a>
|
||||||
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
{% elif patch.game == "Factorio" %}
|
||||||
Download Factorio Mod...</a>
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
{% elif patch.game == "Ocarina of Time" %}
|
Download Factorio Mod...</a>
|
||||||
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
{% elif patch.game == "Kingdom Hearts 2" %}
|
||||||
Download APZ5 File...</a>
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
{% elif patch.game == "VVVVVV" and room.seed.slots|length == 1 %}
|
Download Kingdom Hearts 2 Mod...</a>
|
||||||
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
{% elif patch.game == "Ocarina of Time" %}
|
||||||
Download APV6 File...</a>
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
{% elif patch.game == "Super Mario 64" and room.seed.slots|length == 1 %}
|
Download APZ5 File...</a>
|
||||||
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
{% elif patch.game == "VVVVVV" and room.seed.slots|length == 1 %}
|
||||||
Download APSM64EX File...</a>
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
{% elif patch.game | supports_apdeltapatch %}
|
Download APV6 File...</a>
|
||||||
<a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}" download>
|
{% elif patch.game == "Super Mario 64" and room.seed.slots|length == 1 %}
|
||||||
Download Patch File...</a>
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
{% elif patch.game == "Dark Souls III" and patch.data %}
|
Download APSM64EX File...</a>
|
||||||
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
{% elif patch.game | supports_apdeltapatch %}
|
||||||
Download JSON File...</a>
|
<a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}" download>
|
||||||
|
Download Patch File...</a>
|
||||||
|
{% elif patch.game == "Dark Souls III" %}
|
||||||
|
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
|
||||||
|
Download JSON File...</a>
|
||||||
|
{% else %}
|
||||||
|
No file to download for this game.
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
No file to download for this game.
|
No file to download for this game.
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
<th class="center-column">Checks</th>
|
<th class="center-column">Checks</th>
|
||||||
<th class="center-column">%</th>
|
<th class="center-column">%</th>
|
||||||
|
<th class="center-column">Status</th>
|
||||||
<th class="center-column hours">Last<br>Activity</th>
|
<th class="center-column hours">Last<br>Activity</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -51,8 +52,10 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
<td class="center-column">{{ checks["Total"] }}/{{ checks_in_area[player]["Total"] }}</td>
|
<td class="center-column">{{ checks["Total"] }}/{{ checks_in_area[player]["Total"] }}</td>
|
||||||
<td class="center-column">{{ percent_total_checks_done[team][player] }}</td>
|
<td class="center-column">{{ percent_total_checks_done[team][player] }}</td>
|
||||||
{%- if activity_timers[(team, player)] -%}
|
<td>{{ {0: "Disconnected", 5: "Connected", 10: "Ready", 20: "Playing",
|
||||||
<td class="center-column">{{ activity_timers[(team, player)].total_seconds() }}</td>
|
30: "Goal Completed"}.get(states[team, player], "Unknown State") }}</td>
|
||||||
|
{%- if activity_timers[team, player] -%}
|
||||||
|
<td class="center-column">{{ activity_timers[team, player].total_seconds() }}</td>
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
<td class="center-column">None</td>
|
<td class="center-column">None</td>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div id="tracker-navigation">
|
<div id="tracker-navigation">
|
||||||
{% for enabled_tracker in enabled_multiworld_trackers %}
|
{% for enabled_tracker in enabled_multiworld_trackers %}
|
||||||
{% set tracker_url = url_for(enabled_tracker.endpoint, tracker=room.tracker) %}
|
{% set tracker_url = url_for(enabled_tracker.endpoint, tracker=room.tracker) %}
|
||||||
<a class="tracker-navigation-button{%- if enabled_tracker.current -%} selected{% endif %}"
|
<a class="tracker-navigation-button{% if enabled_tracker.current %} selected{% endif %}"
|
||||||
href="{{ tracker_url }}">{{ enabled_tracker.name }}</a>
|
href="{{ tracker_url }}">{{ enabled_tracker.name }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ from werkzeug.exceptions import abort
|
|||||||
from MultiServer import Context, get_saving_second
|
from MultiServer import Context, get_saving_second
|
||||||
from NetUtils import SlotType
|
from NetUtils import SlotType
|
||||||
from Utils import restricted_loads
|
from Utils import restricted_loads
|
||||||
from worlds import lookup_any_item_id_to_name, lookup_any_location_id_to_name
|
from worlds import lookup_any_item_id_to_name, lookup_any_location_id_to_name, network_data_package
|
||||||
from worlds.alttp import Items
|
from worlds.alttp import Items
|
||||||
from . import app, cache
|
from . import app, cache
|
||||||
from .models import Room
|
from .models import GameDataPackage, Room
|
||||||
|
|
||||||
alttp_icons = {
|
alttp_icons = {
|
||||||
"Blue Shield": r"https://www.zeldadungeon.net/wiki/images/8/85/Fighters-Shield.png",
|
"Blue Shield": r"https://www.zeldadungeon.net/wiki/images/8/85/Fighters-Shield.png",
|
||||||
@@ -229,14 +229,15 @@ def render_timedelta(delta: datetime.timedelta):
|
|||||||
|
|
||||||
@pass_context
|
@pass_context
|
||||||
def get_location_name(context: runtime.Context, loc: int) -> str:
|
def get_location_name(context: runtime.Context, loc: int) -> str:
|
||||||
|
# once all rooms embed data package, the chain lookup can be dropped
|
||||||
context_locations = context.get("custom_locations", {})
|
context_locations = context.get("custom_locations", {})
|
||||||
return collections.ChainMap(lookup_any_location_id_to_name, context_locations).get(loc, loc)
|
return collections.ChainMap(context_locations, lookup_any_location_id_to_name).get(loc, loc)
|
||||||
|
|
||||||
|
|
||||||
@pass_context
|
@pass_context
|
||||||
def get_item_name(context: runtime.Context, item: int) -> str:
|
def get_item_name(context: runtime.Context, item: int) -> str:
|
||||||
context_items = context.get("custom_items", {})
|
context_items = context.get("custom_items", {})
|
||||||
return collections.ChainMap(lookup_any_item_id_to_name, context_items).get(item, item)
|
return collections.ChainMap(context_items, lookup_any_item_id_to_name).get(item, item)
|
||||||
|
|
||||||
|
|
||||||
app.jinja_env.filters["location_name"] = get_location_name
|
app.jinja_env.filters["location_name"] = get_location_name
|
||||||
@@ -274,11 +275,21 @@ def get_static_room_data(room: Room):
|
|||||||
if slot_info.type == SlotType.group}
|
if slot_info.type == SlotType.group}
|
||||||
|
|
||||||
for game in games.values():
|
for game in games.values():
|
||||||
if game in multidata["datapackage"]:
|
if game not in multidata["datapackage"]:
|
||||||
custom_locations.update(
|
continue
|
||||||
{id: name for name, id in multidata["datapackage"][game]["location_name_to_id"].items()})
|
game_data = multidata["datapackage"][game]
|
||||||
custom_items.update(
|
if "checksum" in game_data:
|
||||||
{id: name for name, id in multidata["datapackage"][game]["item_name_to_id"].items()})
|
if network_data_package["games"].get(game, {}).get("checksum") == game_data["checksum"]:
|
||||||
|
# non-custom. remove from multidata
|
||||||
|
# network_data_package import could be skipped once all rooms embed data package
|
||||||
|
del multidata["datapackage"][game]
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
game_data = restricted_loads(GameDataPackage.get(checksum=game_data["checksum"]).data)
|
||||||
|
custom_locations.update(
|
||||||
|
{id_: name for name, id_ in game_data["location_name_to_id"].items()})
|
||||||
|
custom_items.update(
|
||||||
|
{id_: name for name, id_ in game_data["item_name_to_id"].items()})
|
||||||
elif "games" in multidata:
|
elif "games" in multidata:
|
||||||
games = multidata["games"]
|
games = multidata["games"]
|
||||||
seed_checks_in_area = checks_in_area.copy()
|
seed_checks_in_area = checks_in_area.copy()
|
||||||
@@ -1373,24 +1384,26 @@ def _get_multiworld_tracker_data(tracker: UUID) -> typing.Optional[typing.Dict[s
|
|||||||
activity_timers[team, player] = now - datetime.datetime.utcfromtimestamp(timestamp)
|
activity_timers[team, player] = now - datetime.datetime.utcfromtimestamp(timestamp)
|
||||||
|
|
||||||
player_names = {}
|
player_names = {}
|
||||||
|
states: typing.Dict[typing.Tuple[int, int], int] = {}
|
||||||
for team, names in enumerate(names):
|
for team, names in enumerate(names):
|
||||||
for player, name in enumerate(names, 1):
|
for player, name in enumerate(names, 1):
|
||||||
player_names[(team, player)] = name
|
player_names[team, player] = name
|
||||||
|
states[team, player] = multisave.get("client_game_state", {}).get((team, player), 0)
|
||||||
long_player_names = player_names.copy()
|
long_player_names = player_names.copy()
|
||||||
for (team, player), alias in multisave.get("name_aliases", {}).items():
|
for (team, player), alias in multisave.get("name_aliases", {}).items():
|
||||||
player_names[(team, player)] = alias
|
player_names[team, player] = alias
|
||||||
long_player_names[(team, player)] = f"{alias} ({long_player_names[(team, player)]})"
|
long_player_names[(team, player)] = f"{alias} ({long_player_names[team, player]})"
|
||||||
|
|
||||||
video = {}
|
video = {}
|
||||||
for (team, player), data in multisave.get("video", []):
|
for (team, player), data in multisave.get("video", []):
|
||||||
video[(team, player)] = data
|
video[team, player] = data
|
||||||
|
|
||||||
return dict(player_names=player_names, room=room, checks_done=checks_done,
|
return dict(player_names=player_names, room=room, checks_done=checks_done,
|
||||||
percent_total_checks_done=percent_total_checks_done, checks_in_area=checks_in_area,
|
percent_total_checks_done=percent_total_checks_done, checks_in_area=checks_in_area,
|
||||||
activity_timers=activity_timers, video=video, hints=hints,
|
activity_timers=activity_timers, video=video, hints=hints,
|
||||||
long_player_names=long_player_names,
|
long_player_names=long_player_names,
|
||||||
multisave=multisave, precollected_items=precollected_items, groups=groups,
|
multisave=multisave, precollected_items=precollected_items, groups=groups,
|
||||||
locations=locations, games=games)
|
locations=locations, games=games, states=states)
|
||||||
|
|
||||||
|
|
||||||
def _get_inventory_data(data: typing.Dict[str, typing.Any]) -> typing.Dict[int, typing.Dict[int, int]]:
|
def _get_inventory_data(data: typing.Dict[str, typing.Any]) -> typing.Dict[int, typing.Dict[int, int]]:
|
||||||
|
|||||||
@@ -1,22 +1,60 @@
|
|||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
|
import pickle
|
||||||
import typing
|
import typing
|
||||||
import uuid
|
import uuid
|
||||||
import zipfile
|
import zipfile
|
||||||
from io import BytesIO
|
import zlib
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
from flask import request, flash, redirect, url_for, session, render_template, Markup
|
from flask import request, flash, redirect, url_for, session, render_template, Markup
|
||||||
from pony.orm import flush, select
|
from pony.orm import commit, flush, select, rollback
|
||||||
|
from pony.orm.core import TransactionIntegrityError
|
||||||
|
|
||||||
import MultiServer
|
import MultiServer
|
||||||
from NetUtils import NetworkSlot, SlotType
|
from NetUtils import NetworkSlot, SlotType
|
||||||
from Utils import VersionException, __version__
|
from Utils import VersionException, __version__
|
||||||
from worlds.Files import AutoPatchRegister
|
from worlds.Files import AutoPatchRegister
|
||||||
from . import app
|
from . import app
|
||||||
from .models import Seed, Room, Slot
|
from .models import Seed, Room, Slot, GameDataPackage
|
||||||
|
|
||||||
banned_zip_contents = (".sfc", ".z64", ".n64", ".sms", ".gb")
|
banned_zip_contents = (".sfc", ".z64", ".n64", ".sms", ".gb")
|
||||||
|
|
||||||
|
def process_multidata(compressed_multidata, files={}):
|
||||||
|
decompressed_multidata = MultiServer.Context.decompress(compressed_multidata)
|
||||||
|
|
||||||
|
slots: typing.Set[Slot] = set()
|
||||||
|
if "datapackage" in decompressed_multidata:
|
||||||
|
# strip datapackage from multidata, leaving only the checksums
|
||||||
|
game_data_packages: typing.List[GameDataPackage] = []
|
||||||
|
for game, game_data in decompressed_multidata["datapackage"].items():
|
||||||
|
if game_data.get("checksum"):
|
||||||
|
game_data_package = GameDataPackage(checksum=game_data["checksum"],
|
||||||
|
data=pickle.dumps(game_data))
|
||||||
|
decompressed_multidata["datapackage"][game] = {
|
||||||
|
"version": game_data.get("version", 0),
|
||||||
|
"checksum": game_data["checksum"]
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
commit() # commit game data package
|
||||||
|
game_data_packages.append(game_data_package)
|
||||||
|
except TransactionIntegrityError:
|
||||||
|
del game_data_package
|
||||||
|
rollback()
|
||||||
|
|
||||||
|
if "slot_info" in decompressed_multidata:
|
||||||
|
for slot, slot_info in decompressed_multidata["slot_info"].items():
|
||||||
|
# Ignore Player Groups (e.g. item links)
|
||||||
|
if slot_info.type == SlotType.group:
|
||||||
|
continue
|
||||||
|
slots.add(Slot(data=files.get(slot, None),
|
||||||
|
player_name=slot_info.name,
|
||||||
|
player_id=slot,
|
||||||
|
game=slot_info.game))
|
||||||
|
flush() # commit slots
|
||||||
|
|
||||||
|
compressed_multidata = compressed_multidata[0:1] + zlib.compress(pickle.dumps(decompressed_multidata), 9)
|
||||||
|
return slots, compressed_multidata
|
||||||
|
|
||||||
def upload_zip_to_db(zfile: zipfile.ZipFile, owner=None, meta={"race": False}, sid=None):
|
def upload_zip_to_db(zfile: zipfile.ZipFile, owner=None, meta={"race": False}, sid=None):
|
||||||
if not owner:
|
if not owner:
|
||||||
@@ -26,7 +64,7 @@ def upload_zip_to_db(zfile: zipfile.ZipFile, owner=None, meta={"race": False}, s
|
|||||||
flash(Markup("Error: Your .zip file only contains .yaml files. "
|
flash(Markup("Error: Your .zip file only contains .yaml files. "
|
||||||
'Did you mean to <a href="/generate">generate a game</a>?'))
|
'Did you mean to <a href="/generate">generate a game</a>?'))
|
||||||
return
|
return
|
||||||
slots: typing.Set[Slot] = set()
|
|
||||||
spoiler = ""
|
spoiler = ""
|
||||||
files = {}
|
files = {}
|
||||||
multidata = None
|
multidata = None
|
||||||
@@ -77,18 +115,7 @@ def upload_zip_to_db(zfile: zipfile.ZipFile, owner=None, meta={"race": False}, s
|
|||||||
|
|
||||||
# Load multi data.
|
# Load multi data.
|
||||||
if multidata:
|
if multidata:
|
||||||
decompressed_multidata = MultiServer.Context.decompress(multidata)
|
slots, multidata = process_multidata(multidata, files)
|
||||||
if "slot_info" in decompressed_multidata:
|
|
||||||
for slot, slot_info in decompressed_multidata["slot_info"].items():
|
|
||||||
# Ignore Player Groups (e.g. item links)
|
|
||||||
if slot_info.type == SlotType.group:
|
|
||||||
continue
|
|
||||||
slots.add(Slot(data=files.get(slot, None),
|
|
||||||
player_name=slot_info.name,
|
|
||||||
player_id=slot,
|
|
||||||
game=slot_info.game))
|
|
||||||
|
|
||||||
flush() # commit slots
|
|
||||||
|
|
||||||
seed = Seed(multidata=multidata, spoiler=spoiler, slots=slots, owner=owner, meta=json.dumps(meta),
|
seed = Seed(multidata=multidata, spoiler=spoiler, slots=slots, owner=owner, meta=json.dumps(meta),
|
||||||
id=sid if sid else uuid.uuid4())
|
id=sid if sid else uuid.uuid4())
|
||||||
@@ -129,11 +156,11 @@ def uploads():
|
|||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
multidata = file.read()
|
multidata = file.read()
|
||||||
MultiServer.Context.decompress(multidata)
|
slots, multidata = process_multidata(multidata)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
flash(f"Could not load multidata. File may be corrupted or incompatible. ({e})")
|
flash(f"Could not load multidata. File may be corrupted or incompatible. ({e})")
|
||||||
else:
|
else:
|
||||||
seed = Seed(multidata=multidata, owner=session["_id"])
|
seed = Seed(multidata=multidata, slots=slots, owner=session["_id"])
|
||||||
flush() # place into DB and generate ids
|
flush() # place into DB and generate ids
|
||||||
return redirect(url_for("view_seed", seed=seed.id))
|
return redirect(url_for("view_seed", seed=seed.id))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ from worlds.tloz import Items, Locations, Rom
|
|||||||
|
|
||||||
SYSTEM_MESSAGE_ID = 0
|
SYSTEM_MESSAGE_ID = 0
|
||||||
|
|
||||||
CONNECTION_TIMING_OUT_STATUS = "Connection timing out. Please restart your emulator, then restart Zelda_connector.lua"
|
CONNECTION_TIMING_OUT_STATUS = "Connection timing out. Please restart your emulator, then restart connector_tloz.lua"
|
||||||
CONNECTION_REFUSED_STATUS = "Connection Refused. Please start your emulator and make sure Zelda_connector.lua is running"
|
CONNECTION_REFUSED_STATUS = "Connection Refused. Please start your emulator and make sure connector_tloz.lua is running"
|
||||||
CONNECTION_RESET_STATUS = "Connection was reset. Please restart your emulator, then restart Zelda_connector.lua"
|
CONNECTION_RESET_STATUS = "Connection was reset. Please restart your emulator, then restart connector_tloz.lua"
|
||||||
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
CONNECTION_TENTATIVE_STATUS = "Initial Connection Made"
|
||||||
CONNECTION_CONNECTED_STATUS = "Connected"
|
CONNECTION_CONNECTED_STATUS = "Connected"
|
||||||
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
CONNECTION_INITIAL_STATUS = "Connection has not been initiated"
|
||||||
|
|||||||
BIN
data/adventure_basepatch.bsdiff4
Normal file
BIN
data/discord-mark-blue.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
data/icon.ico
|
Before Width: | Height: | Size: 214 KiB After Width: | Height: | Size: 255 KiB |
BIN
data/icon.png
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 37 KiB |
@@ -1,132 +0,0 @@
|
|||||||
-----------------------------------------------------------------------------
|
|
||||||
-- LuaSocket helper module
|
|
||||||
-- Author: Diego Nehab
|
|
||||||
-- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Declare module and import dependencies
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
local base = _G
|
|
||||||
local string = require("string")
|
|
||||||
local math = require("math")
|
|
||||||
local socket = require("socket.core")
|
|
||||||
module("socket")
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Exported auxiliar functions
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
function connect(address, port, laddress, lport)
|
|
||||||
local sock, err = socket.tcp()
|
|
||||||
if not sock then return nil, err end
|
|
||||||
if laddress then
|
|
||||||
local res, err = sock:bind(laddress, lport, -1)
|
|
||||||
if not res then return nil, err end
|
|
||||||
end
|
|
||||||
local res, err = sock:connect(address, port)
|
|
||||||
if not res then return nil, err end
|
|
||||||
return sock
|
|
||||||
end
|
|
||||||
|
|
||||||
function bind(host, port, backlog)
|
|
||||||
local sock, err = socket.tcp()
|
|
||||||
if not sock then return nil, err end
|
|
||||||
sock:setoption("reuseaddr", true)
|
|
||||||
local res, err = sock:bind(host, port)
|
|
||||||
if not res then return nil, err end
|
|
||||||
res, err = sock:listen(backlog)
|
|
||||||
if not res then return nil, err end
|
|
||||||
return sock
|
|
||||||
end
|
|
||||||
|
|
||||||
try = newtry()
|
|
||||||
|
|
||||||
function choose(table)
|
|
||||||
return function(name, opt1, opt2)
|
|
||||||
if base.type(name) ~= "string" then
|
|
||||||
name, opt1, opt2 = "default", name, opt1
|
|
||||||
end
|
|
||||||
local f = table[name or "nil"]
|
|
||||||
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
|
|
||||||
else return f(opt1, opt2) end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Socket sources and sinks, conforming to LTN12
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- create namespaces inside LuaSocket namespace
|
|
||||||
sourcet = {}
|
|
||||||
sinkt = {}
|
|
||||||
|
|
||||||
BLOCKSIZE = 2048
|
|
||||||
|
|
||||||
sinkt["close-when-done"] = function(sock)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function(self, chunk, err)
|
|
||||||
if not chunk then
|
|
||||||
sock:close()
|
|
||||||
return 1
|
|
||||||
else return sock:send(chunk) end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sinkt["keep-open"] = function(sock)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function(self, chunk, err)
|
|
||||||
if chunk then return sock:send(chunk)
|
|
||||||
else return 1 end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sinkt["default"] = sinkt["keep-open"]
|
|
||||||
|
|
||||||
sink = choose(sinkt)
|
|
||||||
|
|
||||||
sourcet["by-length"] = function(sock, length)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function()
|
|
||||||
if length <= 0 then return nil end
|
|
||||||
local size = math.min(socket.BLOCKSIZE, length)
|
|
||||||
local chunk, err = sock:receive(size)
|
|
||||||
if err then return nil, err end
|
|
||||||
length = length - string.len(chunk)
|
|
||||||
return chunk
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sourcet["until-closed"] = function(sock)
|
|
||||||
local done
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function()
|
|
||||||
if done then return nil end
|
|
||||||
local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
|
|
||||||
if not err then return chunk
|
|
||||||
elseif err == "closed" then
|
|
||||||
sock:close()
|
|
||||||
done = 1
|
|
||||||
return partial
|
|
||||||
else return nil, err end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
sourcet["default"] = sourcet["until-closed"]
|
|
||||||
|
|
||||||
source = choose(sourcet)
|
|
||||||
@@ -1,380 +0,0 @@
|
|||||||
--
|
|
||||||
-- json.lua
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2015 rxi
|
|
||||||
--
|
|
||||||
-- This library is free software; you can redistribute it and/or modify it
|
|
||||||
-- under the terms of the MIT license. See LICENSE for details.
|
|
||||||
--
|
|
||||||
|
|
||||||
local json = { _version = "0.1.0" }
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- Encode
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local encode
|
|
||||||
|
|
||||||
local escape_char_map = {
|
|
||||||
[ "\\" ] = "\\\\",
|
|
||||||
[ "\"" ] = "\\\"",
|
|
||||||
[ "\b" ] = "\\b",
|
|
||||||
[ "\f" ] = "\\f",
|
|
||||||
[ "\n" ] = "\\n",
|
|
||||||
[ "\r" ] = "\\r",
|
|
||||||
[ "\t" ] = "\\t",
|
|
||||||
}
|
|
||||||
|
|
||||||
local escape_char_map_inv = { [ "\\/" ] = "/" }
|
|
||||||
for k, v in pairs(escape_char_map) do
|
|
||||||
escape_char_map_inv[v] = k
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function escape_char(c)
|
|
||||||
return escape_char_map[c] or string.format("\\u%04x", c:byte())
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_nil(val)
|
|
||||||
return "null"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_table(val, stack)
|
|
||||||
local res = {}
|
|
||||||
stack = stack or {}
|
|
||||||
|
|
||||||
-- Circular reference?
|
|
||||||
if stack[val] then error("circular reference") end
|
|
||||||
|
|
||||||
stack[val] = true
|
|
||||||
|
|
||||||
if val[1] ~= nil or next(val) == nil then
|
|
||||||
-- Treat as array -- check keys are valid and it is not sparse
|
|
||||||
local n = 0
|
|
||||||
for k in pairs(val) do
|
|
||||||
if type(k) ~= "number" then
|
|
||||||
error("invalid table: mixed or invalid key types")
|
|
||||||
end
|
|
||||||
n = n + 1
|
|
||||||
end
|
|
||||||
if n ~= #val then
|
|
||||||
error("invalid table: sparse array")
|
|
||||||
end
|
|
||||||
-- Encode
|
|
||||||
for i, v in ipairs(val) do
|
|
||||||
table.insert(res, encode(v, stack))
|
|
||||||
end
|
|
||||||
stack[val] = nil
|
|
||||||
return "[" .. table.concat(res, ",") .. "]"
|
|
||||||
|
|
||||||
else
|
|
||||||
-- Treat as an object
|
|
||||||
for k, v in pairs(val) do
|
|
||||||
if type(k) ~= "string" then
|
|
||||||
error("invalid table: mixed or invalid key types")
|
|
||||||
end
|
|
||||||
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
|
|
||||||
end
|
|
||||||
stack[val] = nil
|
|
||||||
return "{" .. table.concat(res, ",") .. "}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_string(val)
|
|
||||||
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_number(val)
|
|
||||||
-- Check for NaN, -inf and inf
|
|
||||||
if val ~= val or val <= -math.huge or val >= math.huge then
|
|
||||||
error("unexpected number value '" .. tostring(val) .. "'")
|
|
||||||
end
|
|
||||||
return string.format("%.14g", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local type_func_map = {
|
|
||||||
[ "nil" ] = encode_nil,
|
|
||||||
[ "table" ] = encode_table,
|
|
||||||
[ "string" ] = encode_string,
|
|
||||||
[ "number" ] = encode_number,
|
|
||||||
[ "boolean" ] = tostring,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encode = function(val, stack)
|
|
||||||
local t = type(val)
|
|
||||||
local f = type_func_map[t]
|
|
||||||
if f then
|
|
||||||
return f(val, stack)
|
|
||||||
end
|
|
||||||
error("unexpected type '" .. t .. "'")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function json.encode(val)
|
|
||||||
return ( encode(val) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- Decode
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local parse
|
|
||||||
|
|
||||||
local function create_set(...)
|
|
||||||
local res = {}
|
|
||||||
for i = 1, select("#", ...) do
|
|
||||||
res[ select(i, ...) ] = true
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
|
|
||||||
local space_chars = create_set(" ", "\t", "\r", "\n")
|
|
||||||
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
|
||||||
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
|
||||||
local literals = create_set("true", "false", "null")
|
|
||||||
|
|
||||||
local literal_map = {
|
|
||||||
[ "true" ] = true,
|
|
||||||
[ "false" ] = false,
|
|
||||||
[ "null" ] = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
local function next_char(str, idx, set, negate)
|
|
||||||
for i = idx, #str do
|
|
||||||
if set[str:sub(i, i)] ~= negate then
|
|
||||||
return i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return #str + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function decode_error(str, idx, msg)
|
|
||||||
--local line_count = 1
|
|
||||||
--local col_count = 1
|
|
||||||
--for i = 1, idx - 1 do
|
|
||||||
-- col_count = col_count + 1
|
|
||||||
-- if str:sub(i, i) == "\n" then
|
|
||||||
-- line_count = line_count + 1
|
|
||||||
-- col_count = 1
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- emu.message( string.format("%s at line %d col %d", msg, line_count, col_count) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function codepoint_to_utf8(n)
|
|
||||||
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
|
||||||
local f = math.floor
|
|
||||||
if n <= 0x7f then
|
|
||||||
return string.char(n)
|
|
||||||
elseif n <= 0x7ff then
|
|
||||||
return string.char(f(n / 64) + 192, n % 64 + 128)
|
|
||||||
elseif n <= 0xffff then
|
|
||||||
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
|
|
||||||
elseif n <= 0x10ffff then
|
|
||||||
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
|
|
||||||
f(n % 4096 / 64) + 128, n % 64 + 128)
|
|
||||||
end
|
|
||||||
error( string.format("invalid unicode codepoint '%x'", n) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_unicode_escape(s)
|
|
||||||
local n1 = tonumber( s:sub(3, 6), 16 )
|
|
||||||
local n2 = tonumber( s:sub(9, 12), 16 )
|
|
||||||
-- Surrogate pair?
|
|
||||||
if n2 then
|
|
||||||
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
|
|
||||||
else
|
|
||||||
return codepoint_to_utf8(n1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_string(str, i)
|
|
||||||
local has_unicode_escape = false
|
|
||||||
local has_surrogate_escape = false
|
|
||||||
local has_escape = false
|
|
||||||
local last
|
|
||||||
for j = i + 1, #str do
|
|
||||||
local x = str:byte(j)
|
|
||||||
|
|
||||||
if x < 32 then
|
|
||||||
decode_error(str, j, "control character in string")
|
|
||||||
end
|
|
||||||
|
|
||||||
if last == 92 then -- "\\" (escape char)
|
|
||||||
if x == 117 then -- "u" (unicode escape sequence)
|
|
||||||
local hex = str:sub(j + 1, j + 5)
|
|
||||||
if not hex:find("%x%x%x%x") then
|
|
||||||
decode_error(str, j, "invalid unicode escape in string")
|
|
||||||
end
|
|
||||||
if hex:find("^[dD][89aAbB]") then
|
|
||||||
has_surrogate_escape = true
|
|
||||||
else
|
|
||||||
has_unicode_escape = true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local c = string.char(x)
|
|
||||||
if not escape_chars[c] then
|
|
||||||
decode_error(str, j, "invalid escape char '" .. c .. "' in string")
|
|
||||||
end
|
|
||||||
has_escape = true
|
|
||||||
end
|
|
||||||
last = nil
|
|
||||||
|
|
||||||
elseif x == 34 then -- '"' (end of string)
|
|
||||||
local s = str:sub(i + 1, j - 1)
|
|
||||||
if has_surrogate_escape then
|
|
||||||
s = s:gsub("\\u[dD][89aAbB]..\\u....", parse_unicode_escape)
|
|
||||||
end
|
|
||||||
if has_unicode_escape then
|
|
||||||
s = s:gsub("\\u....", parse_unicode_escape)
|
|
||||||
end
|
|
||||||
if has_escape then
|
|
||||||
s = s:gsub("\\.", escape_char_map_inv)
|
|
||||||
end
|
|
||||||
return s, j + 1
|
|
||||||
|
|
||||||
else
|
|
||||||
last = x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
decode_error(str, i, "expected closing quote for string")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_number(str, i)
|
|
||||||
local x = next_char(str, i, delim_chars)
|
|
||||||
local s = str:sub(i, x - 1)
|
|
||||||
local n = tonumber(s)
|
|
||||||
if not n then
|
|
||||||
decode_error(str, i, "invalid number '" .. s .. "'")
|
|
||||||
end
|
|
||||||
return n, x
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_literal(str, i)
|
|
||||||
local x = next_char(str, i, delim_chars)
|
|
||||||
local word = str:sub(i, x - 1)
|
|
||||||
if not literals[word] then
|
|
||||||
decode_error(str, i, "invalid literal '" .. word .. "'")
|
|
||||||
end
|
|
||||||
return literal_map[word], x
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_array(str, i)
|
|
||||||
local res = {}
|
|
||||||
local n = 1
|
|
||||||
i = i + 1
|
|
||||||
while 1 do
|
|
||||||
local x
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
-- Empty / end of array?
|
|
||||||
if str:sub(i, i) == "]" then
|
|
||||||
i = i + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- Read token
|
|
||||||
x, i = parse(str, i)
|
|
||||||
res[n] = x
|
|
||||||
n = n + 1
|
|
||||||
-- Next token
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
local chr = str:sub(i, i)
|
|
||||||
i = i + 1
|
|
||||||
if chr == "]" then break end
|
|
||||||
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
|
|
||||||
end
|
|
||||||
return res, i
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_object(str, i)
|
|
||||||
local res = {}
|
|
||||||
i = i + 1
|
|
||||||
while 1 do
|
|
||||||
local key, val
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
-- Empty / end of object?
|
|
||||||
if str:sub(i, i) == "}" then
|
|
||||||
i = i + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- Read key
|
|
||||||
if str:sub(i, i) ~= '"' then
|
|
||||||
decode_error(str, i, "expected string for key")
|
|
||||||
end
|
|
||||||
key, i = parse(str, i)
|
|
||||||
-- Read ':' delimiter
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
if str:sub(i, i) ~= ":" then
|
|
||||||
decode_error(str, i, "expected ':' after key")
|
|
||||||
end
|
|
||||||
i = next_char(str, i + 1, space_chars, true)
|
|
||||||
-- Read value
|
|
||||||
val, i = parse(str, i)
|
|
||||||
-- Set
|
|
||||||
res[key] = val
|
|
||||||
-- Next token
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
local chr = str:sub(i, i)
|
|
||||||
i = i + 1
|
|
||||||
if chr == "}" then break end
|
|
||||||
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
|
|
||||||
end
|
|
||||||
return res, i
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local char_func_map = {
|
|
||||||
[ '"' ] = parse_string,
|
|
||||||
[ "0" ] = parse_number,
|
|
||||||
[ "1" ] = parse_number,
|
|
||||||
[ "2" ] = parse_number,
|
|
||||||
[ "3" ] = parse_number,
|
|
||||||
[ "4" ] = parse_number,
|
|
||||||
[ "5" ] = parse_number,
|
|
||||||
[ "6" ] = parse_number,
|
|
||||||
[ "7" ] = parse_number,
|
|
||||||
[ "8" ] = parse_number,
|
|
||||||
[ "9" ] = parse_number,
|
|
||||||
[ "-" ] = parse_number,
|
|
||||||
[ "t" ] = parse_literal,
|
|
||||||
[ "f" ] = parse_literal,
|
|
||||||
[ "n" ] = parse_literal,
|
|
||||||
[ "[" ] = parse_array,
|
|
||||||
[ "{" ] = parse_object,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
parse = function(str, idx)
|
|
||||||
local chr = str:sub(idx, idx)
|
|
||||||
local f = char_func_map[chr]
|
|
||||||
if f then
|
|
||||||
return f(str, idx)
|
|
||||||
end
|
|
||||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function json.decode(str)
|
|
||||||
if type(str) ~= "string" then
|
|
||||||
error("expected argument of type string, got " .. type(str))
|
|
||||||
end
|
|
||||||
return ( parse(str, next_char(str, 1, space_chars, true)) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return json
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
-----------------------------------------------------------------------------
|
|
||||||
-- LuaSocket helper module
|
|
||||||
-- Author: Diego Nehab
|
|
||||||
-- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Declare module and import dependencies
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
local base = _G
|
|
||||||
local string = require("string")
|
|
||||||
local math = require("math")
|
|
||||||
local socket = require("socket.core")
|
|
||||||
module("socket")
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Exported auxiliar functions
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
function connect(address, port, laddress, lport)
|
|
||||||
local sock, err = socket.tcp()
|
|
||||||
if not sock then return nil, err end
|
|
||||||
if laddress then
|
|
||||||
local res, err = sock:bind(laddress, lport, -1)
|
|
||||||
if not res then return nil, err end
|
|
||||||
end
|
|
||||||
local res, err = sock:connect(address, port)
|
|
||||||
if not res then return nil, err end
|
|
||||||
return sock
|
|
||||||
end
|
|
||||||
|
|
||||||
function bind(host, port, backlog)
|
|
||||||
local sock, err = socket.tcp()
|
|
||||||
if not sock then return nil, err end
|
|
||||||
sock:setoption("reuseaddr", true)
|
|
||||||
local res, err = sock:bind(host, port)
|
|
||||||
if not res then return nil, err end
|
|
||||||
res, err = sock:listen(backlog)
|
|
||||||
if not res then return nil, err end
|
|
||||||
return sock
|
|
||||||
end
|
|
||||||
|
|
||||||
try = newtry()
|
|
||||||
|
|
||||||
function choose(table)
|
|
||||||
return function(name, opt1, opt2)
|
|
||||||
if base.type(name) ~= "string" then
|
|
||||||
name, opt1, opt2 = "default", name, opt1
|
|
||||||
end
|
|
||||||
local f = table[name or "nil"]
|
|
||||||
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
|
|
||||||
else return f(opt1, opt2) end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Socket sources and sinks, conforming to LTN12
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- create namespaces inside LuaSocket namespace
|
|
||||||
sourcet = {}
|
|
||||||
sinkt = {}
|
|
||||||
|
|
||||||
BLOCKSIZE = 2048
|
|
||||||
|
|
||||||
sinkt["close-when-done"] = function(sock)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function(self, chunk, err)
|
|
||||||
if not chunk then
|
|
||||||
sock:close()
|
|
||||||
return 1
|
|
||||||
else return sock:send(chunk) end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sinkt["keep-open"] = function(sock)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function(self, chunk, err)
|
|
||||||
if chunk then return sock:send(chunk)
|
|
||||||
else return 1 end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sinkt["default"] = sinkt["keep-open"]
|
|
||||||
|
|
||||||
sink = choose(sinkt)
|
|
||||||
|
|
||||||
sourcet["by-length"] = function(sock, length)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function()
|
|
||||||
if length <= 0 then return nil end
|
|
||||||
local size = math.min(socket.BLOCKSIZE, length)
|
|
||||||
local chunk, err = sock:receive(size)
|
|
||||||
if err then return nil, err end
|
|
||||||
length = length - string.len(chunk)
|
|
||||||
return chunk
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sourcet["until-closed"] = function(sock)
|
|
||||||
local done
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function()
|
|
||||||
if done then return nil end
|
|
||||||
local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
|
|
||||||
if not err then return chunk
|
|
||||||
elseif err == "closed" then
|
|
||||||
sock:close()
|
|
||||||
done = 1
|
|
||||||
return partial
|
|
||||||
else return nil, err end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
sourcet["default"] = sourcet["until-closed"]
|
|
||||||
|
|
||||||
source = choose(sourcet)
|
|
||||||
@@ -1,389 +0,0 @@
|
|||||||
--
|
|
||||||
-- json.lua
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2015 rxi
|
|
||||||
--
|
|
||||||
-- This library is free software; you can redistribute it and/or modify it
|
|
||||||
-- under the terms of the MIT license. See LICENSE for details.
|
|
||||||
--
|
|
||||||
|
|
||||||
local json = { _version = "0.1.0" }
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- Encode
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local encode
|
|
||||||
|
|
||||||
function error(err)
|
|
||||||
print(err)
|
|
||||||
end
|
|
||||||
|
|
||||||
local escape_char_map = {
|
|
||||||
[ "\\" ] = "\\\\",
|
|
||||||
[ "\"" ] = "\\\"",
|
|
||||||
[ "\b" ] = "\\b",
|
|
||||||
[ "\f" ] = "\\f",
|
|
||||||
[ "\n" ] = "\\n",
|
|
||||||
[ "\r" ] = "\\r",
|
|
||||||
[ "\t" ] = "\\t",
|
|
||||||
}
|
|
||||||
|
|
||||||
local escape_char_map_inv = { [ "\\/" ] = "/" }
|
|
||||||
for k, v in pairs(escape_char_map) do
|
|
||||||
escape_char_map_inv[v] = k
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function escape_char(c)
|
|
||||||
return escape_char_map[c] or string.format("\\u%04x", c:byte())
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_nil(val)
|
|
||||||
return "null"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_table(val, stack)
|
|
||||||
local res = {}
|
|
||||||
stack = stack or {}
|
|
||||||
|
|
||||||
-- Circular reference?
|
|
||||||
if stack[val] then error("circular reference") end
|
|
||||||
|
|
||||||
stack[val] = true
|
|
||||||
|
|
||||||
if val[1] ~= nil or next(val) == nil then
|
|
||||||
-- Treat as array -- check keys are valid and it is not sparse
|
|
||||||
local n = 0
|
|
||||||
for k in pairs(val) do
|
|
||||||
if type(k) ~= "number" then
|
|
||||||
error("invalid table: mixed or invalid key types")
|
|
||||||
end
|
|
||||||
n = n + 1
|
|
||||||
end
|
|
||||||
if n ~= #val then
|
|
||||||
print("invalid table: sparse array")
|
|
||||||
print(n)
|
|
||||||
print("VAL:")
|
|
||||||
print(val)
|
|
||||||
print("STACK:")
|
|
||||||
print(stack)
|
|
||||||
end
|
|
||||||
-- Encode
|
|
||||||
for i, v in ipairs(val) do
|
|
||||||
table.insert(res, encode(v, stack))
|
|
||||||
end
|
|
||||||
stack[val] = nil
|
|
||||||
return "[" .. table.concat(res, ",") .. "]"
|
|
||||||
|
|
||||||
else
|
|
||||||
-- Treat as an object
|
|
||||||
for k, v in pairs(val) do
|
|
||||||
if type(k) ~= "string" then
|
|
||||||
error("invalid table: mixed or invalid key types")
|
|
||||||
end
|
|
||||||
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
|
|
||||||
end
|
|
||||||
stack[val] = nil
|
|
||||||
return "{" .. table.concat(res, ",") .. "}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_string(val)
|
|
||||||
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_number(val)
|
|
||||||
-- Check for NaN, -inf and inf
|
|
||||||
if val ~= val or val <= -math.huge or val >= math.huge then
|
|
||||||
error("unexpected number value '" .. tostring(val) .. "'")
|
|
||||||
end
|
|
||||||
return string.format("%.14g", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local type_func_map = {
|
|
||||||
[ "nil" ] = encode_nil,
|
|
||||||
[ "table" ] = encode_table,
|
|
||||||
[ "string" ] = encode_string,
|
|
||||||
[ "number" ] = encode_number,
|
|
||||||
[ "boolean" ] = tostring,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encode = function(val, stack)
|
|
||||||
local t = type(val)
|
|
||||||
local f = type_func_map[t]
|
|
||||||
if f then
|
|
||||||
return f(val, stack)
|
|
||||||
end
|
|
||||||
error("unexpected type '" .. t .. "'")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function json.encode(val)
|
|
||||||
return ( encode(val) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- Decode
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local parse
|
|
||||||
|
|
||||||
local function create_set(...)
|
|
||||||
local res = {}
|
|
||||||
for i = 1, select("#", ...) do
|
|
||||||
res[ select(i, ...) ] = true
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
|
|
||||||
local space_chars = create_set(" ", "\t", "\r", "\n")
|
|
||||||
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
|
||||||
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
|
||||||
local literals = create_set("true", "false", "null")
|
|
||||||
|
|
||||||
local literal_map = {
|
|
||||||
[ "true" ] = true,
|
|
||||||
[ "false" ] = false,
|
|
||||||
[ "null" ] = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
local function next_char(str, idx, set, negate)
|
|
||||||
for i = idx, #str do
|
|
||||||
if set[str:sub(i, i)] ~= negate then
|
|
||||||
return i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return #str + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function decode_error(str, idx, msg)
|
|
||||||
--local line_count = 1
|
|
||||||
--local col_count = 1
|
|
||||||
--for i = 1, idx - 1 do
|
|
||||||
-- col_count = col_count + 1
|
|
||||||
-- if str:sub(i, i) == "\n" then
|
|
||||||
-- line_count = line_count + 1
|
|
||||||
-- col_count = 1
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- emu.message( string.format("%s at line %d col %d", msg, line_count, col_count) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function codepoint_to_utf8(n)
|
|
||||||
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
|
||||||
local f = math.floor
|
|
||||||
if n <= 0x7f then
|
|
||||||
return string.char(n)
|
|
||||||
elseif n <= 0x7ff then
|
|
||||||
return string.char(f(n / 64) + 192, n % 64 + 128)
|
|
||||||
elseif n <= 0xffff then
|
|
||||||
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
|
|
||||||
elseif n <= 0x10ffff then
|
|
||||||
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
|
|
||||||
f(n % 4096 / 64) + 128, n % 64 + 128)
|
|
||||||
end
|
|
||||||
error( string.format("invalid unicode codepoint '%x'", n) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_unicode_escape(s)
|
|
||||||
local n1 = tonumber( s:sub(3, 6), 16 )
|
|
||||||
local n2 = tonumber( s:sub(9, 12), 16 )
|
|
||||||
-- Surrogate pair?
|
|
||||||
if n2 then
|
|
||||||
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
|
|
||||||
else
|
|
||||||
return codepoint_to_utf8(n1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_string(str, i)
|
|
||||||
local has_unicode_escape = false
|
|
||||||
local has_surrogate_escape = false
|
|
||||||
local has_escape = false
|
|
||||||
local last
|
|
||||||
for j = i + 1, #str do
|
|
||||||
local x = str:byte(j)
|
|
||||||
|
|
||||||
if x < 32 then
|
|
||||||
decode_error(str, j, "control character in string")
|
|
||||||
end
|
|
||||||
|
|
||||||
if last == 92 then -- "\\" (escape char)
|
|
||||||
if x == 117 then -- "u" (unicode escape sequence)
|
|
||||||
local hex = str:sub(j + 1, j + 5)
|
|
||||||
if not hex:find("%x%x%x%x") then
|
|
||||||
decode_error(str, j, "invalid unicode escape in string")
|
|
||||||
end
|
|
||||||
if hex:find("^[dD][89aAbB]") then
|
|
||||||
has_surrogate_escape = true
|
|
||||||
else
|
|
||||||
has_unicode_escape = true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local c = string.char(x)
|
|
||||||
if not escape_chars[c] then
|
|
||||||
decode_error(str, j, "invalid escape char '" .. c .. "' in string")
|
|
||||||
end
|
|
||||||
has_escape = true
|
|
||||||
end
|
|
||||||
last = nil
|
|
||||||
|
|
||||||
elseif x == 34 then -- '"' (end of string)
|
|
||||||
local s = str:sub(i + 1, j - 1)
|
|
||||||
if has_surrogate_escape then
|
|
||||||
s = s:gsub("\\u[dD][89aAbB]..\\u....", parse_unicode_escape)
|
|
||||||
end
|
|
||||||
if has_unicode_escape then
|
|
||||||
s = s:gsub("\\u....", parse_unicode_escape)
|
|
||||||
end
|
|
||||||
if has_escape then
|
|
||||||
s = s:gsub("\\.", escape_char_map_inv)
|
|
||||||
end
|
|
||||||
return s, j + 1
|
|
||||||
|
|
||||||
else
|
|
||||||
last = x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
decode_error(str, i, "expected closing quote for string")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_number(str, i)
|
|
||||||
local x = next_char(str, i, delim_chars)
|
|
||||||
local s = str:sub(i, x - 1)
|
|
||||||
local n = tonumber(s)
|
|
||||||
if not n then
|
|
||||||
decode_error(str, i, "invalid number '" .. s .. "'")
|
|
||||||
end
|
|
||||||
return n, x
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_literal(str, i)
|
|
||||||
local x = next_char(str, i, delim_chars)
|
|
||||||
local word = str:sub(i, x - 1)
|
|
||||||
if not literals[word] then
|
|
||||||
decode_error(str, i, "invalid literal '" .. word .. "'")
|
|
||||||
end
|
|
||||||
return literal_map[word], x
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_array(str, i)
|
|
||||||
local res = {}
|
|
||||||
local n = 1
|
|
||||||
i = i + 1
|
|
||||||
while 1 do
|
|
||||||
local x
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
-- Empty / end of array?
|
|
||||||
if str:sub(i, i) == "]" then
|
|
||||||
i = i + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- Read token
|
|
||||||
x, i = parse(str, i)
|
|
||||||
res[n] = x
|
|
||||||
n = n + 1
|
|
||||||
-- Next token
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
local chr = str:sub(i, i)
|
|
||||||
i = i + 1
|
|
||||||
if chr == "]" then break end
|
|
||||||
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
|
|
||||||
end
|
|
||||||
return res, i
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_object(str, i)
|
|
||||||
local res = {}
|
|
||||||
i = i + 1
|
|
||||||
while 1 do
|
|
||||||
local key, val
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
-- Empty / end of object?
|
|
||||||
if str:sub(i, i) == "}" then
|
|
||||||
i = i + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- Read key
|
|
||||||
if str:sub(i, i) ~= '"' then
|
|
||||||
decode_error(str, i, "expected string for key")
|
|
||||||
end
|
|
||||||
key, i = parse(str, i)
|
|
||||||
-- Read ':' delimiter
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
if str:sub(i, i) ~= ":" then
|
|
||||||
decode_error(str, i, "expected ':' after key")
|
|
||||||
end
|
|
||||||
i = next_char(str, i + 1, space_chars, true)
|
|
||||||
-- Read value
|
|
||||||
val, i = parse(str, i)
|
|
||||||
-- Set
|
|
||||||
res[key] = val
|
|
||||||
-- Next token
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
local chr = str:sub(i, i)
|
|
||||||
i = i + 1
|
|
||||||
if chr == "}" then break end
|
|
||||||
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
|
|
||||||
end
|
|
||||||
return res, i
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local char_func_map = {
|
|
||||||
[ '"' ] = parse_string,
|
|
||||||
[ "0" ] = parse_number,
|
|
||||||
[ "1" ] = parse_number,
|
|
||||||
[ "2" ] = parse_number,
|
|
||||||
[ "3" ] = parse_number,
|
|
||||||
[ "4" ] = parse_number,
|
|
||||||
[ "5" ] = parse_number,
|
|
||||||
[ "6" ] = parse_number,
|
|
||||||
[ "7" ] = parse_number,
|
|
||||||
[ "8" ] = parse_number,
|
|
||||||
[ "9" ] = parse_number,
|
|
||||||
[ "-" ] = parse_number,
|
|
||||||
[ "t" ] = parse_literal,
|
|
||||||
[ "f" ] = parse_literal,
|
|
||||||
[ "n" ] = parse_literal,
|
|
||||||
[ "[" ] = parse_array,
|
|
||||||
[ "{" ] = parse_object,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
parse = function(str, idx)
|
|
||||||
local chr = str:sub(idx, idx)
|
|
||||||
local f = char_func_map[chr]
|
|
||||||
if f then
|
|
||||||
return f(str, idx)
|
|
||||||
end
|
|
||||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function json.decode(str)
|
|
||||||
if type(str) ~= "string" then
|
|
||||||
error("expected argument of type string, got " .. type(str))
|
|
||||||
end
|
|
||||||
return ( parse(str, next_char(str, 1, space_chars, true)) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return json
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
-----------------------------------------------------------------------------
|
|
||||||
-- LuaSocket helper module
|
|
||||||
-- Author: Diego Nehab
|
|
||||||
-- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Declare module and import dependencies
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
local base = _G
|
|
||||||
local string = require("string")
|
|
||||||
local math = require("math")
|
|
||||||
local socket = require("socket.core")
|
|
||||||
module("socket")
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Exported auxiliar functions
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
function connect(address, port, laddress, lport)
|
|
||||||
local sock, err = socket.tcp()
|
|
||||||
if not sock then return nil, err end
|
|
||||||
if laddress then
|
|
||||||
local res, err = sock:bind(laddress, lport, -1)
|
|
||||||
if not res then return nil, err end
|
|
||||||
end
|
|
||||||
local res, err = sock:connect(address, port)
|
|
||||||
if not res then return nil, err end
|
|
||||||
return sock
|
|
||||||
end
|
|
||||||
|
|
||||||
function bind(host, port, backlog)
|
|
||||||
local sock, err = socket.tcp()
|
|
||||||
if not sock then return nil, err end
|
|
||||||
sock:setoption("reuseaddr", true)
|
|
||||||
local res, err = sock:bind(host, port)
|
|
||||||
if not res then return nil, err end
|
|
||||||
res, err = sock:listen(backlog)
|
|
||||||
if not res then return nil, err end
|
|
||||||
return sock
|
|
||||||
end
|
|
||||||
|
|
||||||
try = newtry()
|
|
||||||
|
|
||||||
function choose(table)
|
|
||||||
return function(name, opt1, opt2)
|
|
||||||
if base.type(name) ~= "string" then
|
|
||||||
name, opt1, opt2 = "default", name, opt1
|
|
||||||
end
|
|
||||||
local f = table[name or "nil"]
|
|
||||||
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
|
|
||||||
else return f(opt1, opt2) end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- Socket sources and sinks, conforming to LTN12
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
-- create namespaces inside LuaSocket namespace
|
|
||||||
sourcet = {}
|
|
||||||
sinkt = {}
|
|
||||||
|
|
||||||
BLOCKSIZE = 2048
|
|
||||||
|
|
||||||
sinkt["close-when-done"] = function(sock)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function(self, chunk, err)
|
|
||||||
if not chunk then
|
|
||||||
sock:close()
|
|
||||||
return 1
|
|
||||||
else return sock:send(chunk) end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sinkt["keep-open"] = function(sock)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function(self, chunk, err)
|
|
||||||
if chunk then return sock:send(chunk)
|
|
||||||
else return 1 end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sinkt["default"] = sinkt["keep-open"]
|
|
||||||
|
|
||||||
sink = choose(sinkt)
|
|
||||||
|
|
||||||
sourcet["by-length"] = function(sock, length)
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function()
|
|
||||||
if length <= 0 then return nil end
|
|
||||||
local size = math.min(socket.BLOCKSIZE, length)
|
|
||||||
local chunk, err = sock:receive(size)
|
|
||||||
if err then return nil, err end
|
|
||||||
length = length - string.len(chunk)
|
|
||||||
return chunk
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
sourcet["until-closed"] = function(sock)
|
|
||||||
local done
|
|
||||||
return base.setmetatable({
|
|
||||||
getfd = function() return sock:getfd() end,
|
|
||||||
dirty = function() return sock:dirty() end
|
|
||||||
}, {
|
|
||||||
__call = function()
|
|
||||||
if done then return nil end
|
|
||||||
local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
|
|
||||||
if not err then return chunk
|
|
||||||
elseif err == "closed" then
|
|
||||||
sock:close()
|
|
||||||
done = 1
|
|
||||||
return partial
|
|
||||||
else return nil, err end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
sourcet["default"] = sourcet["until-closed"]
|
|
||||||
|
|
||||||
source = choose(sourcet)
|
|
||||||
@@ -1,380 +0,0 @@
|
|||||||
--
|
|
||||||
-- json.lua
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2015 rxi
|
|
||||||
--
|
|
||||||
-- This library is free software; you can redistribute it and/or modify it
|
|
||||||
-- under the terms of the MIT license. See LICENSE for details.
|
|
||||||
--
|
|
||||||
|
|
||||||
local json = { _version = "0.1.0" }
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- Encode
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local encode
|
|
||||||
|
|
||||||
local escape_char_map = {
|
|
||||||
[ "\\" ] = "\\\\",
|
|
||||||
[ "\"" ] = "\\\"",
|
|
||||||
[ "\b" ] = "\\b",
|
|
||||||
[ "\f" ] = "\\f",
|
|
||||||
[ "\n" ] = "\\n",
|
|
||||||
[ "\r" ] = "\\r",
|
|
||||||
[ "\t" ] = "\\t",
|
|
||||||
}
|
|
||||||
|
|
||||||
local escape_char_map_inv = { [ "\\/" ] = "/" }
|
|
||||||
for k, v in pairs(escape_char_map) do
|
|
||||||
escape_char_map_inv[v] = k
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function escape_char(c)
|
|
||||||
return escape_char_map[c] or string.format("\\u%04x", c:byte())
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_nil(val)
|
|
||||||
return "null"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_table(val, stack)
|
|
||||||
local res = {}
|
|
||||||
stack = stack or {}
|
|
||||||
|
|
||||||
-- Circular reference?
|
|
||||||
if stack[val] then error("circular reference") end
|
|
||||||
|
|
||||||
stack[val] = true
|
|
||||||
|
|
||||||
if val[1] ~= nil or next(val) == nil then
|
|
||||||
-- Treat as array -- check keys are valid and it is not sparse
|
|
||||||
local n = 0
|
|
||||||
for k in pairs(val) do
|
|
||||||
if type(k) ~= "number" then
|
|
||||||
error("invalid table: mixed or invalid key types")
|
|
||||||
end
|
|
||||||
n = n + 1
|
|
||||||
end
|
|
||||||
if n ~= #val then
|
|
||||||
error("invalid table: sparse array")
|
|
||||||
end
|
|
||||||
-- Encode
|
|
||||||
for i, v in ipairs(val) do
|
|
||||||
table.insert(res, encode(v, stack))
|
|
||||||
end
|
|
||||||
stack[val] = nil
|
|
||||||
return "[" .. table.concat(res, ",") .. "]"
|
|
||||||
|
|
||||||
else
|
|
||||||
-- Treat as an object
|
|
||||||
for k, v in pairs(val) do
|
|
||||||
if type(k) ~= "string" then
|
|
||||||
error("invalid table: mixed or invalid key types")
|
|
||||||
end
|
|
||||||
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
|
|
||||||
end
|
|
||||||
stack[val] = nil
|
|
||||||
return "{" .. table.concat(res, ",") .. "}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_string(val)
|
|
||||||
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function encode_number(val)
|
|
||||||
-- Check for NaN, -inf and inf
|
|
||||||
if val ~= val or val <= -math.huge or val >= math.huge then
|
|
||||||
error("unexpected number value '" .. tostring(val) .. "'")
|
|
||||||
end
|
|
||||||
return string.format("%.14g", val)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local type_func_map = {
|
|
||||||
[ "nil" ] = encode_nil,
|
|
||||||
[ "table" ] = encode_table,
|
|
||||||
[ "string" ] = encode_string,
|
|
||||||
[ "number" ] = encode_number,
|
|
||||||
[ "boolean" ] = tostring,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
encode = function(val, stack)
|
|
||||||
local t = type(val)
|
|
||||||
local f = type_func_map[t]
|
|
||||||
if f then
|
|
||||||
return f(val, stack)
|
|
||||||
end
|
|
||||||
error("unexpected type '" .. t .. "'")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function json.encode(val)
|
|
||||||
return ( encode(val) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- Decode
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
local parse
|
|
||||||
|
|
||||||
local function create_set(...)
|
|
||||||
local res = {}
|
|
||||||
for i = 1, select("#", ...) do
|
|
||||||
res[ select(i, ...) ] = true
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
|
||||||
|
|
||||||
local space_chars = create_set(" ", "\t", "\r", "\n")
|
|
||||||
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
|
||||||
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
|
||||||
local literals = create_set("true", "false", "null")
|
|
||||||
|
|
||||||
local literal_map = {
|
|
||||||
[ "true" ] = true,
|
|
||||||
[ "false" ] = false,
|
|
||||||
[ "null" ] = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
local function next_char(str, idx, set, negate)
|
|
||||||
for i = idx, #str do
|
|
||||||
if set[str:sub(i, i)] ~= negate then
|
|
||||||
return i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return #str + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function decode_error(str, idx, msg)
|
|
||||||
--local line_count = 1
|
|
||||||
--local col_count = 1
|
|
||||||
--for i = 1, idx - 1 do
|
|
||||||
-- col_count = col_count + 1
|
|
||||||
-- if str:sub(i, i) == "\n" then
|
|
||||||
-- line_count = line_count + 1
|
|
||||||
-- col_count = 1
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- emu.message( string.format("%s at line %d col %d", msg, line_count, col_count) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function codepoint_to_utf8(n)
|
|
||||||
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
|
||||||
local f = math.floor
|
|
||||||
if n <= 0x7f then
|
|
||||||
return string.char(n)
|
|
||||||
elseif n <= 0x7ff then
|
|
||||||
return string.char(f(n / 64) + 192, n % 64 + 128)
|
|
||||||
elseif n <= 0xffff then
|
|
||||||
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
|
|
||||||
elseif n <= 0x10ffff then
|
|
||||||
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
|
|
||||||
f(n % 4096 / 64) + 128, n % 64 + 128)
|
|
||||||
end
|
|
||||||
error( string.format("invalid unicode codepoint '%x'", n) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_unicode_escape(s)
|
|
||||||
local n1 = tonumber( s:sub(3, 6), 16 )
|
|
||||||
local n2 = tonumber( s:sub(9, 12), 16 )
|
|
||||||
-- Surrogate pair?
|
|
||||||
if n2 then
|
|
||||||
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
|
|
||||||
else
|
|
||||||
return codepoint_to_utf8(n1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_string(str, i)
|
|
||||||
local has_unicode_escape = false
|
|
||||||
local has_surrogate_escape = false
|
|
||||||
local has_escape = false
|
|
||||||
local last
|
|
||||||
for j = i + 1, #str do
|
|
||||||
local x = str:byte(j)
|
|
||||||
|
|
||||||
if x < 32 then
|
|
||||||
decode_error(str, j, "control character in string")
|
|
||||||
end
|
|
||||||
|
|
||||||
if last == 92 then -- "\\" (escape char)
|
|
||||||
if x == 117 then -- "u" (unicode escape sequence)
|
|
||||||
local hex = str:sub(j + 1, j + 5)
|
|
||||||
if not hex:find("%x%x%x%x") then
|
|
||||||
decode_error(str, j, "invalid unicode escape in string")
|
|
||||||
end
|
|
||||||
if hex:find("^[dD][89aAbB]") then
|
|
||||||
has_surrogate_escape = true
|
|
||||||
else
|
|
||||||
has_unicode_escape = true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local c = string.char(x)
|
|
||||||
if not escape_chars[c] then
|
|
||||||
decode_error(str, j, "invalid escape char '" .. c .. "' in string")
|
|
||||||
end
|
|
||||||
has_escape = true
|
|
||||||
end
|
|
||||||
last = nil
|
|
||||||
|
|
||||||
elseif x == 34 then -- '"' (end of string)
|
|
||||||
local s = str:sub(i + 1, j - 1)
|
|
||||||
if has_surrogate_escape then
|
|
||||||
s = s:gsub("\\u[dD][89aAbB]..\\u....", parse_unicode_escape)
|
|
||||||
end
|
|
||||||
if has_unicode_escape then
|
|
||||||
s = s:gsub("\\u....", parse_unicode_escape)
|
|
||||||
end
|
|
||||||
if has_escape then
|
|
||||||
s = s:gsub("\\.", escape_char_map_inv)
|
|
||||||
end
|
|
||||||
return s, j + 1
|
|
||||||
|
|
||||||
else
|
|
||||||
last = x
|
|
||||||
end
|
|
||||||
end
|
|
||||||
decode_error(str, i, "expected closing quote for string")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_number(str, i)
|
|
||||||
local x = next_char(str, i, delim_chars)
|
|
||||||
local s = str:sub(i, x - 1)
|
|
||||||
local n = tonumber(s)
|
|
||||||
if not n then
|
|
||||||
decode_error(str, i, "invalid number '" .. s .. "'")
|
|
||||||
end
|
|
||||||
return n, x
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_literal(str, i)
|
|
||||||
local x = next_char(str, i, delim_chars)
|
|
||||||
local word = str:sub(i, x - 1)
|
|
||||||
if not literals[word] then
|
|
||||||
decode_error(str, i, "invalid literal '" .. word .. "'")
|
|
||||||
end
|
|
||||||
return literal_map[word], x
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_array(str, i)
|
|
||||||
local res = {}
|
|
||||||
local n = 1
|
|
||||||
i = i + 1
|
|
||||||
while 1 do
|
|
||||||
local x
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
-- Empty / end of array?
|
|
||||||
if str:sub(i, i) == "]" then
|
|
||||||
i = i + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- Read token
|
|
||||||
x, i = parse(str, i)
|
|
||||||
res[n] = x
|
|
||||||
n = n + 1
|
|
||||||
-- Next token
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
local chr = str:sub(i, i)
|
|
||||||
i = i + 1
|
|
||||||
if chr == "]" then break end
|
|
||||||
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
|
|
||||||
end
|
|
||||||
return res, i
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function parse_object(str, i)
|
|
||||||
local res = {}
|
|
||||||
i = i + 1
|
|
||||||
while 1 do
|
|
||||||
local key, val
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
-- Empty / end of object?
|
|
||||||
if str:sub(i, i) == "}" then
|
|
||||||
i = i + 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
-- Read key
|
|
||||||
if str:sub(i, i) ~= '"' then
|
|
||||||
decode_error(str, i, "expected string for key")
|
|
||||||
end
|
|
||||||
key, i = parse(str, i)
|
|
||||||
-- Read ':' delimiter
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
if str:sub(i, i) ~= ":" then
|
|
||||||
decode_error(str, i, "expected ':' after key")
|
|
||||||
end
|
|
||||||
i = next_char(str, i + 1, space_chars, true)
|
|
||||||
-- Read value
|
|
||||||
val, i = parse(str, i)
|
|
||||||
-- Set
|
|
||||||
res[key] = val
|
|
||||||
-- Next token
|
|
||||||
i = next_char(str, i, space_chars, true)
|
|
||||||
local chr = str:sub(i, i)
|
|
||||||
i = i + 1
|
|
||||||
if chr == "}" then break end
|
|
||||||
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
|
|
||||||
end
|
|
||||||
return res, i
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local char_func_map = {
|
|
||||||
[ '"' ] = parse_string,
|
|
||||||
[ "0" ] = parse_number,
|
|
||||||
[ "1" ] = parse_number,
|
|
||||||
[ "2" ] = parse_number,
|
|
||||||
[ "3" ] = parse_number,
|
|
||||||
[ "4" ] = parse_number,
|
|
||||||
[ "5" ] = parse_number,
|
|
||||||
[ "6" ] = parse_number,
|
|
||||||
[ "7" ] = parse_number,
|
|
||||||
[ "8" ] = parse_number,
|
|
||||||
[ "9" ] = parse_number,
|
|
||||||
[ "-" ] = parse_number,
|
|
||||||
[ "t" ] = parse_literal,
|
|
||||||
[ "f" ] = parse_literal,
|
|
||||||
[ "n" ] = parse_literal,
|
|
||||||
[ "[" ] = parse_array,
|
|
||||||
[ "{" ] = parse_object,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
parse = function(str, idx)
|
|
||||||
local chr = str:sub(idx, idx)
|
|
||||||
local f = char_func_map[chr]
|
|
||||||
if f then
|
|
||||||
return f(str, idx)
|
|
||||||
end
|
|
||||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function json.decode(str)
|
|
||||||
if type(str) ~= "string" then
|
|
||||||
error("expected argument of type string, got " .. type(str))
|
|
||||||
end
|
|
||||||
return ( parse(str, next_char(str, 1, space_chars, true)) )
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return json
|
|
||||||
109
data/lua/common.lua
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
print("Loading AP lua connector script")
|
||||||
|
|
||||||
|
local lua_major, lua_minor = _VERSION:match("Lua (%d+)%.(%d+)")
|
||||||
|
lua_major = tonumber(lua_major)
|
||||||
|
lua_minor = tonumber(lua_minor)
|
||||||
|
-- lua compat shims
|
||||||
|
if lua_major > 5 or (lua_major == 5 and lua_minor >= 3) then
|
||||||
|
require("lua_5_3_compat")
|
||||||
|
end
|
||||||
|
|
||||||
|
function table.empty (self)
|
||||||
|
for _, _ in pairs(self) do
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local bizhawk_version = client.getversion()
|
||||||
|
local bizhawk_major, bizhawk_minor, bizhawk_patch = bizhawk_version:match("(%d+)%.(%d+)%.?(%d*)")
|
||||||
|
bizhawk_major = tonumber(bizhawk_major)
|
||||||
|
bizhawk_minor = tonumber(bizhawk_minor)
|
||||||
|
if bizhawk_patch == "" then
|
||||||
|
bizhawk_patch = 0
|
||||||
|
else
|
||||||
|
bizhawk_patch = tonumber(bizhawk_patch)
|
||||||
|
end
|
||||||
|
|
||||||
|
local is23Or24Or25 = (bizhawk_version=="2.3.1") or (bizhawk_major == 2 and bizhawk_minor >= 3 and bizhawk_minor <= 5)
|
||||||
|
local isGreaterOrEqualTo26 = bizhawk_major > 2 or (bizhawk_major == 2 and bizhawk_minor >= 6)
|
||||||
|
local isUntestedBizhawk = bizhawk_major > 2 or (bizhawk_major == 2 and bizhawk_minor > 9)
|
||||||
|
local untestedBizhawkMessage = "Warning: this version of bizhawk is newer than we know about. If it doesn't work, consider downgrading to 2.9"
|
||||||
|
|
||||||
|
u8 = memory.read_u8
|
||||||
|
wU8 = memory.write_u8
|
||||||
|
u16 = memory.read_u16_le
|
||||||
|
uRange = memory.readbyterange
|
||||||
|
|
||||||
|
function getMaxMessageLength()
|
||||||
|
local denominator = 12
|
||||||
|
if is23Or24Or25 then
|
||||||
|
denominator = 11
|
||||||
|
end
|
||||||
|
return math.floor(client.screenwidth()/denominator)
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawText(x, y, message, color)
|
||||||
|
if is23Or24Or25 then
|
||||||
|
gui.addmessage(message)
|
||||||
|
elseif isGreaterOrEqualTo26 then
|
||||||
|
gui.drawText(x, y, message, color, 0xB0000000, 18, "Courier New", "middle", "bottom", nil, "client")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function clearScreen()
|
||||||
|
if is23Or24Or25 then
|
||||||
|
return
|
||||||
|
elseif isGreaterOrEqualTo26 then
|
||||||
|
drawText(0, 0, "", "black")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
itemMessages = {}
|
||||||
|
|
||||||
|
function drawMessages()
|
||||||
|
if table.empty(itemMessages) then
|
||||||
|
clearScreen()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local y = 10
|
||||||
|
found = false
|
||||||
|
maxMessageLength = getMaxMessageLength()
|
||||||
|
for k, v in pairs(itemMessages) do
|
||||||
|
if v["TTL"] > 0 then
|
||||||
|
message = v["message"]
|
||||||
|
while true do
|
||||||
|
drawText(5, y, message:sub(1, maxMessageLength), v["color"])
|
||||||
|
y = y + 16
|
||||||
|
|
||||||
|
message = message:sub(maxMessageLength + 1, message:len())
|
||||||
|
if message:len() == 0 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
newTTL = 0
|
||||||
|
if isGreaterOrEqualTo26 then
|
||||||
|
newTTL = itemMessages[k]["TTL"] - 1
|
||||||
|
end
|
||||||
|
itemMessages[k]["TTL"] = newTTL
|
||||||
|
found = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if found == false then
|
||||||
|
clearScreen()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function checkBizhawkVersion()
|
||||||
|
if not is23Or24Or25 and not isGreaterOrEqualTo26 then
|
||||||
|
print("Must use a version of bizhawk 2.3.1 or higher")
|
||||||
|
return false
|
||||||
|
elseif isUntestedBizhawk then
|
||||||
|
print(untestedBizhawkMessage)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function stripPrefix(s, p)
|
||||||
|
return (s:sub(0, #p) == p) and s:sub(#p+1) or s
|
||||||
|
end
|
||||||
738
data/lua/connector_adventure.lua
Normal file
@@ -0,0 +1,738 @@
|
|||||||
|
local socket = require("socket")
|
||||||
|
local json = require('json')
|
||||||
|
local math = require('math')
|
||||||
|
require("common")
|
||||||
|
|
||||||
|
local STATE_OK = "Ok"
|
||||||
|
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
||||||
|
local STATE_INITIAL_CONNECTION_MADE = "Initial Connection Made"
|
||||||
|
local STATE_UNINITIALIZED = "Uninitialized"
|
||||||
|
|
||||||
|
local SCRIPT_VERSION = 1
|
||||||
|
|
||||||
|
local APItemValue = 0xA2
|
||||||
|
local APItemRam = 0xE7
|
||||||
|
local BatAPItemValue = 0xAB
|
||||||
|
local BatAPItemRam = 0xEA
|
||||||
|
local PlayerRoomAddr = 0x8A -- if in number room, we're not in play mode
|
||||||
|
local WinAddr = 0xDE -- if not 0 (I think if 0xff specifically), we won (and should update once, immediately)
|
||||||
|
|
||||||
|
-- If any of these are 2, that dragon ate the player (should send update immediately
|
||||||
|
-- once, and reset that when none of them are 2 again)
|
||||||
|
|
||||||
|
local DragonState = {0xA8, 0xAD, 0xB2}
|
||||||
|
local last_dragon_state = {0, 0, 0}
|
||||||
|
local carryAddress = 0x9D -- uses rom object table
|
||||||
|
local batRoomAddr = 0xCB
|
||||||
|
local batCarryAddress = 0xD0 -- uses ram object location
|
||||||
|
local batInvalidCarryItem = 0x78
|
||||||
|
local batItemCheckAddr = 0xf69f
|
||||||
|
local batMatrixLen = 11 -- number of pairs
|
||||||
|
local last_carry_item = 0xB4
|
||||||
|
local frames_with_no_item = 0
|
||||||
|
local ItemTableStart = 0xfe9d
|
||||||
|
local PlayerSlotAddress = 0xfff9
|
||||||
|
|
||||||
|
local nullObjectId = 0xB4
|
||||||
|
local ItemsReceived = nil
|
||||||
|
local sha256hash = nil
|
||||||
|
local foreign_items = nil
|
||||||
|
local foreign_items_by_room = {}
|
||||||
|
local bat_no_touch_locations_by_room = {}
|
||||||
|
local bat_no_touch_items = {}
|
||||||
|
local autocollect_items = {}
|
||||||
|
local localItemLocations = {}
|
||||||
|
|
||||||
|
local prev_bat_room = 0xff
|
||||||
|
local prev_player_room = 0
|
||||||
|
local prev_ap_room_index = nil
|
||||||
|
|
||||||
|
local pending_foreign_items_collected = {}
|
||||||
|
local pending_local_items_collected = {}
|
||||||
|
local rendering_foreign_item = nil
|
||||||
|
local skip_inventory_items = {}
|
||||||
|
|
||||||
|
local inventory = {}
|
||||||
|
local next_inventory_item = nil
|
||||||
|
|
||||||
|
local input_button_address = 0xD7
|
||||||
|
|
||||||
|
local deathlink_rec = nil
|
||||||
|
local deathlink_send = 0
|
||||||
|
|
||||||
|
local deathlink_sent = false
|
||||||
|
|
||||||
|
local prevstate = ""
|
||||||
|
local curstate = STATE_UNINITIALIZED
|
||||||
|
local atariSocket = nil
|
||||||
|
local frame = 0
|
||||||
|
|
||||||
|
local ItemIndex = 0
|
||||||
|
|
||||||
|
local yorgle_speed_address = 0xf725
|
||||||
|
local grundle_speed_address = 0xf740
|
||||||
|
local rhindle_speed_address = 0xf70A
|
||||||
|
|
||||||
|
local read_switch_a = 0xf780
|
||||||
|
local read_switch_b = 0xf764
|
||||||
|
|
||||||
|
local yorgle_speed = nil
|
||||||
|
local grundle_speed = nil
|
||||||
|
local rhindle_speed = nil
|
||||||
|
|
||||||
|
local slow_yorgle_id = tostring(118000000 + 0x103)
|
||||||
|
local slow_grundle_id = tostring(118000000 + 0x104)
|
||||||
|
local slow_rhindle_id = tostring(118000000 + 0x105)
|
||||||
|
|
||||||
|
local yorgle_dead = false
|
||||||
|
local grundle_dead = false
|
||||||
|
local rhindle_dead = false
|
||||||
|
|
||||||
|
local diff_a_locked = false
|
||||||
|
local diff_b_locked = false
|
||||||
|
|
||||||
|
local bat_logic = 0
|
||||||
|
|
||||||
|
local is_dead = 0
|
||||||
|
local freeincarnates_available = 0
|
||||||
|
local send_freeincarnate_used = false
|
||||||
|
local current_bat_ap_item = nil
|
||||||
|
|
||||||
|
local was_in_number_room = false
|
||||||
|
|
||||||
|
function uRangeRam(address, bytes)
|
||||||
|
data = memory.read_bytes_as_array(address, bytes, "Main RAM")
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
function uRangeRom(address, bytes)
|
||||||
|
data = memory.read_bytes_as_array(address+0xf000, bytes, "System Bus")
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
function uRangeAddress(address, bytes)
|
||||||
|
data = memory.read_bytes_as_array(address, bytes, "System Bus")
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
local function createForeignItemsByRoom()
|
||||||
|
foreign_items_by_room = {}
|
||||||
|
if foreign_items == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _, foreign_item in pairs(foreign_items) do
|
||||||
|
if foreign_items_by_room[foreign_item.room_id] == nil then
|
||||||
|
foreign_items_by_room[foreign_item.room_id] = {}
|
||||||
|
end
|
||||||
|
new_foreign_item = {}
|
||||||
|
new_foreign_item.room_id = foreign_item.room_id
|
||||||
|
new_foreign_item.room_x = foreign_item.room_x
|
||||||
|
new_foreign_item.room_y = foreign_item.room_y
|
||||||
|
new_foreign_item.short_location_id = foreign_item.short_location_id
|
||||||
|
|
||||||
|
table.insert(foreign_items_by_room[foreign_item.room_id], new_foreign_item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function debugPrintNoTouchLocations()
|
||||||
|
for room_id, list in pairs(bat_no_touch_locations_by_room) do
|
||||||
|
for index, notouch_location in ipairs(list) do
|
||||||
|
print("ROOM "..tostring(room_id).. "["..tostring(index).."]: "..tostring(notouch_location.short_location_id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function processBlock(block)
|
||||||
|
if block == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local block_identified = 0
|
||||||
|
local msgBlock = block['messages']
|
||||||
|
if msgBlock ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
for i, v in pairs(msgBlock) do
|
||||||
|
if itemMessages[i] == nil then
|
||||||
|
local msg = {TTL=450, message=v, color=0xFFFF0000}
|
||||||
|
itemMessages[i] = msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local itemsBlock = block["items"]
|
||||||
|
if itemsBlock ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
ItemsReceived = itemsBlock
|
||||||
|
end
|
||||||
|
local apItemsBlock = block["foreign_items"]
|
||||||
|
if apItemsBlock ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
print("got foreign items block")
|
||||||
|
foreign_items = apItemsBlock
|
||||||
|
createForeignItemsByRoom()
|
||||||
|
end
|
||||||
|
local autocollectItems = block["autocollect_items"]
|
||||||
|
if autocollectItems ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
autocollect_items = {}
|
||||||
|
for _, acitem in pairs(autocollectItems) do
|
||||||
|
if autocollect_items[acitem.room_id] == nil then
|
||||||
|
autocollect_items[acitem.room_id] = {}
|
||||||
|
end
|
||||||
|
table.insert(autocollect_items[acitem.room_id], acitem)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local localLocalItemLocations = block["local_item_locations"]
|
||||||
|
if localLocalItemLocations ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
localItemLocations = localLocalItemLocations
|
||||||
|
print("got local item locations")
|
||||||
|
end
|
||||||
|
local checkedLocationsBlock = block["checked_locations"]
|
||||||
|
if checkedLocationsBlock ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
for room_id, foreign_item_list in pairs(foreign_items_by_room) do
|
||||||
|
for i, foreign_item in pairs(foreign_item_list) do
|
||||||
|
short_id = foreign_item.short_location_id
|
||||||
|
for j, checked_id in pairs(checkedLocationsBlock) do
|
||||||
|
if checked_id == short_id then
|
||||||
|
table.remove(foreign_item_list, i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if foreign_items ~= nil then
|
||||||
|
for i, foreign_item in pairs(foreign_items) do
|
||||||
|
short_id = foreign_item.short_location_id
|
||||||
|
for j, checked_id in pairs(checkedLocationsBlock) do
|
||||||
|
if checked_id == short_id then
|
||||||
|
foreign_items[i] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local dragon_speeds_block = block["dragon_speeds"]
|
||||||
|
if dragon_speeds_block ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
yorgle_speed = dragon_speeds_block[slow_yorgle_id]
|
||||||
|
grundle_speed = dragon_speeds_block[slow_grundle_id]
|
||||||
|
rhindle_speed = dragon_speeds_block[slow_rhindle_id]
|
||||||
|
end
|
||||||
|
local diff_a_block = block["difficulty_a_locked"]
|
||||||
|
if diff_a_block ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
diff_a_locked = diff_a_block
|
||||||
|
end
|
||||||
|
local diff_b_block = block["difficulty_b_locked"]
|
||||||
|
if diff_b_block ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
diff_b_locked = diff_b_block
|
||||||
|
end
|
||||||
|
local freeincarnates_available_block = block["freeincarnates_available"]
|
||||||
|
if freeincarnates_available_block ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
if freeincarnates_available ~= freeincarnates_available_block then
|
||||||
|
freeincarnates_available = freeincarnates_available_block
|
||||||
|
local msg = {TTL=450, message="freeincarnates: "..tostring(freeincarnates_available), color=0xFFFF0000}
|
||||||
|
itemMessages[-2] = msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local bat_logic_block = block["bat_logic"]
|
||||||
|
if bat_logic_block ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
bat_logic = bat_logic_block
|
||||||
|
end
|
||||||
|
local bat_no_touch_locations_block = block["bat_no_touch_locations"]
|
||||||
|
if bat_no_touch_locations_block ~= nil then
|
||||||
|
block_identified = 1
|
||||||
|
for _, notouch_location in pairs(bat_no_touch_locations_block) do
|
||||||
|
local room_id = tonumber(notouch_location.room_id)
|
||||||
|
if bat_no_touch_locations_by_room[room_id] == nil then
|
||||||
|
bat_no_touch_locations_by_room[room_id] = {}
|
||||||
|
end
|
||||||
|
table.insert(bat_no_touch_locations_by_room[room_id], notouch_location)
|
||||||
|
|
||||||
|
if notouch_location.local_item ~= nil and notouch_location.local_item ~= 255 then
|
||||||
|
bat_no_touch_items[tonumber(notouch_location.local_item)] = true
|
||||||
|
-- print("no touch: "..tostring(notouch_location.local_item))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- debugPrintNoTouchLocations()
|
||||||
|
end
|
||||||
|
deathlink_rec = deathlink_rec or block["deathlink"]
|
||||||
|
if( block_identified == 0 ) then
|
||||||
|
print("unidentified block")
|
||||||
|
print(block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function getAllRam()
|
||||||
|
uRangeRAM(0,128);
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
local function alive_mode()
|
||||||
|
return (u8(PlayerRoomAddr) ~= 0x00 and u8(WinAddr) == 0x00)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function generateLocationsChecked()
|
||||||
|
list_of_locations = {}
|
||||||
|
for s, f in pairs(pending_foreign_items_collected) do
|
||||||
|
table.insert(list_of_locations, f.short_location_id + 118000000)
|
||||||
|
end
|
||||||
|
for s, f in pairs(pending_local_items_collected) do
|
||||||
|
table.insert(list_of_locations, f + 118000000)
|
||||||
|
end
|
||||||
|
return list_of_locations
|
||||||
|
end
|
||||||
|
|
||||||
|
function receive()
|
||||||
|
l, e = atariSocket:receive()
|
||||||
|
if e == 'closed' then
|
||||||
|
if curstate == STATE_OK then
|
||||||
|
print("Connection closed")
|
||||||
|
end
|
||||||
|
curstate = STATE_UNINITIALIZED
|
||||||
|
return
|
||||||
|
elseif e == 'timeout' then
|
||||||
|
return
|
||||||
|
elseif e ~= nil then
|
||||||
|
print(e)
|
||||||
|
curstate = STATE_UNINITIALIZED
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if l ~= nil then
|
||||||
|
processBlock(json.decode(l))
|
||||||
|
end
|
||||||
|
-- Determine Message to send back
|
||||||
|
|
||||||
|
newSha256 = memory.hash_region(0xF000, 0x1000, "System Bus")
|
||||||
|
if (sha256hash ~= nil and sha256hash ~= newSha256) then
|
||||||
|
print("ROM changed, quitting")
|
||||||
|
curstate = STATE_UNINITIALIZED
|
||||||
|
return
|
||||||
|
end
|
||||||
|
sha256hash = newSha256
|
||||||
|
local retTable = {}
|
||||||
|
retTable["scriptVersion"] = SCRIPT_VERSION
|
||||||
|
retTable["romhash"] = sha256hash
|
||||||
|
if (alive_mode()) then
|
||||||
|
retTable["locations"] = generateLocationsChecked()
|
||||||
|
end
|
||||||
|
if (u8(WinAddr) ~= 0x00) then
|
||||||
|
retTable["victory"] = 1
|
||||||
|
end
|
||||||
|
if( deathlink_sent or deathlink_send == 0 ) then
|
||||||
|
retTable["deathLink"] = 0
|
||||||
|
else
|
||||||
|
print("Sending deathlink "..tostring(deathlink_send))
|
||||||
|
retTable["deathLink"] = deathlink_send
|
||||||
|
deathlink_sent = true
|
||||||
|
end
|
||||||
|
deathlink_send = 0
|
||||||
|
|
||||||
|
if send_freeincarnate_used == true then
|
||||||
|
print("Sending freeincarnate used")
|
||||||
|
retTable["freeincarnate"] = true
|
||||||
|
send_freeincarnate_used = false
|
||||||
|
end
|
||||||
|
|
||||||
|
msg = json.encode(retTable).."\n"
|
||||||
|
local ret, error = atariSocket:send(msg)
|
||||||
|
if ret == nil then
|
||||||
|
print(error)
|
||||||
|
elseif curstate == STATE_INITIAL_CONNECTION_MADE then
|
||||||
|
curstate = STATE_TENTATIVELY_CONNECTED
|
||||||
|
elseif curstate == STATE_TENTATIVELY_CONNECTED then
|
||||||
|
print("Connected!")
|
||||||
|
curstate = STATE_OK
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function AutocollectFromRoom()
|
||||||
|
if autocollect_items ~= nil and autocollect_items[prev_player_room] ~= nil then
|
||||||
|
for _, item in pairs(autocollect_items[prev_player_room]) do
|
||||||
|
pending_foreign_items_collected[item.short_location_id] = item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SetYorgleSpeed()
|
||||||
|
if yorgle_speed ~= nil then
|
||||||
|
emu.setregister("A", yorgle_speed);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SetGrundleSpeed()
|
||||||
|
if grundle_speed ~= nil then
|
||||||
|
emu.setregister("A", grundle_speed);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SetRhindleSpeed()
|
||||||
|
if rhindle_speed ~= nil then
|
||||||
|
emu.setregister("A", rhindle_speed);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SetDifficultySwitchB()
|
||||||
|
if diff_b_locked then
|
||||||
|
local a = emu.getregister("A")
|
||||||
|
if a < 128 then
|
||||||
|
emu.setregister("A", a + 128)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function SetDifficultySwitchA()
|
||||||
|
if diff_a_locked then
|
||||||
|
local a = emu.getregister("A")
|
||||||
|
if (a > 128 and a < 128 + 64) or (a < 64) then
|
||||||
|
emu.setregister("A", a + 64)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function TryFreeincarnate()
|
||||||
|
if freeincarnates_available > 0 then
|
||||||
|
freeincarnates_available = freeincarnates_available - 1
|
||||||
|
for index, state_addr in pairs(DragonState) do
|
||||||
|
if last_dragon_state[index] == 1 then
|
||||||
|
send_freeincarnate_used = true
|
||||||
|
memory.write_u8(state_addr, 1, "System Bus")
|
||||||
|
local msg = {TTL=450, message="used freeincarnate", color=0xFF00FF00}
|
||||||
|
itemMessages[-1] = msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function GetLinkedObject()
|
||||||
|
if emu.getregister("X") == batRoomAddr then
|
||||||
|
bat_interest_item = emu.getregister("A")
|
||||||
|
-- if the bat can't touch that item, we'll switch it to the number item, which should never be
|
||||||
|
-- in the same room as the bat.
|
||||||
|
if bat_no_touch_items[bat_interest_item] ~= nil then
|
||||||
|
emu.setregister("A", 0xDD )
|
||||||
|
emu.setregister("Y", 0xDD )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function CheckCollectAPItem(carry_item, target_item_value, target_item_ram, rendering_foreign_item)
|
||||||
|
if( carry_item == target_item_value and rendering_foreign_item ~= nil ) then
|
||||||
|
memory.write_u8(carryAddress, nullObjectId, "System Bus")
|
||||||
|
memory.write_u8(target_item_ram, 0xFF, "System Bus")
|
||||||
|
pending_foreign_items_collected[rendering_foreign_item.short_location_id] = rendering_foreign_item
|
||||||
|
for index, fi in pairs(foreign_items_by_room[rendering_foreign_item.room_id]) do
|
||||||
|
if( fi.short_location_id == rendering_foreign_item.short_location_id ) then
|
||||||
|
table.remove(foreign_items_by_room[rendering_foreign_item.room_id], index)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for index, fi in pairs(foreign_items) do
|
||||||
|
if( fi.short_location_id == rendering_foreign_item.short_location_id ) then
|
||||||
|
foreign_items[index] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
prev_ap_room_index = 0
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function BatCanTouchForeign(foreign_item, bat_room)
|
||||||
|
if bat_no_touch_locations_by_room[bat_room] == nil or bat_no_touch_locations_by_room[bat_room][1] == nil then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
for index, location in ipairs(bat_no_touch_locations_by_room[bat_room]) do
|
||||||
|
if location.short_location_id == foreign_item.short_location_id then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true;
|
||||||
|
end
|
||||||
|
|
||||||
|
function main()
|
||||||
|
memory.usememorydomain("System Bus")
|
||||||
|
if not checkBizhawkVersion() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local playerSlot = memory.read_u8(PlayerSlotAddress)
|
||||||
|
local port = 17242 + playerSlot
|
||||||
|
print("Using port"..tostring(port))
|
||||||
|
server, error = socket.bind('localhost', port)
|
||||||
|
if( error ~= nil ) then
|
||||||
|
print(error)
|
||||||
|
end
|
||||||
|
event.onmemoryexecute(SetYorgleSpeed, yorgle_speed_address);
|
||||||
|
event.onmemoryexecute(SetGrundleSpeed, grundle_speed_address);
|
||||||
|
event.onmemoryexecute(SetRhindleSpeed, rhindle_speed_address);
|
||||||
|
event.onmemoryexecute(SetDifficultySwitchA, read_switch_a)
|
||||||
|
event.onmemoryexecute(SetDifficultySwitchB, read_switch_b)
|
||||||
|
event.onmemoryexecute(GetLinkedObject, batItemCheckAddr)
|
||||||
|
-- TODO: Add an onmemoryexecute event to intercept the bat reading item rooms, and don't 'see' an item in the
|
||||||
|
-- room if it is in bat_no_touch_locations_by_room. Although realistically, I may have to handle this in the rom
|
||||||
|
-- for it to be totally reliable, because it won't work before the script connects (I might have to reset them?)
|
||||||
|
-- TODO: Also remove those items from the bat_no_touch_locations_by_room if they have been collected
|
||||||
|
while true do
|
||||||
|
frame = frame + 1
|
||||||
|
drawMessages()
|
||||||
|
if not (curstate == prevstate) then
|
||||||
|
print("Current state: "..curstate)
|
||||||
|
prevstate = curstate
|
||||||
|
end
|
||||||
|
|
||||||
|
local current_player_room = u8(PlayerRoomAddr)
|
||||||
|
local bat_room = u8(batRoomAddr)
|
||||||
|
local bat_carrying_item = u8(batCarryAddress)
|
||||||
|
local bat_carrying_ap_item = (BatAPItemRam == bat_carrying_item)
|
||||||
|
|
||||||
|
if current_player_room == 0x1E then
|
||||||
|
if u8(PlayerRoomAddr + 1) > 0x4B then
|
||||||
|
memory.write_u8(PlayerRoomAddr + 1, 0x4B)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if current_player_room == 0x00 then
|
||||||
|
if not was_in_number_room then
|
||||||
|
print("reset "..tostring(bat_carrying_ap_item).." "..tostring(bat_carrying_item))
|
||||||
|
memory.write_u8(batCarryAddress, batInvalidCarryItem)
|
||||||
|
memory.write_u8(batCarryAddress+ 1, 0)
|
||||||
|
createForeignItemsByRoom()
|
||||||
|
memory.write_u8(BatAPItemRam, 0xff)
|
||||||
|
memory.write_u8(APItemRam, 0xff)
|
||||||
|
prev_ap_room_index = 0
|
||||||
|
prev_player_room = 0
|
||||||
|
rendering_foreign_item = nil
|
||||||
|
was_in_number_room = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
was_in_number_room = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if bat_room ~= prev_bat_room then
|
||||||
|
if bat_carrying_ap_item then
|
||||||
|
if foreign_items_by_room[prev_bat_room] ~= nil then
|
||||||
|
for r,f in pairs(foreign_items_by_room[prev_bat_room]) do
|
||||||
|
if f.short_location_id == current_bat_ap_item.short_location_id then
|
||||||
|
-- print("removing item from "..tostring(r).." in "..tostring(prev_bat_room))
|
||||||
|
table.remove(foreign_items_by_room[prev_bat_room], r)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if foreign_items_by_room[bat_room] == nil then
|
||||||
|
foreign_items_by_room[bat_room] = {}
|
||||||
|
end
|
||||||
|
-- print("adding item to "..tostring(bat_room))
|
||||||
|
table.insert(foreign_items_by_room[bat_room], current_bat_ap_item)
|
||||||
|
else
|
||||||
|
-- set AP item room and position for new room, or to invalid room
|
||||||
|
if foreign_items_by_room[bat_room] ~= nil and foreign_items_by_room[bat_room][1] ~= nil
|
||||||
|
and BatCanTouchForeign(foreign_items_by_room[bat_room][1], bat_room) then
|
||||||
|
if current_bat_ap_item ~= foreign_items_by_room[bat_room][1] then
|
||||||
|
current_bat_ap_item = foreign_items_by_room[bat_room][1]
|
||||||
|
-- print("Changing bat item to "..tostring(current_bat_ap_item.short_location_id))
|
||||||
|
end
|
||||||
|
memory.write_u8(BatAPItemRam, bat_room)
|
||||||
|
memory.write_u8(BatAPItemRam + 1, current_bat_ap_item.room_x)
|
||||||
|
memory.write_u8(BatAPItemRam + 2, current_bat_ap_item.room_y)
|
||||||
|
else
|
||||||
|
memory.write_u8(BatAPItemRam, 0xff)
|
||||||
|
if current_bat_ap_item ~= nil then
|
||||||
|
-- print("clearing bat item")
|
||||||
|
end
|
||||||
|
current_bat_ap_item = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
prev_bat_room = bat_room
|
||||||
|
|
||||||
|
-- update foreign_items_by_room position and room id for bat item if bat carrying an item
|
||||||
|
if bat_carrying_ap_item then
|
||||||
|
-- this is setting the item using the bat's position, which is somewhat wrong, but I think
|
||||||
|
-- there will be more problems with the room not matching sometimes if I use the actual item position
|
||||||
|
current_bat_ap_item.room_id = bat_room
|
||||||
|
current_bat_ap_item.room_x = u8(batRoomAddr + 1)
|
||||||
|
current_bat_ap_item.room_y = u8(batRoomAddr + 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (alive_mode()) then
|
||||||
|
if (current_player_room ~= prev_player_room) then
|
||||||
|
memory.write_u8(APItemRam, 0xFF, "System Bus")
|
||||||
|
prev_ap_room_index = 0
|
||||||
|
prev_player_room = current_player_room
|
||||||
|
AutocollectFromRoom()
|
||||||
|
end
|
||||||
|
local carry_item = memory.read_u8(carryAddress, "System Bus")
|
||||||
|
bat_no_touch_items[carry_item] = nil
|
||||||
|
if (next_inventory_item ~= nil) then
|
||||||
|
if ( carry_item == nullObjectId and last_carry_item == nullObjectId ) then
|
||||||
|
frames_with_no_item = frames_with_no_item + 1
|
||||||
|
if (frames_with_no_item > 10) then
|
||||||
|
frames_with_no_item = 10
|
||||||
|
local input_value = memory.read_u8(input_button_address, "System Bus")
|
||||||
|
if( input_value >= 64 and input_value < 128 ) then -- high bit clear, second highest bit set
|
||||||
|
memory.write_u8(carryAddress, next_inventory_item)
|
||||||
|
local item_ram_location = memory.read_u8(ItemTableStart + next_inventory_item)
|
||||||
|
if( memory.read_u8(batCarryAddress) ~= 0x78 and
|
||||||
|
memory.read_u8(batCarryAddress) == item_ram_location) then
|
||||||
|
memory.write_u8(batCarryAddress, batInvalidCarryItem)
|
||||||
|
memory.write_u8(batCarryAddress+ 1, 0)
|
||||||
|
memory.write_u8(item_ram_location, current_player_room)
|
||||||
|
memory.write_u8(item_ram_location + 1, memory.read_u8(PlayerRoomAddr + 1))
|
||||||
|
memory.write_u8(item_ram_location + 2, memory.read_u8(PlayerRoomAddr + 2))
|
||||||
|
end
|
||||||
|
ItemIndex = ItemIndex + 1
|
||||||
|
next_inventory_item = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
frames_with_no_item = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if( carry_item ~= last_carry_item ) then
|
||||||
|
if ( localItemLocations ~= nil and localItemLocations[tostring(carry_item)] ~= nil ) then
|
||||||
|
pending_local_items_collected[localItemLocations[tostring(carry_item)]] =
|
||||||
|
localItemLocations[tostring(carry_item)]
|
||||||
|
localItemLocations[tostring(carry_item)] = nil
|
||||||
|
skip_inventory_items[carry_item] = carry_item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
last_carry_item = carry_item
|
||||||
|
|
||||||
|
CheckCollectAPItem(carry_item, APItemValue, APItemRam, rendering_foreign_item)
|
||||||
|
if CheckCollectAPItem(carry_item, BatAPItemValue, BatAPItemRam, current_bat_ap_item) and bat_carrying_ap_item then
|
||||||
|
memory.write_u8(batCarryAddress, batInvalidCarryItem)
|
||||||
|
memory.write_u8(batCarryAddress+ 1, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
rendering_foreign_item = nil
|
||||||
|
if( foreign_items_by_room[current_player_room] ~= nil ) then
|
||||||
|
if( foreign_items_by_room[current_player_room][prev_ap_room_index] ~= nil ) and memory.read_u8(APItemRam) ~= 0xff then
|
||||||
|
foreign_items_by_room[current_player_room][prev_ap_room_index].room_x = memory.read_u8(APItemRam + 1)
|
||||||
|
foreign_items_by_room[current_player_room][prev_ap_room_index].room_y = memory.read_u8(APItemRam + 2)
|
||||||
|
end
|
||||||
|
prev_ap_room_index = prev_ap_room_index + 1
|
||||||
|
local invalid_index = -1
|
||||||
|
if( foreign_items_by_room[current_player_room][prev_ap_room_index] == nil ) then
|
||||||
|
prev_ap_room_index = 1
|
||||||
|
end
|
||||||
|
if( foreign_items_by_room[current_player_room][prev_ap_room_index] ~= nil and current_bat_ap_item ~= nil and
|
||||||
|
foreign_items_by_room[current_player_room][prev_ap_room_index].short_location_id == current_bat_ap_item.short_location_id) then
|
||||||
|
invalid_index = prev_ap_room_index
|
||||||
|
prev_ap_room_index = prev_ap_room_index + 1
|
||||||
|
if( foreign_items_by_room[current_player_room][prev_ap_room_index] == nil ) then
|
||||||
|
prev_ap_room_index = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if( foreign_items_by_room[current_player_room][prev_ap_room_index] ~= nil and prev_ap_room_index ~= invalid_index ) then
|
||||||
|
memory.write_u8(APItemRam, current_player_room)
|
||||||
|
rendering_foreign_item = foreign_items_by_room[current_player_room][prev_ap_room_index]
|
||||||
|
memory.write_u8(APItemRam + 1, rendering_foreign_item.room_x)
|
||||||
|
memory.write_u8(APItemRam + 2, rendering_foreign_item.room_y)
|
||||||
|
else
|
||||||
|
memory.write_u8(APItemRam, 0xFF, "System Bus")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if is_dead == 0 then
|
||||||
|
dragons_revived = false
|
||||||
|
player_dead = false
|
||||||
|
new_dragon_state = {0,0,0}
|
||||||
|
for index, dragon_state_addr in pairs(DragonState) do
|
||||||
|
new_dragon_state[index] = memory.read_u8(dragon_state_addr, "System Bus" )
|
||||||
|
if last_dragon_state[index] == 1 and new_dragon_state[index] ~= 1 then
|
||||||
|
dragons_revived = true
|
||||||
|
elseif last_dragon_state[index] ~= 1 and new_dragon_state[index] == 1 then
|
||||||
|
dragon_real_index = index - 1
|
||||||
|
print("Killed dragon: "..tostring(dragon_real_index))
|
||||||
|
local dragon_item = {}
|
||||||
|
dragon_item["short_location_id"] = 0xD0 + dragon_real_index
|
||||||
|
pending_foreign_items_collected[dragon_item.short_location_id] = dragon_item
|
||||||
|
end
|
||||||
|
if new_dragon_state[index] == 2 then
|
||||||
|
player_dead = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if dragons_revived and player_dead == false then
|
||||||
|
TryFreeincarnate()
|
||||||
|
end
|
||||||
|
last_dragon_state = new_dragon_state
|
||||||
|
end
|
||||||
|
elseif (u8(PlayerRoomAddr) == 0x00) then -- not alive mode, in number room
|
||||||
|
ItemIndex = 0 -- reset our inventory
|
||||||
|
next_inventory_item = nil
|
||||||
|
skip_inventory_items = {}
|
||||||
|
end
|
||||||
|
if (curstate == STATE_OK) or (curstate == STATE_INITIAL_CONNECTION_MADE) or (curstate == STATE_TENTATIVELY_CONNECTED) then
|
||||||
|
if (frame % 5 == 0) then
|
||||||
|
receive()
|
||||||
|
if alive_mode() then
|
||||||
|
local was_dead = is_dead
|
||||||
|
is_dead = 0
|
||||||
|
for index, dragonStateAddr in pairs(DragonState) do
|
||||||
|
local dragonstateval = memory.read_u8(dragonStateAddr, "System Bus")
|
||||||
|
if ( dragonstateval == 2) then
|
||||||
|
is_dead = index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if was_dead ~= 0 and is_dead == 0 then
|
||||||
|
TryFreeincarnate()
|
||||||
|
end
|
||||||
|
if deathlink_rec == true and is_dead == 0 then
|
||||||
|
print("setting dead from deathlink")
|
||||||
|
deathlink_rec = false
|
||||||
|
deathlink_sent = true
|
||||||
|
is_dead = 1
|
||||||
|
memory.write_u8(carryAddress, nullObjectId, "System Bus")
|
||||||
|
memory.write_u8(DragonState[1], 2, "System Bus")
|
||||||
|
end
|
||||||
|
if (is_dead > 0 and deathlink_send == 0 and not deathlink_sent) then
|
||||||
|
deathlink_send = is_dead
|
||||||
|
print("setting deathlink_send to "..tostring(is_dead))
|
||||||
|
elseif (is_dead == 0) then
|
||||||
|
deathlink_send = 0
|
||||||
|
deathlink_sent = false
|
||||||
|
end
|
||||||
|
if ItemsReceived ~= nil and ItemsReceived[ItemIndex + 1] ~= nil then
|
||||||
|
while ItemsReceived[ItemIndex + 1] ~= nil and skip_inventory_items[ItemsReceived[ItemIndex + 1]] ~= nil do
|
||||||
|
print("skip")
|
||||||
|
ItemIndex = ItemIndex + 1
|
||||||
|
end
|
||||||
|
local static_id = ItemsReceived[ItemIndex + 1]
|
||||||
|
if static_id ~= nil then
|
||||||
|
inventory[static_id] = 1
|
||||||
|
if next_inventory_item == nil then
|
||||||
|
next_inventory_item = static_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif (curstate == STATE_UNINITIALIZED) then
|
||||||
|
if (frame % 60 == 0) then
|
||||||
|
|
||||||
|
print("Waiting for client.")
|
||||||
|
|
||||||
|
emu.frameadvance()
|
||||||
|
server:settimeout(2)
|
||||||
|
print("Attempting to connect")
|
||||||
|
local client, timeout = server:accept()
|
||||||
|
if timeout == nil then
|
||||||
|
print("Initial connection made")
|
||||||
|
curstate = STATE_INITIAL_CONNECTION_MADE
|
||||||
|
atariSocket = client
|
||||||
|
atariSocket:settimeout(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
emu.frameadvance()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
main()
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local json = require('json')
|
local json = require('json')
|
||||||
local math = require('math')
|
local math = require('math')
|
||||||
|
require("common")
|
||||||
|
|
||||||
local STATE_OK = "Ok"
|
local STATE_OK = "Ok"
|
||||||
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
||||||
@@ -102,15 +103,12 @@ local noOverworldItemsLookup = {
|
|||||||
[500] = 0x12,
|
[500] = 0x12,
|
||||||
}
|
}
|
||||||
|
|
||||||
local itemMessages = {}
|
|
||||||
local consumableStacks = nil
|
local consumableStacks = nil
|
||||||
local prevstate = ""
|
local prevstate = ""
|
||||||
local curstate = STATE_UNINITIALIZED
|
local curstate = STATE_UNINITIALIZED
|
||||||
local ff1Socket = nil
|
local ff1Socket = nil
|
||||||
local frame = 0
|
local frame = 0
|
||||||
|
|
||||||
local u8 = nil
|
|
||||||
local wU8 = nil
|
|
||||||
local isNesHawk = false
|
local isNesHawk = false
|
||||||
|
|
||||||
|
|
||||||
@@ -134,9 +132,6 @@ local function defineMemoryFunctions()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local memDomain = defineMemoryFunctions()
|
local memDomain = defineMemoryFunctions()
|
||||||
u8 = memory.read_u8
|
|
||||||
wU8 = memory.write_u8
|
|
||||||
uRange = memory.readbyterange
|
|
||||||
|
|
||||||
local function StateOKForMainLoop()
|
local function StateOKForMainLoop()
|
||||||
memDomain.saveram()
|
memDomain.saveram()
|
||||||
@@ -146,83 +141,6 @@ local function StateOKForMainLoop()
|
|||||||
return A ~= 0x00 and not (A== 0xF2 and B == 0xF2 and C == 0xF2)
|
return A ~= 0x00 and not (A== 0xF2 and B == 0xF2 and C == 0xF2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function table.empty (self)
|
|
||||||
for _, _ in pairs(self) do
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function slice (tbl, s, e)
|
|
||||||
local pos, new = 1, {}
|
|
||||||
for i = s + 1, e do
|
|
||||||
new[pos] = tbl[i]
|
|
||||||
pos = pos + 1
|
|
||||||
end
|
|
||||||
return new
|
|
||||||
end
|
|
||||||
|
|
||||||
local bizhawk_version = client.getversion()
|
|
||||||
local is23Or24Or25 = (bizhawk_version=="2.3.1") or (bizhawk_version:sub(1,3)=="2.4") or (bizhawk_version:sub(1,3)=="2.5")
|
|
||||||
local is26To28 = (bizhawk_version:sub(1,3)=="2.6") or (bizhawk_version:sub(1,3)=="2.7") or (bizhawk_version:sub(1,3)=="2.8")
|
|
||||||
|
|
||||||
local function getMaxMessageLength()
|
|
||||||
if is23Or24Or25 then
|
|
||||||
return client.screenwidth()/11
|
|
||||||
elseif is26To28 then
|
|
||||||
return client.screenwidth()/12
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function drawText(x, y, message, color)
|
|
||||||
if is23Or24Or25 then
|
|
||||||
gui.addmessage(message)
|
|
||||||
elseif is26To28 then
|
|
||||||
gui.drawText(x, y, message, color, 0xB0000000, 18, "Courier New", nil, nil, nil, "client")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function clearScreen()
|
|
||||||
if is23Or24Or25 then
|
|
||||||
return
|
|
||||||
elseif is26To28 then
|
|
||||||
drawText(0, 0, "", "black")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function drawMessages()
|
|
||||||
if table.empty(itemMessages) then
|
|
||||||
clearScreen()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local y = 10
|
|
||||||
found = false
|
|
||||||
maxMessageLength = getMaxMessageLength()
|
|
||||||
for k, v in pairs(itemMessages) do
|
|
||||||
if v["TTL"] > 0 then
|
|
||||||
message = v["message"]
|
|
||||||
while true do
|
|
||||||
drawText(5, y, message:sub(1, maxMessageLength), v["color"])
|
|
||||||
y = y + 16
|
|
||||||
|
|
||||||
message = message:sub(maxMessageLength + 1, message:len())
|
|
||||||
if message:len() == 0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
newTTL = 0
|
|
||||||
if is26To28 then
|
|
||||||
newTTL = itemMessages[k]["TTL"] - 1
|
|
||||||
end
|
|
||||||
itemMessages[k]["TTL"] = newTTL
|
|
||||||
found = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if found == false then
|
|
||||||
clearScreen()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function generateLocationChecked()
|
function generateLocationChecked()
|
||||||
memDomain.saveram()
|
memDomain.saveram()
|
||||||
data = uRange(0x01FF, 0x101)
|
data = uRange(0x01FF, 0x101)
|
||||||
@@ -316,7 +234,14 @@ function getEmptyArmorSlots()
|
|||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
local function slice (tbl, s, e)
|
||||||
|
local pos, new = 1, {}
|
||||||
|
for i = s + 1, e do
|
||||||
|
new[pos] = tbl[i]
|
||||||
|
pos = pos + 1
|
||||||
|
end
|
||||||
|
return new
|
||||||
|
end
|
||||||
function processBlock(block)
|
function processBlock(block)
|
||||||
local msgBlock = block['messages']
|
local msgBlock = block['messages']
|
||||||
if msgBlock ~= nil then
|
if msgBlock ~= nil then
|
||||||
@@ -448,18 +373,6 @@ function processBlock(block)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function difference(a, b)
|
|
||||||
local aa = {}
|
|
||||||
for k,v in pairs(a) do aa[v]=true end
|
|
||||||
for k,v in pairs(b) do aa[v]=nil end
|
|
||||||
local ret = {}
|
|
||||||
local n = 0
|
|
||||||
for k,v in pairs(a) do
|
|
||||||
if aa[v] then n=n+1 ret[n]=v end
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
function receive()
|
function receive()
|
||||||
l, e = ff1Socket:receive()
|
l, e = ff1Socket:receive()
|
||||||
if e == 'closed' then
|
if e == 'closed' then
|
||||||
@@ -501,8 +414,7 @@ function receive()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function main()
|
function main()
|
||||||
if (is23Or24Or25 or is26To28) == false then
|
if not checkBizhawkVersion() then
|
||||||
print("Must use a version of bizhawk 2.3.1 or higher")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
server, error = socket.bind('localhost', 52980)
|
server, error = socket.bind('localhost', 52980)
|
||||||
140
data/lua/connector_ladx_bizhawk.lua
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
-- SPDX-FileCopyrightText: 2023 Wilhelm Schürmann <wimschuermann@googlemail.com>
|
||||||
|
--
|
||||||
|
-- SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
-- This script attempts to implement the basic functionality needed in order for
|
||||||
|
-- the LADXR Archipelago client to be able to talk to BizHawk instead of RetroArch
|
||||||
|
-- by reproducing the RetroArch API with BizHawk's Lua interface.
|
||||||
|
--
|
||||||
|
-- RetroArch UDP API: https://github.com/libretro/RetroArch/blob/master/command.c
|
||||||
|
--
|
||||||
|
-- Only
|
||||||
|
-- VERSION
|
||||||
|
-- GET_STATUS
|
||||||
|
-- READ_CORE_MEMORY
|
||||||
|
-- WRITE_CORE_MEMORY
|
||||||
|
-- commands are supported right now.
|
||||||
|
--
|
||||||
|
-- USAGE:
|
||||||
|
-- Load this script in BizHawk ("Tools" -> "Lua Console" -> "Script" -> "Open Script")
|
||||||
|
--
|
||||||
|
-- All inconsistencies (like missing newlines for some commands) of the RetroArch
|
||||||
|
-- UDP API (network_cmd_enable) are reproduced as-is in order for clients written to work with
|
||||||
|
-- RetroArch's current API to "just work"(tm).
|
||||||
|
--
|
||||||
|
-- This script has only been tested on GB(C). If you have made sure it works for N64 or other
|
||||||
|
-- cores supported by BizHawk, please let me know. Note that GET_STATUS, at the very least, will
|
||||||
|
-- have to be adjusted.
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- NOTE:
|
||||||
|
-- BizHawk's Lua API is very trigger-happy on throwing exceptions.
|
||||||
|
-- Emulation will continue fine, but the RetroArch API layer will stop working. This
|
||||||
|
-- is indicated only by an exception visible in the Lua console, which most players
|
||||||
|
-- will probably not have in the foreground.
|
||||||
|
--
|
||||||
|
-- pcall(), the usual way to catch exceptions in Lua, doesn't appear to be supported at all,
|
||||||
|
-- meaning that error/exception handling is not easily possible.
|
||||||
|
--
|
||||||
|
-- This means that a lot more error checking would need to happen before e.g. reading/writing
|
||||||
|
-- memory. Since the end goal, according to AP's Discord, seems to be SNI integration of GB(C),
|
||||||
|
-- no further fault-proofing has been done on this.
|
||||||
|
--
|
||||||
|
|
||||||
|
|
||||||
|
local socket = require("socket")
|
||||||
|
local udp = socket.socket.udp()
|
||||||
|
require('common')
|
||||||
|
|
||||||
|
udp:setsockname('127.0.0.1', 55355)
|
||||||
|
udp:settimeout(0)
|
||||||
|
|
||||||
|
while true do
|
||||||
|
-- Attempt to lessen the CPU load by only polling the UDP socket every x frames.
|
||||||
|
-- x = 10 is entirely arbitrary, very little thought went into it.
|
||||||
|
-- We could try to make use of client.get_approx_framerate() here, but the values returned
|
||||||
|
-- seemed more or less arbitrary as well.
|
||||||
|
--
|
||||||
|
-- NOTE: Never mind the above, the LADXR Archipelago client appears to run into problems with
|
||||||
|
-- interwoven GET_STATUS calls, leading to stopped communication.
|
||||||
|
-- For GB(C), polling the socket on every frame is OK-ish, so we just do that.
|
||||||
|
--
|
||||||
|
--while emu.framecount() % 10 ~= 0 do
|
||||||
|
-- emu.frameadvance()
|
||||||
|
--end
|
||||||
|
|
||||||
|
local data, msg_or_ip, port_or_nil = udp:receivefrom()
|
||||||
|
if data then
|
||||||
|
-- "data" format is "COMMAND [PARAMETERS] [...]"
|
||||||
|
local command = string.match(data, "%S+")
|
||||||
|
if command == "VERSION" then
|
||||||
|
-- 1.14 is the latest RetroArch release at the time of writing this, no other reason
|
||||||
|
-- for choosing this here.
|
||||||
|
udp:sendto("1.14.0\n", msg_or_ip, port_or_nil)
|
||||||
|
elseif command == "GET_STATUS" then
|
||||||
|
local status = "PLAYING"
|
||||||
|
if client.ispaused() then
|
||||||
|
status = "PAUSED"
|
||||||
|
end
|
||||||
|
|
||||||
|
if emu.getsystemid() == "GBC" then
|
||||||
|
-- Actual reply from RetroArch's API:
|
||||||
|
-- "GET_STATUS PLAYING game_boy,AP_62468482466172374046_P1_Lonk,crc32=3ecb7b6f"
|
||||||
|
-- CRC32 isn't readily available through the Lua API. We could calculate
|
||||||
|
-- it ourselves, but since LADXR doesn't make use of this field it is
|
||||||
|
-- simply replaced by the hash that BizHawk _does_ make available.
|
||||||
|
|
||||||
|
udp:sendto(
|
||||||
|
"GET_STATUS " .. status .. " game_boy," ..
|
||||||
|
string.gsub(gameinfo.getromname(), "[%s,]", "_") ..
|
||||||
|
",romhash=" ..
|
||||||
|
gameinfo.getromhash() .. "\n",
|
||||||
|
msg_or_ip, port_or_nil
|
||||||
|
)
|
||||||
|
else -- No ROM loaded
|
||||||
|
-- NOTE: No newline is intentional here for 1:1 RetroArch compatibility
|
||||||
|
udp:sendto("GET_STATUS CONTENTLESS", msg_or_ip, port_or_nil)
|
||||||
|
end
|
||||||
|
elseif command == "READ_CORE_MEMORY" then
|
||||||
|
local _, address, length = string.match(data, "(%S+) (%S+) (%S+)")
|
||||||
|
address = stripPrefix(address, "0x")
|
||||||
|
address = tonumber(address, 16)
|
||||||
|
length = tonumber(length)
|
||||||
|
|
||||||
|
-- NOTE: mainmemory.read_bytes_as_array() would seem to be the obvious choice
|
||||||
|
-- here instead, but it isn't. At least for Sameboy and Gambatte, the "main"
|
||||||
|
-- memory differs (ROM vs WRAM).
|
||||||
|
-- Using memory.read_bytes_as_array() and explicitly using the System Bus
|
||||||
|
-- as the active memory domain solves this incompatibility, allowing us
|
||||||
|
-- to hopefully use whatever GB(C) emulator we want.
|
||||||
|
local mem = memory.read_bytes_as_array(address, length, "System Bus")
|
||||||
|
local hex_string = ""
|
||||||
|
for _, v in ipairs(mem) do
|
||||||
|
hex_string = hex_string .. string.format("%02X ", v)
|
||||||
|
end
|
||||||
|
hex_string = hex_string:sub(1, -2) -- Hang head in shame, remove last " "
|
||||||
|
local reply = string.format("%s %02x %s\n", command, address, hex_string)
|
||||||
|
udp:sendto(reply, msg_or_ip, port_or_nil)
|
||||||
|
elseif command == "WRITE_CORE_MEMORY" then
|
||||||
|
local _, address = string.match(data, "(%S+) (%S+)")
|
||||||
|
address = stripPrefix(address, "0x")
|
||||||
|
address = tonumber(address, 16)
|
||||||
|
|
||||||
|
local to_write = {}
|
||||||
|
local i = 1
|
||||||
|
for byte_str in string.gmatch(data, "%S+") do
|
||||||
|
if i > 2 then
|
||||||
|
byte_str = stripPrefix(byte_str, "0x")
|
||||||
|
table.insert(to_write, tonumber(byte_str, 16))
|
||||||
|
end
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
memory.write_bytes_as_array(address, to_write, "System Bus")
|
||||||
|
local reply = string.format("%s %02x %d\n", command, address, i - 3)
|
||||||
|
udp:sendto(reply, msg_or_ip, port_or_nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
emu.frameadvance()
|
||||||
|
end
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local json = require('json')
|
local json = require('json')
|
||||||
local math = require('math')
|
local math = require('math')
|
||||||
|
require('common')
|
||||||
|
|
||||||
local last_modified_date = '2022-11-27' -- Should be the last modified date
|
local last_modified_date = '2022-4-15' -- Should be the last modified date
|
||||||
local script_version = 3
|
local script_version = 3
|
||||||
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
@@ -1861,8 +1862,7 @@ function receive()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function main()
|
function main()
|
||||||
if (is23Or24Or25 or is26To27) == false then
|
if not checkBizhawkVersion() then
|
||||||
print("Must use a version of bizhawk 2.3.1 or higher")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
server, error = socket.bind('localhost', 28921)
|
server, error = socket.bind('localhost', 28921)
|
||||||
@@ -1886,7 +1886,7 @@ function main()
|
|||||||
ootSocket = client
|
ootSocket = client
|
||||||
ootSocket:settimeout(0)
|
ootSocket:settimeout(0)
|
||||||
else
|
else
|
||||||
print('Connection failed, ensure OoTClient is running and rerun oot_connector.lua')
|
print('Connection failed, ensure OoTClient is running and rerun connector_oot.lua')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1895,4 +1895,4 @@ function main()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local json = require('json')
|
local json = require('json')
|
||||||
local math = require('math')
|
local math = require('math')
|
||||||
|
require("common")
|
||||||
local STATE_OK = "Ok"
|
local STATE_OK = "Ok"
|
||||||
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
||||||
local STATE_INITIAL_CONNECTION_MADE = "Initial Connection Made"
|
local STATE_INITIAL_CONNECTION_MADE = "Initial Connection Made"
|
||||||
@@ -32,9 +32,6 @@ local curstate = STATE_UNINITIALIZED
|
|||||||
local gbSocket = nil
|
local gbSocket = nil
|
||||||
local frame = 0
|
local frame = 0
|
||||||
|
|
||||||
local u8 = nil
|
|
||||||
local wU8 = nil
|
|
||||||
local u16
|
|
||||||
local compat = nil
|
local compat = nil
|
||||||
|
|
||||||
local function defineMemoryFunctions()
|
local function defineMemoryFunctions()
|
||||||
@@ -55,68 +52,42 @@ function uRange(address, bytes)
|
|||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function table.empty (self)
|
|
||||||
for _, _ in pairs(self) do
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function slice (tbl, s, e)
|
|
||||||
local pos, new = 1, {}
|
|
||||||
for i = s + 1, e do
|
|
||||||
new[pos] = tbl[i]
|
|
||||||
pos = pos + 1
|
|
||||||
end
|
|
||||||
return new
|
|
||||||
end
|
|
||||||
|
|
||||||
function difference(a, b)
|
|
||||||
local aa = {}
|
|
||||||
for k,v in pairs(a) do aa[v]=true end
|
|
||||||
for k,v in pairs(b) do aa[v]=nil end
|
|
||||||
local ret = {}
|
|
||||||
local n = 0
|
|
||||||
for k,v in pairs(a) do
|
|
||||||
if aa[v] then n=n+1 ret[n]=v end
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
function generateLocationsChecked()
|
function generateLocationsChecked()
|
||||||
memDomain.wram()
|
memDomain.wram()
|
||||||
events = uRange(EventFlagAddress, 0x140)
|
events = uRange(EventFlagAddress, 0x140)
|
||||||
missables = uRange(MissableAddress, 0x20)
|
missables = uRange(MissableAddress, 0x20)
|
||||||
hiddenitems = uRange(HiddenItemsAddress, 0x0E)
|
hiddenitems = uRange(HiddenItemsAddress, 0x0E)
|
||||||
|
rod = {u8(RodAddress)}
|
||||||
dexsanity = uRange(DexSanityAddress, 19)
|
dexsanity = uRange(DexSanityAddress, 19)
|
||||||
rod = u8(RodAddress)
|
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
table.foreach(events, function(k, v) table.insert(data, v) end)
|
categories = {events, missables, hiddenitems, rod}
|
||||||
table.foreach(missables, function(k, v) table.insert(data, v) end)
|
if compat > 1 then
|
||||||
table.foreach(hiddenitems, function(k, v) table.insert(data, v) end)
|
table.insert(categories, dexsanity)
|
||||||
table.insert(data, rod)
|
end
|
||||||
|
for _, category in ipairs(categories) do
|
||||||
|
for _, v in ipairs(category) do
|
||||||
|
table.insert(data, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if compat > 1 then
|
|
||||||
table.foreach(dexsanity, function(k, v) table.insert(data, v) end)
|
|
||||||
end
|
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
local function arrayEqual(a1, a2)
|
local function arrayEqual(a1, a2)
|
||||||
if #a1 ~= #a2 then
|
if #a1 ~= #a2 then
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
for i, v in ipairs(a1) do
|
|
||||||
if v ~= a2[i] then
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
for i, v in ipairs(a1) do
|
||||||
return true
|
if v ~= a2[i] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function receive()
|
function receive()
|
||||||
@@ -196,8 +167,7 @@ function receive()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function main()
|
function main()
|
||||||
if (is23Or24Or25 or is26To28) == false then
|
if not checkBizhawkVersion() then
|
||||||
print("Must use a version of bizhawk 2.3.1 or higher")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
server, error = socket.bind('localhost', 17242)
|
server, error = socket.bind('localhost', 17242)
|
||||||
@@ -3,13 +3,12 @@
|
|||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local json = require('json')
|
local json = require('json')
|
||||||
local math = require('math')
|
local math = require('math')
|
||||||
|
require("common")
|
||||||
local STATE_OK = "Ok"
|
local STATE_OK = "Ok"
|
||||||
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
local STATE_TENTATIVELY_CONNECTED = "Tentatively Connected"
|
||||||
local STATE_INITIAL_CONNECTION_MADE = "Initial Connection Made"
|
local STATE_INITIAL_CONNECTION_MADE = "Initial Connection Made"
|
||||||
local STATE_UNINITIALIZED = "Uninitialized"
|
local STATE_UNINITIALIZED = "Uninitialized"
|
||||||
|
|
||||||
local itemMessages = {}
|
|
||||||
local consumableStacks = nil
|
local consumableStacks = nil
|
||||||
local prevstate = ""
|
local prevstate = ""
|
||||||
local curstate = STATE_UNINITIALIZED
|
local curstate = STATE_UNINITIALIZED
|
||||||
@@ -21,8 +20,6 @@ local cave_index
|
|||||||
local triforce_byte
|
local triforce_byte
|
||||||
local game_state
|
local game_state
|
||||||
|
|
||||||
local u8 = nil
|
|
||||||
local wU8 = nil
|
|
||||||
local isNesHawk = false
|
local isNesHawk = false
|
||||||
|
|
||||||
local shopsChecked = {}
|
local shopsChecked = {}
|
||||||
@@ -420,83 +417,6 @@ local function checkCaveItemObtained()
|
|||||||
return returnTable
|
return returnTable
|
||||||
end
|
end
|
||||||
|
|
||||||
function table.empty (self)
|
|
||||||
for _, _ in pairs(self) do
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function slice (tbl, s, e)
|
|
||||||
local pos, new = 1, {}
|
|
||||||
for i = s + 1, e do
|
|
||||||
new[pos] = tbl[i]
|
|
||||||
pos = pos + 1
|
|
||||||
end
|
|
||||||
return new
|
|
||||||
end
|
|
||||||
|
|
||||||
local bizhawk_version = client.getversion()
|
|
||||||
local is23Or24Or25 = (bizhawk_version=="2.3.1") or (bizhawk_version:sub(1,3)=="2.4") or (bizhawk_version:sub(1,3)=="2.5")
|
|
||||||
local is26To28 = (bizhawk_version:sub(1,3)=="2.6") or (bizhawk_version:sub(1,3)=="2.7") or (bizhawk_version:sub(1,3)=="2.8")
|
|
||||||
|
|
||||||
local function getMaxMessageLength()
|
|
||||||
if is23Or24Or25 then
|
|
||||||
return client.screenwidth()/11
|
|
||||||
elseif is26To28 then
|
|
||||||
return client.screenwidth()/12
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function drawText(x, y, message, color)
|
|
||||||
if is23Or24Or25 then
|
|
||||||
gui.addmessage(message)
|
|
||||||
elseif is26To28 then
|
|
||||||
gui.drawText(x, y, message, color, 0xB0000000, 18, "Courier New", "middle", "bottom", nil, "client")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function clearScreen()
|
|
||||||
if is23Or24Or25 then
|
|
||||||
return
|
|
||||||
elseif is26To28 then
|
|
||||||
drawText(0, 0, "", "black")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function drawMessages()
|
|
||||||
if table.empty(itemMessages) then
|
|
||||||
clearScreen()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local y = 10
|
|
||||||
found = false
|
|
||||||
maxMessageLength = getMaxMessageLength()
|
|
||||||
for k, v in pairs(itemMessages) do
|
|
||||||
if v["TTL"] > 0 then
|
|
||||||
message = v["message"]
|
|
||||||
while true do
|
|
||||||
drawText(5, y, message:sub(1, maxMessageLength), v["color"])
|
|
||||||
y = y + 16
|
|
||||||
|
|
||||||
message = message:sub(maxMessageLength + 1, message:len())
|
|
||||||
if message:len() == 0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
newTTL = 0
|
|
||||||
if is26To28 then
|
|
||||||
newTTL = itemMessages[k]["TTL"] - 1
|
|
||||||
end
|
|
||||||
itemMessages[k]["TTL"] = newTTL
|
|
||||||
found = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if found == false then
|
|
||||||
clearScreen()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function generateOverworldLocationChecked()
|
function generateOverworldLocationChecked()
|
||||||
memDomain.ram()
|
memDomain.ram()
|
||||||
data = uRange(0x067E, 0x81)
|
data = uRange(0x067E, 0x81)
|
||||||
@@ -589,18 +509,6 @@ function processBlock(block)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function difference(a, b)
|
|
||||||
local aa = {}
|
|
||||||
for k,v in pairs(a) do aa[v]=true end
|
|
||||||
for k,v in pairs(b) do aa[v]=nil end
|
|
||||||
local ret = {}
|
|
||||||
local n = 0
|
|
||||||
for k,v in pairs(a) do
|
|
||||||
if aa[v] then n=n+1 ret[n]=v end
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
function receive()
|
function receive()
|
||||||
l, e = zeldaSocket:receive()
|
l, e = zeldaSocket:receive()
|
||||||
if e == 'closed' then
|
if e == 'closed' then
|
||||||
@@ -621,7 +529,7 @@ function receive()
|
|||||||
|
|
||||||
-- Determine Message to send back
|
-- Determine Message to send back
|
||||||
memDomain.rom()
|
memDomain.rom()
|
||||||
local playerName = uRange(0x1F, 0x10)
|
local playerName = uRange(0x1F, 0x11)
|
||||||
playerName[0] = nil
|
playerName[0] = nil
|
||||||
local retTable = {}
|
local retTable = {}
|
||||||
retTable["playerName"] = playerName
|
retTable["playerName"] = playerName
|
||||||
@@ -653,8 +561,7 @@ function receive()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function main()
|
function main()
|
||||||
if (is23Or24Or25 or is26To28) == false then
|
if not checkBizhawkVersion() then
|
||||||
print("Must use a version of bizhawk 2.3.1 or higher")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
server, error = socket.bind('localhost', 52980)
|
server, error = socket.bind('localhost', 52980)
|
||||||
12
data/lua/lua_5_3_compat.lua
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
function bit.rshift(a, b)
|
||||||
|
return a >> b
|
||||||
|
end
|
||||||
|
function bit.lshift(a, b)
|
||||||
|
return a << b
|
||||||
|
end
|
||||||
|
function bit.bor(a, b)
|
||||||
|
return a | b
|
||||||
|
end
|
||||||
|
function bit.band(a, b)
|
||||||
|
return a & b
|
||||||
|
end
|
||||||
@@ -10,8 +10,55 @@
|
|||||||
local base = _G
|
local base = _G
|
||||||
local string = require("string")
|
local string = require("string")
|
||||||
local math = require("math")
|
local math = require("math")
|
||||||
local socket = require("socket.core")
|
|
||||||
module("socket")
|
function get_lua_version()
|
||||||
|
local major, minor = _VERSION:match("Lua (%d+)%.(%d+)")
|
||||||
|
assert(tonumber(major) == 5)
|
||||||
|
if tonumber(minor) >= 4 then
|
||||||
|
return "5-4"
|
||||||
|
end
|
||||||
|
return "5-1"
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_os()
|
||||||
|
local the_os, ext, arch
|
||||||
|
if package.config:sub(1,1) == "\\" then
|
||||||
|
the_os, ext = "windows", "dll"
|
||||||
|
arch = os.getenv"PROCESSOR_ARCHITECTURE"
|
||||||
|
else
|
||||||
|
-- TODO: macos?
|
||||||
|
the_os, ext = "linux", "so"
|
||||||
|
arch = "x86_64" -- TODO: read ELF header from /proc/$PID/exe to get arch
|
||||||
|
end
|
||||||
|
|
||||||
|
if arch:find("64") ~= nil then
|
||||||
|
arch = "x64"
|
||||||
|
else
|
||||||
|
arch = "x86"
|
||||||
|
end
|
||||||
|
|
||||||
|
return the_os, ext, arch
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_socket_path()
|
||||||
|
local the_os, ext, arch = get_os()
|
||||||
|
-- for some reason ./ isn't working, so use a horrible hack to get the pwd
|
||||||
|
local pwd = (io.popen and io.popen("cd"):read'*l') or "."
|
||||||
|
return pwd .. "/" .. arch .. "/socket-" .. the_os .. "-" .. get_lua_version() .. "." .. ext
|
||||||
|
end
|
||||||
|
|
||||||
|
local socket_path = get_socket_path()
|
||||||
|
local socket = assert(package.loadlib(socket_path, "luaopen_socket_core"))()
|
||||||
|
|
||||||
|
-- http://lua-users.org/wiki/ModulesTutorial
|
||||||
|
local M = {}
|
||||||
|
if setfenv then
|
||||||
|
setfenv(1, M) -- for 5.1
|
||||||
|
else
|
||||||
|
_ENV = M -- for 5.2
|
||||||
|
end
|
||||||
|
|
||||||
|
M.socket = socket
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- Exported auxiliar functions
|
-- Exported auxiliar functions
|
||||||
@@ -39,7 +86,7 @@ function bind(host, port, backlog)
|
|||||||
return sock
|
return sock
|
||||||
end
|
end
|
||||||
|
|
||||||
try = newtry()
|
try = socket.newtry()
|
||||||
|
|
||||||
function choose(table)
|
function choose(table)
|
||||||
return function(name, opt1, opt2)
|
return function(name, opt1, opt2)
|
||||||
@@ -130,3 +177,5 @@ end
|
|||||||
sourcet["default"] = sourcet["until-closed"]
|
sourcet["default"] = sourcet["until-closed"]
|
||||||
|
|
||||||
source = choose(sourcet)
|
source = choose(sourcet)
|
||||||
|
|
||||||
|
return M
|
||||||
20
data/lua/x64/luasocket.LICENSE.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
LuaSocket 3.0 license
|
||||||
|
Copyright <20> 2004-2013 Diego Nehab
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
BIN
data/lua/x64/socket-linux-5-1.so
Normal file
BIN
data/lua/x64/socket-linux-5-4.so
Normal file
BIN
data/lua/x64/socket-windows-5-1.dll
Normal file
BIN
data/lua/x64/socket-windows-5-4.dll
Normal file
20
data/lua/x86/luasocket.LICENSE.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
LuaSocket 3.0 license
|
||||||
|
Copyright <20> 2004-2013 Diego Nehab
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
BIN
data/lua/x86/socket-windows-5-1.dll
Normal file
BIN
data/mcicon.png
Normal file
|
After Width: | Height: | Size: 594 B |
BIN
data/sprites/ladx/Bowwow.bdiff
Normal file
BIN
data/sprites/ladx/Bunny.bdiff
Normal file
BIN
data/sprites/ladx/Luigi.bdiff
Normal file
BIN
data/sprites/ladx/Mario.bdiff
Normal file
BIN
data/sprites/ladx/Matty_LA.bdiff
Normal file
BIN
data/sprites/ladx/Richard.bdiff
Normal file
BIN
data/sprites/ladx/Tarin.bdiff
Normal file
@@ -7,10 +7,12 @@ See [world api.md](world%20api.md) for details.
|
|||||||
apworld provides a way to package and ship a world that is not part of the main distribution by placing a `*.apworld`
|
apworld provides a way to package and ship a world that is not part of the main distribution by placing a `*.apworld`
|
||||||
file into the worlds folder.
|
file into the worlds folder.
|
||||||
|
|
||||||
|
**Warning:** apworlds have to be all lower case, otherwise they raise a bogus Exception when trying to import in frozen python 3.10+!
|
||||||
|
|
||||||
|
|
||||||
## File Format
|
## File Format
|
||||||
|
|
||||||
apworld files are zip archives with the case-sensitive file ending `.apworld`.
|
apworld files are zip archives, all lower case, with the file ending `.apworld`.
|
||||||
The zip has to contain a folder with the same name as the zip, case-sensitive, that contains what would normally be in
|
The zip has to contain a folder with the same name as the zip, case-sensitive, that contains what would normally be in
|
||||||
the world's folder in `worlds/`. I.e. `worlds/ror2.apworld` containing `ror2/__init__.py`.
|
the world's folder in `worlds/`. I.e. `worlds/ror2.apworld` containing `ror2/__init__.py`.
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 526 KiB After Width: | Height: | Size: 535 KiB |
@@ -75,6 +75,18 @@ flowchart LR
|
|||||||
end
|
end
|
||||||
SNI <-- Various, depending on SNES device --> DK3
|
SNI <-- Various, depending on SNES device --> DK3
|
||||||
|
|
||||||
|
%% Super Mario World
|
||||||
|
subgraph Super Mario World
|
||||||
|
SMW[SNES]
|
||||||
|
end
|
||||||
|
SNI <-- Various, depending on SNES device --> SMW
|
||||||
|
|
||||||
|
%% Lufia II Ancient Cave
|
||||||
|
subgraph Lufia II Ancient Cave
|
||||||
|
L2AC[SNES]
|
||||||
|
end
|
||||||
|
SNI <-- Various, depending on SNES device --> L2AC
|
||||||
|
|
||||||
%% Native Clients or Games
|
%% Native Clients or Games
|
||||||
%% Games or clients which compile to native or which the client is integrated in the game.
|
%% Games or clients which compile to native or which the client is integrated in the game.
|
||||||
subgraph "Native"
|
subgraph "Native"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 91 KiB |
@@ -20,12 +20,13 @@ There are also a number of community-supported libraries available that implemen
|
|||||||
| Python | [Archipelago CommonClient](https://github.com/ArchipelagoMW/Archipelago/blob/main/CommonClient.py) | |
|
| Python | [Archipelago CommonClient](https://github.com/ArchipelagoMW/Archipelago/blob/main/CommonClient.py) | |
|
||||||
| | [Archipelago SNIClient](https://github.com/ArchipelagoMW/Archipelago/blob/main/SNIClient.py) | For Super Nintendo Game Support; Utilizes [SNI](https://github.com/alttpo/sni). |
|
| | [Archipelago SNIClient](https://github.com/ArchipelagoMW/Archipelago/blob/main/SNIClient.py) | For Super Nintendo Game Support; Utilizes [SNI](https://github.com/alttpo/sni). |
|
||||||
| JVM (Java / Kotlin) | [Archipelago.MultiClient.Java](https://github.com/ArchipelagoMW/Archipelago.MultiClient.Java) | |
|
| JVM (Java / Kotlin) | [Archipelago.MultiClient.Java](https://github.com/ArchipelagoMW/Archipelago.MultiClient.Java) | |
|
||||||
| .NET (C# / C++ / F# / VB.NET) | [Archipelago.MultiClient.Net](https://www.nuget.org/packages/Archipelago.MultiClient.Net) | |
|
| .NET (C# / F# / VB.NET) | [Archipelago.MultiClient.Net](https://www.nuget.org/packages/Archipelago.MultiClient.Net) | |
|
||||||
| C++ | [apclientpp](https://github.com/black-sliver/apclientpp) | header-only |
|
| C++ | [apclientpp](https://github.com/black-sliver/apclientpp) | header-only |
|
||||||
| | [APCpp](https://github.com/N00byKing/APCpp) | CMake |
|
| | [APCpp](https://github.com/N00byKing/APCpp) | CMake |
|
||||||
| JavaScript / TypeScript | [archipelago.js](https://www.npmjs.com/package/archipelago.js) | Browser and Node.js Supported |
|
| JavaScript / TypeScript | [archipelago.js](https://www.npmjs.com/package/archipelago.js) | Browser and Node.js Supported |
|
||||||
| Haxe | [hxArchipelago](https://lib.haxe.org/p/hxArchipelago) | |
|
| Haxe | [hxArchipelago](https://lib.haxe.org/p/hxArchipelago) | |
|
||||||
| Rust | [ArchipelagoRS](https://github.com/ryanisaacg/archipelago_rs) | |
|
| Rust | [ArchipelagoRS](https://github.com/ryanisaacg/archipelago_rs) | |
|
||||||
|
| Lua | [lua-apclientpp](https://github.com/black-sliver/lua-apclientpp) | |
|
||||||
|
|
||||||
## Synchronizing Items
|
## Synchronizing Items
|
||||||
When the client receives a [ReceivedItems](#ReceivedItems) packet, if the `index` argument does not match the next index that the client expects then it is expected that the client will re-sync items with the server. This can be accomplished by sending the server a [Sync](#Sync) packet and then a [LocationChecks](#LocationChecks) packet.
|
When the client receives a [ReceivedItems](#ReceivedItems) packet, if the `index` argument does not match the next index that the client expects then it is expected that the client will re-sync items with the server. This can be accomplished by sending the server a [Sync](#Sync) packet and then a [LocationChecks](#LocationChecks) packet.
|
||||||
@@ -64,18 +65,20 @@ These packets are are sent from the multiworld server to the client. They are no
|
|||||||
### RoomInfo
|
### RoomInfo
|
||||||
Sent to clients when they connect to an Archipelago server.
|
Sent to clients when they connect to an Archipelago server.
|
||||||
#### Arguments
|
#### Arguments
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ---- | ---- | ----- |
|
|-----------------------|-----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| version | [NetworkVersion](#NetworkVersion) | Object denoting the version of Archipelago which the server is running. |
|
| version | [NetworkVersion](#NetworkVersion) | Object denoting the version of Archipelago which the server is running. |
|
||||||
| tags | list\[str\] | Denotes special features or capabilities that the sender is capable of. Example: `WebHost` |
|
| generator_version | [NetworkVersion](#NetworkVersion) | Object denoting the version of Archipelago which generated the multiworld. |
|
||||||
| password | bool | Denoted whether a password is required to join this room.|
|
| tags | list\[str\] | Denotes special features or capabilities that the sender is capable of. Example: `WebHost` |
|
||||||
| permissions | dict\[str, [Permission](#Permission)\[int\]\] | Mapping of permission name to [Permission](#Permission), keys are: "release", "collect" and "remaining". |
|
| password | bool | Denoted whether a password is required to join this room. |
|
||||||
| hint_cost | int | The amount of points it costs to receive a hint from the server. |
|
| permissions | dict\[str, [Permission](#Permission)\[int\]\] | Mapping of permission name to [Permission](#Permission), keys are: "release", "collect" and "remaining". |
|
||||||
| location_check_points | int | The amount of hint points you receive per item/location check completed. ||
|
| hint_cost | int | The percentage of total locations that need to be checked to receive a hint from the server. |
|
||||||
| games | list\[str\] | List of games present in this multiworld. |
|
| location_check_points | int | The amount of hint points you receive per item/location check completed. |
|
||||||
| datapackage_versions | dict\[str, int\] | Data versions of the individual games' data packages the server will send. Used to decide which games' caches are outdated. See [Data Package Contents](#Data-Package-Contents). |
|
| games | list\[str\] | List of games present in this multiworld. |
|
||||||
| seed_name | str | uniquely identifying name of this generation |
|
| datapackage_versions | dict\[str, int\] | Data versions of the individual games' data packages the server will send. Used to decide which games' caches are outdated. See [Data Package Contents](#Data-Package-Contents). **Deprecated. Use `datapackage_checksums` instead.** |
|
||||||
| time | float | Unix time stamp of "now". Send for time synchronization if wanted for things like the DeathLink Bounce. |
|
| datapackage_checksums | dict[str, str] | Checksum hash of the individual games' data packages the server will send. Used by newer clients to decide which games' caches are outdated. See [Data Package Contents](#Data-Package-Contents) for more information. |
|
||||||
|
| seed_name | str | Uniquely identifying name of this generation |
|
||||||
|
| time | float | Unix time stamp of "now". Send for time synchronization if wanted for things like the DeathLink Bounce. |
|
||||||
|
|
||||||
#### release
|
#### release
|
||||||
Dictates what is allowed when it comes to a player releasing their run. A release is an action which distributes the rest of the items in a player's run to those other players awaiting them.
|
Dictates what is allowed when it comes to a player releasing their run. A release is an action which distributes the rest of the items in a player's run to those other players awaiting them.
|
||||||
@@ -106,8 +109,8 @@ Dictates what is allowed when it comes to a player querying the items remaining
|
|||||||
### ConnectionRefused
|
### ConnectionRefused
|
||||||
Sent to clients when the server refuses connection. This is sent during the initial connection handshake.
|
Sent to clients when the server refuses connection. This is sent during the initial connection handshake.
|
||||||
#### Arguments
|
#### Arguments
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ---- | ---- | ----- |
|
|--------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| errors | list\[str\] | Optional. When provided, should contain any one of: `InvalidSlot`, `InvalidGame`, `IncompatibleVersion`, `InvalidPassword`, or `InvalidItemsHandling`. |
|
| errors | list\[str\] | Optional. When provided, should contain any one of: `InvalidSlot`, `InvalidGame`, `IncompatibleVersion`, `InvalidPassword`, or `InvalidItemsHandling`. |
|
||||||
|
|
||||||
InvalidSlot indicates that the sent 'name' field did not match any auth entry on the server.
|
InvalidSlot indicates that the sent 'name' field did not match any auth entry on the server.
|
||||||
@@ -127,7 +130,8 @@ Sent to clients when the connection handshake is successfully completed.
|
|||||||
| missing_locations | list\[int\] | Contains ids of remaining locations that need to be checked. Useful for trackers, among other things. |
|
| missing_locations | list\[int\] | Contains ids of remaining locations that need to be checked. Useful for trackers, among other things. |
|
||||||
| checked_locations | list\[int\] | Contains ids of all locations that have been checked. Useful for trackers, among other things. Location ids are in the range of ± 2<sup>53</sup>-1. |
|
| checked_locations | list\[int\] | Contains ids of all locations that have been checked. Useful for trackers, among other things. Location ids are in the range of ± 2<sup>53</sup>-1. |
|
||||||
| slot_data | dict\[str, any\] | Contains a json object for slot related data, differs per game. Empty if not required. Not present if slot_data in [Connect](#Connect) is false. |
|
| slot_data | dict\[str, any\] | Contains a json object for slot related data, differs per game. Empty if not required. Not present if slot_data in [Connect](#Connect) is false. |
|
||||||
| slot_info | dict\[int, [NetworkSlot](#NetworkSlot)\] | maps each slot to a [NetworkSlot](#NetworkSlot) information |
|
| slot_info | dict\[int, [NetworkSlot](#NetworkSlot)\] | maps each slot to a [NetworkSlot](#NetworkSlot) information. |
|
||||||
|
| hint_points | int | Number of hint points that the current player has. |
|
||||||
|
|
||||||
### ReceivedItems
|
### ReceivedItems
|
||||||
Sent to clients when they receive an item.
|
Sent to clients when they receive an item.
|
||||||
@@ -145,17 +149,16 @@ Sent to clients to acknowledge a received [LocationScouts](#LocationScouts) pack
|
|||||||
| locations | list\[[NetworkItem](#NetworkItem)\] | Contains list of item(s) in the location(s) scouted. |
|
| locations | list\[[NetworkItem](#NetworkItem)\] | Contains list of item(s) in the location(s) scouted. |
|
||||||
|
|
||||||
### RoomUpdate
|
### RoomUpdate
|
||||||
Sent when there is a need to update information about the present game session. Generally useful for async games.
|
Sent when there is a need to update information about the present game session.
|
||||||
Once authenticated (received Connected), this may also contain data from Connected.
|
|
||||||
#### Arguments
|
#### Arguments
|
||||||
The arguments for RoomUpdate are identical to [RoomInfo](#RoomInfo) barring:
|
RoomUpdate may contain the same arguments from [RoomInfo](#RoomInfo) and, once authenticated, arguments from
|
||||||
|
[Connected](#Connected) with the following exceptions:
|
||||||
|
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ---- | ---- | ----- |
|
|-------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||||
| hint_points | int | New argument. The client's current hint points. |
|
| players | list\[[NetworkPlayer](#NetworkPlayer)\] | Sent in the event of an alias rename. Always sends all players, whether connected or not. |
|
||||||
| players | list\[[NetworkPlayer](#NetworkPlayer)\] | Send in the event of an alias rename. Always sends all players, whether connected or not. |
|
| checked_locations | list\[int\] | May be a partial update, containing new locations that were checked, especially from a coop partner in the same slot. |
|
||||||
| checked_locations | list\[int\] | May be a partial update, containing new locations that were checked, especially from a coop partner in the same slot. |
|
| missing_locations | - | Never sent in this packet. If needed, it is the inverse of `checked_locations`. |
|
||||||
| missing_locations | list\[int\] | Should never be sent as an update, if needed is the inverse of checked_locations. |
|
|
||||||
|
|
||||||
All arguments for this packet are optional, only changes are sent.
|
All arguments for this packet are optional, only changes are sent.
|
||||||
|
|
||||||
@@ -554,12 +557,16 @@ Color options:
|
|||||||
`flags` contains the [NetworkItem](#NetworkItem) flags that belong to the item
|
`flags` contains the [NetworkItem](#NetworkItem) flags that belong to the item
|
||||||
|
|
||||||
### Client States
|
### Client States
|
||||||
An enumeration containing the possible client states that may be used to inform the server in [StatusUpdate](#StatusUpdate).
|
An enumeration containing the possible client states that may be used to inform
|
||||||
|
the server in [StatusUpdate](#StatusUpdate). The MultiServer automatically sets
|
||||||
|
the client state to `ClientStatus.CLIENT_CONNECTED` on the first active connection
|
||||||
|
to a slot.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import enum
|
import enum
|
||||||
class ClientStatus(enum.IntEnum):
|
class ClientStatus(enum.IntEnum):
|
||||||
CLIENT_UNKNOWN = 0
|
CLIENT_UNKNOWN = 0
|
||||||
|
CLIENT_CONNECTED = 5
|
||||||
CLIENT_READY = 10
|
CLIENT_READY = 10
|
||||||
CLIENT_PLAYING = 20
|
CLIENT_PLAYING = 20
|
||||||
CLIENT_GOAL = 30
|
CLIENT_GOAL = 30
|
||||||
@@ -644,11 +651,12 @@ Note:
|
|||||||
#### GameData
|
#### GameData
|
||||||
GameData is a **dict** but contains these keys and values. It's broken out into another "type" for ease of documentation.
|
GameData is a **dict** but contains these keys and values. It's broken out into another "type" for ease of documentation.
|
||||||
|
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ---- | ---- | ----- |
|
|---------------------|----------------|-------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| item_name_to_id | dict[str, int] | Mapping of all item names to their respective ID. |
|
| item_name_to_id | dict[str, int] | Mapping of all item names to their respective ID. |
|
||||||
| location_name_to_id | dict[str, int] | Mapping of all location names to their respective ID. |
|
| location_name_to_id | dict[str, int] | Mapping of all location names to their respective ID. |
|
||||||
| version | int | Version number of this game's data |
|
| version | int | Version number of this game's data. Deprecated. Used by older clients to request an updated datapackage if cache is outdated. |
|
||||||
|
| checksum | str | A checksum hash of this game's data. |
|
||||||
|
|
||||||
### Tags
|
### Tags
|
||||||
Tags are represented as a list of strings, the common Client tags follow:
|
Tags are represented as a list of strings, the common Client tags follow:
|
||||||
|
|||||||
@@ -13,14 +13,20 @@ need to create:
|
|||||||
- A new option class with a docstring detailing what the option will do to your user.
|
- A new option class with a docstring detailing what the option will do to your user.
|
||||||
- A `display_name` to be displayed on the webhost.
|
- A `display_name` to be displayed on the webhost.
|
||||||
- A new entry in the `option_definitions` dict for your World.
|
- A new entry in the `option_definitions` dict for your World.
|
||||||
By style and convention, the internal names should be snake_case. If the option supports having multiple sub_options
|
By style and convention, the internal names should be snake_case.
|
||||||
such as Choice options, these can be defined with `option_my_sub_option`, where the preceding `option_` is required and
|
|
||||||
stripped for users, so will show as `my_sub_option` in yaml files and if `auto_display_name` is True `My Sub Option`
|
|
||||||
on the webhost. All options support `random` as a generic option. `random` chooses from any of the available
|
|
||||||
values for that option, and is reserved by AP. You can set this as your default value but you cannot define your own
|
|
||||||
new `option_random`.
|
|
||||||
|
|
||||||
### Option Creation
|
### Option Creation
|
||||||
|
- If the option supports having multiple sub_options, such as Choice options, these can be defined with
|
||||||
|
`option_value1`. Any attributes of the class with a preceding `option_` is added to the class's `options` lookup. The
|
||||||
|
`option_` is then stripped for users, so will show as `value1` in yaml files. If `auto_display_name` is True, it will
|
||||||
|
display as `Value1` on the webhost.
|
||||||
|
- An alternative name can be set for any specific option by setting an alias attribute
|
||||||
|
(i.e. `alias_value_1 = option_value1`) which will allow users to use either `value_1` or `value1` in their yaml
|
||||||
|
files, and both will resolve as `value1`. This should be used when changing options around, i.e. changing a Toggle to a
|
||||||
|
Choice, and defining `alias_true = option_full`.
|
||||||
|
- All options support `random` as a generic option. `random` chooses from any of the available values for that option,
|
||||||
|
and is reserved by AP. You can set this as your default value, but you cannot define your own `option_random`.
|
||||||
|
|
||||||
As an example, suppose we want an option that lets the user start their game with a sword in their inventory. Let's
|
As an example, suppose we want an option that lets the user start their game with a sword in their inventory. Let's
|
||||||
create our option class (with a docstring), give it a `display_name`, and add it to a dictionary that keeps track of our
|
create our option class (with a docstring), give it a `display_name`, and add it to a dictionary that keeps track of our
|
||||||
options:
|
options:
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ use that version. These steps are for developers or platforms without compiled r
|
|||||||
## General
|
## General
|
||||||
|
|
||||||
What you'll need:
|
What you'll need:
|
||||||
* Python 3.8.7 or newer
|
* [Python 3.8.7 or newer](https://www.python.org/downloads/), not the Windows Store version
|
||||||
* pip (Depending on platform may come included)
|
* **Python 3.11 does not work currently**
|
||||||
* A C compiler
|
* pip: included in downloads from python.org, separate in many Linux distributions
|
||||||
* possibly optional, read OS-specific sections
|
* Matching C compiler
|
||||||
|
* possibly optional, read operating system specific sections
|
||||||
|
|
||||||
Then run any of the starting point scripts, like Generate.py, and the included ModuleUpdater should prompt to install or update the
|
Then run any of the starting point scripts, like Generate.py, and the included ModuleUpdater should prompt to install or update the
|
||||||
required modules and after pressing enter proceed to install everything automatically.
|
required modules and after pressing enter proceed to install everything automatically.
|
||||||
@@ -29,17 +30,19 @@ After this, you should be able to run the programs.
|
|||||||
|
|
||||||
Recommended steps
|
Recommended steps
|
||||||
* Download and install a "Windows installer (64-bit)" from the [Python download page](https://www.python.org/downloads)
|
* Download and install a "Windows installer (64-bit)" from the [Python download page](https://www.python.org/downloads)
|
||||||
* Download and install full Visual Studio from
|
* **Python 3.11 does not work currently**
|
||||||
[Visual Studio Downloads](https://visualstudio.microsoft.com/downloads/)
|
|
||||||
or an older "Build Tools for Visual Studio" from
|
|
||||||
[Visual Studio Older Downloads](https://visualstudio.microsoft.com/vs/older-downloads/).
|
|
||||||
|
|
||||||
* Refer to [Windows Compilers on the python wiki](https://wiki.python.org/moin/WindowsCompilers) for details
|
* **Optional**: Download and install Visual Studio Build Tools from
|
||||||
* This step is optional. Pre-compiled modules are pinned on
|
[Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/).
|
||||||
|
* Refer to [Windows Compilers on the python wiki](https://wiki.python.org/moin/WindowsCompilers) for details.
|
||||||
|
Generally, selecting the box for "Desktop Development with C++" will provide what you need.
|
||||||
|
* Build tools are not required if all modules are installed pre-compiled. Pre-compiled modules are pinned on
|
||||||
[Discord in #archipelago-dev](https://discord.com/channels/731205301247803413/731214280439103580/905154456377757808)
|
[Discord in #archipelago-dev](https://discord.com/channels/731205301247803413/731214280439103580/905154456377757808)
|
||||||
|
|
||||||
* It is recommended to use [PyCharm IDE](https://www.jetbrains.com/pycharm/)
|
* It is recommended to use [PyCharm IDE](https://www.jetbrains.com/pycharm/)
|
||||||
* Run Generate.py which will prompt installation of missing modules, press enter to confirm
|
* Run Generate.py which will prompt installation of missing modules, press enter to confirm
|
||||||
|
* In PyCharm: right-click Generate.py and select `Run 'Generate'`
|
||||||
|
* Without PyCharm: open a command prompt in the source folder and type `py Generate.py`
|
||||||
|
|
||||||
|
|
||||||
## macOS
|
## macOS
|
||||||
@@ -59,7 +62,7 @@ setting in host.yaml at your Enemizer executable.
|
|||||||
|
|
||||||
## Optional: SNI
|
## Optional: SNI
|
||||||
|
|
||||||
SNI is required to use SNIClient. If not integrated into the project, it has to be started manually.
|
[SNI](https://github.com/alttpo/sni/blob/main/README.md) is required to use SNIClient. If not integrated into the project, it has to be started manually.
|
||||||
|
|
||||||
You can get the latest SNI release at [SNI Github releases](https://github.com/alttpo/sni/releases).
|
You can get the latest SNI release at [SNI Github releases](https://github.com/alttpo/sni/releases).
|
||||||
It should be dropped as "SNI" into the root folder of the project. Alternatively, you can point the sni setting in
|
It should be dropped as "SNI" into the root folder of the project. Alternatively, you can point the sni setting in
|
||||||
|
|||||||
@@ -364,14 +364,9 @@ class MyGameLocation(Location): # or from Locations import MyGameLocation
|
|||||||
|
|
||||||
class MyGameWorld(World):
|
class MyGameWorld(World):
|
||||||
"""Insert description of the world/game here."""
|
"""Insert description of the world/game here."""
|
||||||
game: str = "My Game" # name of the game/world
|
game = "My Game" # name of the game/world
|
||||||
option_definitions = mygame_options # options the player can set
|
option_definitions = mygame_options # options the player can set
|
||||||
topology_present: bool = True # show path to required location checks in spoiler
|
topology_present = True # show path to required location checks in spoiler
|
||||||
|
|
||||||
# data_version is used to signal that items, locations or their names
|
|
||||||
# changed. Set this to 0 during development so other games' clients do not
|
|
||||||
# cache any texts, then increase by 1 for each release that makes changes.
|
|
||||||
data_version = 0
|
|
||||||
|
|
||||||
# ID of first item and location, could be hard-coded but code may be easier
|
# ID of first item and location, could be hard-coded but code may be easier
|
||||||
# to read with this as a propery.
|
# to read with this as a propery.
|
||||||
|
|||||||
26
host.yaml
@@ -93,6 +93,10 @@ sni_options:
|
|||||||
lttp_options:
|
lttp_options:
|
||||||
# File name of the v1.0 J rom
|
# File name of the v1.0 J rom
|
||||||
rom_file: "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc"
|
rom_file: "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc"
|
||||||
|
ladx_options:
|
||||||
|
# File name of the Link's Awakening DX rom
|
||||||
|
rom_file: "Legend of Zelda, The - Link's Awakening DX (USA, Europe) (SGB Enhanced).gbc"
|
||||||
|
|
||||||
lufia2ac_options:
|
lufia2ac_options:
|
||||||
# File name of the US rom
|
# File name of the US rom
|
||||||
rom_file: "Lufia II - Rise of the Sinistrals (USA).sfc"
|
rom_file: "Lufia II - Rise of the Sinistrals (USA).sfc"
|
||||||
@@ -163,3 +167,25 @@ zillion_options:
|
|||||||
# RetroArch doesn't make it easy to launch a game from the command line.
|
# RetroArch doesn't make it easy to launch a game from the command line.
|
||||||
# You have to know the path to the emulator core library on the user's computer.
|
# You have to know the path to the emulator core library on the user's computer.
|
||||||
rom_start: "retroarch"
|
rom_start: "retroarch"
|
||||||
|
|
||||||
|
adventure_options:
|
||||||
|
# File name of the standard NTSC Adventure rom.
|
||||||
|
# The licensed "The 80 Classic Games" CD-ROM contains this.
|
||||||
|
# It may also have a .a26 extension
|
||||||
|
rom_file: "ADVNTURE.BIN"
|
||||||
|
# Set this to false to never autostart a rom (such as after patching)
|
||||||
|
# True for operating system default program for '.a26'
|
||||||
|
# Alternatively, a path to a program to open the .a26 file with (generally EmuHawk for multiworld)
|
||||||
|
rom_start: true
|
||||||
|
# Optional, additional args passed into rom_start before the .bin file
|
||||||
|
# For example, this can be used to autoload the connector script in BizHawk
|
||||||
|
# (see BizHawk --lua= option)
|
||||||
|
# Windows example:
|
||||||
|
# rom_args: "--lua=C:/ProgramData/Archipelago/data/lua/connector_adventure.lua"
|
||||||
|
rom_args: " "
|
||||||
|
# Set this to true to display item received messages in Emuhawk
|
||||||
|
display_msgs: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||