diff --git a/.gitmodules b/.gitmodules index f05842fa7b..16ad1921cc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "extern/borealis"] path = extern/borealis url = https://github.com/encounter/borealis.git +[submodule "mods/randomizer"] + path = mods/randomizer + url = https://github.com/TwilitRealm/dusklight-randomizer.git diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd53086fe..b721eba8ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -571,6 +571,7 @@ if (DUSK_ENABLE_CODE_MODS AND CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR add_subdirectory(mods/window_demo) add_subdirectory(mods/flow_demo) add_subdirectory(mods/basic_cosmetics_mod) + add_subdirectory(mods/randomizer) endif () if (APPLE) diff --git a/cmake/ModExports.exp b/cmake/ModExports.exp new file mode 100644 index 0000000000..3a9ec12942 --- /dev/null +++ b/cmake/ModExports.exp @@ -0,0 +1,5 @@ +_mod_ctx +_mod_initialize +_mod_meta +_mod_shutdown +_mod_update diff --git a/cmake/ModExports.ver b/cmake/ModExports.ver new file mode 100644 index 0000000000..9ddff1866c --- /dev/null +++ b/cmake/ModExports.ver @@ -0,0 +1,10 @@ +{ + global: + mod_ctx; + mod_initialize; + mod_meta; + mod_shutdown; + mod_update; + local: + *; +}; diff --git a/cmake/ModSDK.cmake b/cmake/ModSDK.cmake index da9aa51f38..53c903b627 100644 --- a/cmake/ModSDK.cmake +++ b/cmake/ModSDK.cmake @@ -185,6 +185,20 @@ function(add_mod target_name) WINDOWS_EXPORT_ALL_SYMBOLS OFF) target_compile_features(${target_name} PRIVATE cxx_std_20) target_link_libraries(${target_name} PRIVATE dusklight_mod_api) + + if (APPLE) + set(_mod_exports "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ModExports.exp") + target_link_options(${target_name} PRIVATE + -Xlinker -exported_symbols_list -Xlinker "${_mod_exports}") + set_property(TARGET ${target_name} APPEND PROPERTY LINK_DEPENDS "${_mod_exports}") + elseif (UNIX) + set(_mod_exports "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ModExports.ver") + target_link_options(${target_name} PRIVATE + "-Wl,--version-script=${_mod_exports}" + -Wl,--no-undefined-version) + set_property(TARGET ${target_name} APPEND PROPERTY LINK_DEPENDS "${_mod_exports}") + endif () + foreach (_feature IN LISTS _features) target_link_libraries(${target_name} PRIVATE dusklight_mod_feature_${_feature}) if (_feature STREQUAL "webgpu") diff --git a/docs/modding.md b/docs/modding.md index 637a718a53..4ad29aa8da 100644 --- a/docs/modding.md +++ b/docs/modding.md @@ -257,6 +257,48 @@ mods::file::export_file(location, "report.txt", [](mods::file::PickResult result `export_file` copies an existing file to a user-selected destination and returns the destination location in its callback. Mod-owned persistent files belong in `HostService::data_dir`. +### HttpService (`mods/svc/http.h`) + +Asynchronous HTTPS requests supporting HTTP/2 and TLS 1.2+. C++ mods should use the helpers in `mods/svc/http.hpp`: + +```cpp +#include "mods/svc/http.hpp" + +IMPORT_SERVICE(HttpService, svc_http); + +mods::http::Pending pendingRequest; + +void fetch_manifest() { + mods::http::Request request{ + .url = "https://example.com/manifest.json", + .maxBodyBytes = 256 * 1024, + }; + pendingRequest = mods::http::request(request, [](mods::http::Response response) { + if (!response.ok()) { + handle_fetch_error(response.error, response.statusCode); + return; + } + + std::string manifest{response.body.begin(), response.body.end()}; + use_manifest(manifest); + }); + if (!pendingRequest) { + handle_start_error(pendingRequest.result()); + } +} +``` + +Keep the returned `Pending` alive until completion. Dropping it or calling `cancel` requests cancellation. Callbacks run +on the game thread. + +`Response::ok()` requires a 2xx status. Other HTTP statuses are valid responses, not transport errors, so always check +`statusCode`. In-memory responses default to a 1 MiB limit; set `maxBodyBytes` to increase it if needed. + +For large responses, set `downloadPath` to an absolute path in the calling mod's `HostService::data_dir` or +`HostService::mod_dir`. The response is streamed to disk instead of loaded in memory. On success, the callback receives +an empty `body` and the final path in `downloadPath`. Check `Response::ok()` before using the file. +`Pending::progress()` reports download progress when the server provides a total size. + ### HostService (`mods/svc/host.h`) Mod metadata and runtime interaction with the loader: diff --git a/extern/borealis b/extern/borealis index 32153a5480..4b76f9ea35 160000 --- a/extern/borealis +++ b/extern/borealis @@ -1 +1 @@ -Subproject commit 32153a548019aa0557ce0da354c2e737799f5e3d +Subproject commit 4b76f9ea35eaa116a57fd732b1c4954b6f4d0316 diff --git a/files.cmake b/files.cmake index b111fb7d92..38087f28b8 100644 --- a/files.cmake +++ b/files.cmake @@ -1483,6 +1483,7 @@ set(DUSK_FILES src/dusk/mods/loader/prepatch.cpp src/dusk/mods/loader/prepatch.hpp src/dusk/mods/item.hpp + src/dusk/mods/item_actor.cpp src/dusk/mods/item_checks.cpp src/dusk/mods/item_gives.cpp src/dusk/mods/log_buffer.cpp @@ -1498,6 +1499,7 @@ set(DUSK_FILES src/dusk/mods/svc/flow.cpp src/dusk/mods/svc/hook.cpp src/dusk/mods/svc/host.cpp + src/dusk/mods/svc/http.cpp src/dusk/mods/svc/item.cpp src/dusk/mods/svc/item.hpp src/dusk/mods/svc/log.cpp diff --git a/include/Z2AudioLib/Z2SceneMgr.h b/include/Z2AudioLib/Z2SceneMgr.h index 1b3ef2cc0b..27b43d71f4 100644 --- a/include/Z2AudioLib/Z2SceneMgr.h +++ b/include/Z2AudioLib/Z2SceneMgr.h @@ -47,7 +47,7 @@ public: s32 getBgmLoadStatus(u32 wave) { return getWaveLoadStatus(wave, 1); } u8 getDemoSeWaveNum() { return loadedDemoWave; } -private: +// private: /* 0x00 */ JAISoundID BGM_ID; /* 0x04 */ int sceneNum; /* 0x08 */ int timer; diff --git a/include/d/actor/d_a_door_shutter.h b/include/d/actor/d_a_door_shutter.h index a8e99f1295..34ea7f7fc9 100644 --- a/include/d/actor/d_a_door_shutter.h +++ b/include/d/actor/d_a_door_shutter.h @@ -123,7 +123,7 @@ public: bool checkFlag(u16 flag) { return field_0x68e & flag; } void setAction(u8 action) { mAction = action; } -private: +// private: /* 0x56C */ request_of_phase_process_class mPhase1; /* 0x574 */ request_of_phase_process_class mPhase2; /* 0x57C */ J3DModel* mModel1; diff --git a/include/d/actor/d_a_npc_fairy.h b/include/d/actor/d_a_npc_fairy.h index efa9d760c1..da9977ed37 100644 --- a/include/d/actor/d_a_npc_fairy.h +++ b/include/d/actor/d_a_npc_fairy.h @@ -296,7 +296,7 @@ public: static DUSK_GAME_DATA char DUSK_CONST* DUSK_CONST mCutNameList[18]; static DUSK_GAME_DATA cutFunc DUSK_CONST mCutList[18]; -private: +// private: /* 0x0E40 */ NPC_FAIRY_HIO_CLASS* mHIO; /* 0x0E44 */ dCcD_Cyl mCyl; /* 0x0F80 */ u8 mType; diff --git a/include/d/actor/d_a_npc_ykm.h b/include/d/actor/d_a_npc_ykm.h index d486d6fe6a..5ad9e7210b 100644 --- a/include/d/actor/d_a_npc_ykm.h +++ b/include/d/actor/d_a_npc_ykm.h @@ -287,7 +287,7 @@ public: static DUSK_GAME_DATA char DUSK_CONST* DUSK_CONST mCutNameList[10]; static DUSK_GAME_DATA cutFunc DUSK_CONST mCutList[10]; -private: +// private: /* 0x0E40 */ mDoExt_McaMorfSO* mFishModelMorf; /* 0x0E44 */ mDoExt_McaMorfSO* mLeafModelMorf; /* 0x0E48 */ NPC_YKM_HIO_CLASS* mpHIO; diff --git a/include/d/actor/d_a_npc_zrc.h b/include/d/actor/d_a_npc_zrc.h index f4aeee6ac9..6f6a00061b 100644 --- a/include/d/actor/d_a_npc_zrc.h +++ b/include/d/actor/d_a_npc_zrc.h @@ -96,7 +96,7 @@ public: static DUSK_GAME_DATA char DUSK_CONST* DUSK_CONST mEvtCutNameList[2]; static DUSK_GAME_DATA EventFn DUSK_CONST mEvtCutList[2]; -private: +// private: /* 0xB48 */ Z2Creature mCreatureSound; /* 0xBD8 */ daNpcF_MatAnm_c* mpMatAnm; /* 0xBDC */ daNpcF_Lookat_c mLookat; diff --git a/include/d/actor/d_a_npc_zrz.h b/include/d/actor/d_a_npc_zrz.h index 76c782b7d3..9e03215aa4 100644 --- a/include/d/actor/d_a_npc_zrz.h +++ b/include/d/actor/d_a_npc_zrz.h @@ -114,7 +114,7 @@ public: void himoCalc(); void adjustShapeAngle() {} -private: +// private: /* 0x0B48 */ Z2Creature mCreatureSound; /* 0x0BD8 */ daNpcF_MatAnm_c* mpMatAnm; /* 0x0BDC */ mDoExt_invisibleModel mInvisibleModel; diff --git a/include/d/actor/d_a_obj_bosswarp.h b/include/d/actor/d_a_obj_bosswarp.h index 9b62f1a0f6..71b5b2b58f 100644 --- a/include/d/actor/d_a_obj_bosswarp.h +++ b/include/d/actor/d_a_obj_bosswarp.h @@ -60,7 +60,7 @@ public: bool isFirst() { return fopAcM_GetParamBit(this, 0x1b, 1); } void setAction(u8 action) { mAction = action; } -private: +// private: /* 0x568 */ request_of_phase_process_class mPhaseReq; /* 0x570 */ J3DModel* mpModel; /* 0x574 */ mDoExt_btkAnm* mpBtkAnm[2]; diff --git a/include/d/actor/d_a_obj_life_container.h b/include/d/actor/d_a_obj_life_container.h index d832c63843..d4dc5bb334 100644 --- a/include/d/actor/d_a_obj_life_container.h +++ b/include/d/actor/d_a_obj_life_container.h @@ -64,7 +64,7 @@ public: current.pos = new_pos; } -private: +// private: /* 0x92C */ fpc_ProcID mItemId; /* 0x930 */ int mCounter; /* 0x934 */ u8 mStatus; diff --git a/include/d/actor/d_a_obj_master_sword.h b/include/d/actor/d_a_obj_master_sword.h index a971aa335c..fd41a8d079 100644 --- a/include/d/actor/d_a_obj_master_sword.h +++ b/include/d/actor/d_a_obj_master_sword.h @@ -51,7 +51,7 @@ public: static DUSK_GAME_DATA daObjMasterSword_Attr_c const mAttr; static DUSK_GAME_DATA actionFunc ActionTable[]; -private: +// private: /* 0x568 */ J3DModel* mpModel; /* 0x56C */ request_of_phase_process_class mPhase; /* 0x574 */ mDoExt_btkAnm mBtk; diff --git a/include/d/actor/d_a_tbox2.h b/include/d/actor/d_a_tbox2.h index 9b06e685a3..5e3989db57 100644 --- a/include/d/actor/d_a_tbox2.h +++ b/include/d/actor/d_a_tbox2.h @@ -67,7 +67,7 @@ public: u8 getModelType() { return fopAcM_GetParamBit(this, 8, 4); } u8 getItemNo() { return fopAcM_GetParamBit(this, 0, 8); } -private: +// private: /* 0x718 */ u8 mReturnRupee; /* 0x71C */ request_of_phase_process_class mPhase; /* 0x724 */ J3DModel* mpModel; diff --git a/include/d/d_stage.h b/include/d/d_stage.h index 487488d7c6..f323726f6e 100644 --- a/include/d/d_stage.h +++ b/include/d/d_stage.h @@ -1291,6 +1291,7 @@ public: } void set(const char*, s8, s16, s8, s8, u8); void offEnable() { enabled = 0; } + void onEnable() { enabled = 1; } BOOL isEnable() const { return enabled; } s8 getWipe() const { return wipe; } u8 getWipeSpeed() const { return wipe_speed; } diff --git a/libs/JSystem/include/JSystem/JKernel/JKRHeap.h b/libs/JSystem/include/JSystem/JKernel/JKRHeap.h index ace28de6e3..e23dca3c02 100644 --- a/libs/JSystem/include/JSystem/JKernel/JKRHeap.h +++ b/libs/JSystem/include/JSystem/JKernel/JKRHeap.h @@ -7,6 +7,7 @@ #include #include #include +#include class JKRHeap; typedef void (*JKRErrorHandler)(void*, u32, int); diff --git a/mods/basic_cosmetics_mod/src/hooks.cpp b/mods/basic_cosmetics_mod/src/hooks.cpp index e90e76d8b3..2c878f7632 100644 --- a/mods/basic_cosmetics_mod/src/hooks.cpp +++ b/mods/basic_cosmetics_mod/src/hooks.cpp @@ -18,6 +18,7 @@ #include "d/d_kankyo.h" #include "d/d_kantera_icon_meter.h" #include "d/d_menu_collect.h" +#include "d/d_menu_dmap.h" #include "d/d_menu_fishing.h" #include "d/d_menu_fmap2D.h" #include "d/d_menu_insect.h" @@ -345,7 +346,7 @@ void menu_skill_screen_set_do_icon_post(ModContext*, void* args, void*, void*) { recolor_ui_button(get_cvars().bButtonColor, MULTI_CHAR('b_btn'), screen); } -// A, B, and Z buttons on the map screen +// A, B, and Z buttons on the field map screen DEFINE_HOOK(&dMenu_Fmap_c::_create, MenuFMapCreate); void menu_fmap_create_post(ModContext*, void* args, void*, void*) { auto menuFMap = mods::arg(args, 0); @@ -356,6 +357,16 @@ void menu_fmap_create_post(ModContext*, void* args, void*, void*) { recolor_ui_button(get_cvars().zButtonColor, MULTI_CHAR('zbtn'), screen); } +// A and B buttons on the dungeon map screen +DEFINE_HOOK_SYMBOL("dMenu_DmapBg_c::buttonIconScreenInit", void(dMenu_DmapBg_c*), MenuDMapButtonIconScreenInit); +void menu_dmap_button_icon_screen_init_post(ModContext*, void* args, void*, void*) { + auto menuDMap = mods::arg(args, 0); + auto screen = menuDMap->mButtonScreen; + + recolor_ui_button(get_cvars().aButtonColor, MULTI_CHAR('a_btn'), screen); + recolor_ui_button(get_cvars().bButtonColor, MULTI_CHAR('b_btn'), screen); +} + // A button on the howling screen DEFINE_HOOK(&dMsgObject_c::talkStartInit, MsgObjectTalkStartInit); void msg_object_talk_start_init_post(ModContext*, void* args, void*, void*) { @@ -685,6 +696,8 @@ ModResult add_all_hooks() { ADD_POST_HOOK(OutFontCreatePane, out_font_create_pane_post, COutFont_c::createPane) ADD_POST_HOOK(OutFontSetDrawFont, out_font_set_draw_font_post, COutFontSet_c::drawFont) ADD_POST_HOOK(MenuFMapCreate, menu_fmap_create_post, dMenu_Fmap_c::_create) + ADD_POST_HOOK(MenuDMapButtonIconScreenInit, menu_dmap_button_icon_screen_init_post, + dMenu_DmapBg_c::buttonIconScreenInit) ADD_POST_HOOK( MsgObjectTalkStartInit, msg_object_talk_start_init_post, dMsgObject_c::talkStartInit) ADD_POST_HOOK(MeterHakushaCreate, meter_hakusha_create_post, dMeterHakusha_c::_create) @@ -724,6 +737,7 @@ ModResult remove_all_hooks() { UNINSTALL_HOOK(OutFontCreatePane) UNINSTALL_HOOK(OutFontSetDrawFont) UNINSTALL_HOOK(MenuFMapCreate) + UNINSTALL_HOOK(MenuDMapButtonIconScreenInit) UNINSTALL_HOOK(MsgObjectTalkStartInit) UNINSTALL_HOOK(MeterHakushaCreate) UNINSTALL_HOOK(ItemBaseCreateItemHeap) diff --git a/mods/randomizer b/mods/randomizer new file mode 160000 index 0000000000..61ba8c4058 --- /dev/null +++ b/mods/randomizer @@ -0,0 +1 @@ +Subproject commit 61ba8c40589884955929f467c1eda74d1c88a444 diff --git a/platforms/android/README.md b/platforms/android/README.md index 6ebcac23cd..c4f8a688df 100644 --- a/platforms/android/README.md +++ b/platforms/android/README.md @@ -4,7 +4,7 @@ This directory contains Dusklight's Android shell built on top of Borealis. ## Prerequisites -- Android SDK installed (`ANDROID_HOME`) +- Android SDK with Platform 37 installed (`ANDROID_HOME`) - Android NDK version used by CMake presets (`ANDROID_NDK_VERSION`) - JDK 17+ diff --git a/platforms/android/build.gradle b/platforms/android/build.gradle index eba031aa1b..4b1f3fb3f2 100644 --- a/platforms/android/build.gradle +++ b/platforms/android/build.gradle @@ -1,3 +1,3 @@ plugins { - id 'com.android.application' version '8.13.2' apply false + id 'com.android.application' version '9.1.1' apply false } diff --git a/platforms/android/gradle/wrapper/gradle-wrapper.jar b/platforms/android/gradle/wrapper/gradle-wrapper.jar index 2b338a935b..61285a659d 100644 Binary files a/platforms/android/gradle/wrapper/gradle-wrapper.jar and b/platforms/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/platforms/android/gradle/wrapper/gradle-wrapper.properties b/platforms/android/gradle/wrapper/gradle-wrapper.properties index ec50cfcb6e..37f78a6af8 100644 --- a/platforms/android/gradle/wrapper/gradle-wrapper.properties +++ b/platforms/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Thu Nov 11 18:20:34 PST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/platforms/android/gradlew b/platforms/android/gradlew index 3427607f42..adff685a03 100755 --- a/platforms/android/gradlew +++ b/platforms/android/gradlew @@ -1,74 +1,128 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -77,84 +131,118 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|grep -E -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|grep -E -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/platforms/android/gradlew.bat b/platforms/android/gradlew.bat index 8a0b282aa6..c4bdd3ab8e 100644 --- a/platforms/android/gradlew.bat +++ b/platforms/android/gradlew.bat @@ -1,4 +1,22 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -8,26 +26,30 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,54 +57,35 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/res/rml/mods.rcss b/res/rml/mods.rcss index 6042e35c0f..34e86f485b 100644 --- a/res/rml/mods.rcss +++ b/res/rml/mods.rcss @@ -115,6 +115,14 @@ mod-entry .mod-entry-status.failed { color: #cc4444; } +mod-entry .mod-entry-network { + margin-left: 6dp; + padding: 1dp 5dp; + border-radius: 5dp; + background-color: rgba(67, 151, 219, 20%); + color: #6fb7ef; +} + mod-entry .mod-entry-desc { font-size: 14dp; line-height: 1.3; @@ -216,4 +224,9 @@ window.mods .mod-description { .mod-info-label.failed { color: #cc4444; opacity: 1; -} \ No newline at end of file +} + +.status-badge.network { + color: #6fb7ef; + opacity: 1; +} diff --git a/sdk/include/mods/items.h b/sdk/include/mods/items.h index b79563026c..ceee2a0efc 100644 --- a/sdk/include/mods/items.h +++ b/sdk/include/mods/items.h @@ -10,7 +10,7 @@ #define ITEM_CHECK_FREESTANDING_PREFIX "freestanding:" /* : */ #define ITEM_CHECK_GOLDEN_WOLF_PREFIX "golden_wolf:" /* */ #define ITEM_CHECK_POE_PREFIX "poe:" /* : */ -#define ITEM_CHECK_SHOP_PREFIX "shop:" /* : */ +#define ITEM_CHECK_SHOP_PREFIX "shop:" /* :: */ #define ITEM_CHECK_SKY_PREFIX "sky:" /* : */ #define ITEM_CHECK_DUNGEON_REWARD_PREFIX "dungeon_reward:" /* */ @@ -21,6 +21,8 @@ #define ITEM_CHECK_BULBLIN_KEY "bulblin_key:D_MN09" #define ITEM_CHECK_CORAL_EARRING "coral_earring" #define ITEM_CHECK_CORO_BOTTLE "coro_bottle" +#define ITEM_CHECK_CORO_GATE_KEY "coro_gate_key" +#define ITEM_CHECK_CORO_LANTERN "coro_lantern" #define ITEM_CHECK_DUNGEON_MAP_SNOWPEAK "dungeon_map:D_MN11" #define ITEM_CHECK_FAIRY_REWARD "fairy_reward:D_SB01" #define ITEM_CHECK_FISHING_BOTTLE "fishing_bottle" diff --git a/sdk/include/mods/meta.hpp b/sdk/include/mods/meta.hpp index 6b1de96ad8..ef85d827c2 100644 --- a/sdk/include/mods/meta.hpp +++ b/sdk/include/mods/meta.hpp @@ -46,8 +46,8 @@ extern "C" const unsigned char mod_meta_bounds_end[] __asm("section$end$__DATA$_ #define MOD_META_BOUNDS_BEGIN (mod_meta_bounds_begin) #define MOD_META_BOUNDS_END (mod_meta_bounds_end) #else -extern "C" const unsigned char __start_modmeta[]; -extern "C" const unsigned char __stop_modmeta[]; +extern "C" __attribute__((visibility("hidden"))) const unsigned char __start_modmeta[]; +extern "C" __attribute__((visibility("hidden"))) const unsigned char __stop_modmeta[]; #define MOD_META_BOUNDS_DEFN #define MOD_META_BOUNDS_BEGIN (__start_modmeta) #define MOD_META_BOUNDS_END (__stop_modmeta) diff --git a/sdk/include/mods/svc/http.h b/sdk/include/mods/svc/http.h new file mode 100644 index 0000000000..fd4d9a98db --- /dev/null +++ b/sdk/include/mods/svc/http.h @@ -0,0 +1,98 @@ +#pragma once + +#include + +#ifdef __cplusplus +#include +#endif + +#define HTTP_SERVICE_ID "dev.twilitrealm.dusklight.http" +#define HTTP_SERVICE_MAJOR 1u +#define HTTP_SERVICE_MINOR 0u + +/* Handle for an in-flight request. 0 is never a valid handle. */ +typedef uint64_t HttpRequestHandle; + +typedef enum HttpMethod { + HTTP_METHOD_GET = 0, + HTTP_METHOD_POST = 1, + HTTP_METHOD_HEAD = 2, +} HttpMethod; + +/* Transport-level outcome. HTTP status errors are reported through status_code. */ +typedef enum HttpError { + HTTP_ERROR_NONE = 0, + HTTP_ERROR_INVALID_URL = 1, + HTTP_ERROR_UNSUPPORTED_SCHEME = 2, + HTTP_ERROR_TIMEOUT = 3, + HTTP_ERROR_TOO_LARGE = 4, + HTTP_ERROR_CANCELED = 5, + HTTP_ERROR_IO = 6, + HTTP_ERROR_NETWORK = 7, +} HttpError; + +typedef struct HttpHeader { + const char* name; + const char* value; +} HttpHeader; + +typedef struct HttpRequestDesc { + uint32_t struct_size; + HttpMethod method; + const char* url; + const HttpHeader* headers; + uint32_t header_count; + /* Request body; POST only. */ + const void* body; + size_t body_size; + /* Absolute destination under this mod's data_dir or mod_dir, or NULL for an in-memory body. + * GET and POST only. */ + const char* download_path; + uint32_t connect_timeout_ms; /* 0 = 10 seconds */ + uint32_t idle_timeout_ms; /* 0 = 10 seconds without network progress */ + uint32_t total_timeout_ms; /* 0 = no total timeout */ + size_t max_body_bytes; /* 0 = 1 MiB; ignored for downloads */ +} HttpRequestDesc; + +#define HTTP_REQUEST_DESC_INIT \ + {sizeof(HttpRequestDesc), HTTP_METHOD_GET, NULL, NULL, 0u, NULL, 0u, NULL, 0u, 0u, 0u, 0u} + +/* Snapshot valid only for the duration of the completion callback. */ +typedef struct HttpResult { + uint32_t struct_size; + HttpError error; + const char* error_message; + int32_t status_code; + const HttpHeader* headers; + uint32_t header_count; + const void* body; + size_t body_size; + /* Published absolute destination, or NULL unless a download succeeded. */ + const char* download_path; +} HttpResult; + +/* Runs on the game thread exactly once, unless the calling mod begins deactivation first. */ +typedef void (*HttpCompleteFn)( + ModContext* ctx, HttpRequestHandle request, const HttpResult* result, void* user_data); + +typedef struct HttpProgress { + uint32_t struct_size; + uint64_t completed_bytes; + uint64_t total_bytes; + bool total_known; +} HttpProgress; + +#define HTTP_PROGRESS_INIT {sizeof(HttpProgress), 0u, 0u, false} + +typedef struct HttpService { + ServiceHeader header; + + /* Starts an asynchronous HTTPS request. */ + ModResult (*request)(ModContext* ctx, const HttpRequestDesc* desc, HttpCompleteFn fn, + void* user_data, HttpRequestHandle* out_handle); + ModResult (*progress)(ModContext* ctx, HttpRequestHandle request, HttpProgress* out_progress); + /* Requests cancellation. The completion callback still runs if the mod remains active. */ + ModResult (*cancel)(ModContext* ctx, HttpRequestHandle request); +} HttpService; + +MOD_DECLARE_SERVICE(HttpService, svc_http, HTTP_SERVICE_ID, HTTP_SERVICE_MAJOR, HTTP_SERVICE_MINOR); diff --git a/sdk/include/mods/svc/http.hpp b/sdk/include/mods/svc/http.hpp new file mode 100644 index 0000000000..906bf3d0d2 --- /dev/null +++ b/sdk/include/mods/svc/http.hpp @@ -0,0 +1,204 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace mods::http { + +struct Header { + std::string name; + std::string value; +}; + +struct Request { + HttpMethod method = HTTP_METHOD_GET; + std::string url; + std::vector
headers; + std::string body; + std::string downloadPath; + uint32_t connectTimeoutMs = 0; + uint32_t idleTimeoutMs = 0; + uint32_t totalTimeoutMs = 0; + size_t maxBodyBytes = 0; +}; + +struct Response { + HttpError error = HTTP_ERROR_NETWORK; + std::string errorMessage; + int statusCode = 0; + std::vector
headers; + std::vector body; + std::string downloadPath; + + bool ok() const { return error == HTTP_ERROR_NONE && statusCode >= 200 && statusCode < 300; } + + const std::string* header(std::string_view name) const { + const auto equal = [](std::string_view left, std::string_view right) { + return left.size() == right.size() && + std::equal(left.begin(), left.end(), right.begin(), [](char a, char b) { + return std::tolower(static_cast(a)) == + std::tolower(static_cast(b)); + }); + }; + const auto iter = std::find_if(headers.begin(), headers.end(), + [&](const Header& value) { return equal(value.name, name); }); + return iter != headers.end() ? &iter->value : nullptr; + } +}; + +namespace detail { + +struct Completion { + HttpRequestHandle handle = 0; + std::function callback; +}; + +inline std::unordered_map> completions; + +inline void complete(ModContext*, HttpRequestHandle handle, const HttpResult* raw, void* userData) { + const auto iter = completions.find(handle); + if (iter == completions.end() || iter->second.get() != userData) { + return; + } + auto completion = std::move(iter->second); + completions.erase(iter); + + Response response; + if (raw != nullptr) { + response.error = raw->error; + response.errorMessage = raw->error_message != nullptr ? raw->error_message : ""; + response.statusCode = raw->status_code; + response.headers.reserve(raw->header_count); + for (uint32_t i = 0; i < raw->header_count; ++i) { + response.headers.push_back({ + .name = raw->headers[i].name != nullptr ? raw->headers[i].name : "", + .value = raw->headers[i].value != nullptr ? raw->headers[i].value : "", + }); + } + if (raw->body != nullptr && raw->body_size != 0) { + const auto* begin = static_cast(raw->body); + response.body.assign(begin, begin + raw->body_size); + } + response.downloadPath = raw->download_path != nullptr ? raw->download_path : ""; + } + if (completion->callback) { + completion->callback(std::move(response)); + } +} + +} // namespace detail + +class Pending { +public: + Pending() = default; + Pending(HttpRequestHandle handle, ModResult result) : mHandle{handle}, mResult{result} {} + ~Pending() { reset(); } + Pending(const Pending&) = delete; + Pending& operator=(const Pending&) = delete; + Pending(Pending&& other) noexcept { *this = std::move(other); } + Pending& operator=(Pending&& other) noexcept { + if (this != &other) { + reset(); + mHandle = std::exchange(other.mHandle, 0); + mResult = other.mResult; + } + return *this; + } + + explicit operator bool() const { + if (mResult != MOD_OK || mHandle == 0 || svc_http == nullptr || + !detail::completions.contains(mHandle)) + { + return false; + } + HttpProgress value = HTTP_PROGRESS_INIT; + return svc_http->progress(mod_ctx, mHandle, &value) == MOD_OK; + } + ModResult result() const { return mResult; } + HttpRequestHandle handle() const { return mHandle; } + + HttpProgress progress() const { + HttpProgress value = HTTP_PROGRESS_INIT; + if (mHandle != 0 && svc_http != nullptr) { + svc_http->progress(mod_ctx, mHandle, &value); + } + return value; + } + + void cancel() { + if (mHandle != 0 && svc_http != nullptr) { + if (svc_http->cancel(mod_ctx, mHandle) != MOD_OK) { + detail::completions.erase(mHandle); + } + } + } + + void detach() { mHandle = 0; } + +private: + void reset() { + cancel(); + mHandle = 0; + } + + HttpRequestHandle mHandle = 0; + ModResult mResult = MOD_UNAVAILABLE; +}; + +inline Pending request(const Request& request, std::function callback) { + if (svc_http == nullptr) { + return {0, MOD_UNAVAILABLE}; + } + if (!callback) { + return {0, MOD_INVALID_ARGUMENT}; + } + + if (request.headers.size() > std::numeric_limits::max()) { + return {0, MOD_INVALID_ARGUMENT}; + } + std::vector headers; + headers.reserve(request.headers.size()); + for (const auto& header : request.headers) { + headers.push_back({ + .name = header.name.c_str(), + .value = header.value.c_str(), + }); + } + HttpRequestDesc desc = HTTP_REQUEST_DESC_INIT; + desc.method = request.method; + desc.url = request.url.c_str(); + desc.headers = headers.empty() ? nullptr : headers.data(); + desc.header_count = static_cast(headers.size()); + desc.body = request.body.empty() ? nullptr : request.body.data(); + desc.body_size = request.body.size(); + desc.download_path = request.downloadPath.empty() ? nullptr : request.downloadPath.c_str(); + desc.connect_timeout_ms = request.connectTimeoutMs; + desc.idle_timeout_ms = request.idleTimeoutMs; + desc.total_timeout_ms = request.totalTimeoutMs; + desc.max_body_bytes = request.maxBodyBytes; + + auto completion = std::make_unique(); + auto* userData = completion.get(); + completion->callback = std::move(callback); + HttpRequestHandle handle = 0; + const auto result = svc_http->request(mod_ctx, &desc, detail::complete, userData, &handle); + if (result != MOD_OK) { + return {0, result}; + } + completion->handle = handle; + detail::completions.emplace(handle, std::move(completion)); + return {handle, result}; +} + +} // namespace mods::http diff --git a/sdk/include/mods/svc/item.h b/sdk/include/mods/svc/item.h index 94fec6fb6c..ff4f31b547 100644 --- a/sdk/include/mods/svc/item.h +++ b/sdk/include/mods/svc/item.h @@ -8,7 +8,7 @@ #define ITEM_SERVICE_ID "dev.twilitrealm.dusklight.item" #define ITEM_SERVICE_MAJOR 2u -#define ITEM_SERVICE_MINOR 1u +#define ITEM_SERVICE_MINOR 3u /* 0 is never a valid handle. */ typedef uint64_t ItemCheckHandle; @@ -32,11 +32,13 @@ typedef struct ItemCheckInfo { uint8_t vanilla_item; uint8_t current_item; uint8_t current_display_item; + bool was_resolved; } ItemCheckInfo; typedef struct ItemCheckResolution { uint8_t item; uint8_t display_item; /* leave unset (0xFF/NONE) to use the item */ + bool was_resolved; } ItemCheckResolution; /* Return true and write out_result to replace the result, or false to leave it unchanged. */ @@ -97,6 +99,13 @@ typedef struct ItemService { ModContext* ctx, ItemGiveObserveFn fn, void* user_data, ItemGiveHandle* out_handle); ModResult (*unobserve_gives)(ModContext* ctx, ItemGiveHandle handle); + + /* Minor version 2 */ + + /* Resolve a live preview (item + display item) without granting an item or notifying give + * observers. */ + ModResult (*resolve_check_full)(ModContext* ctx, const char* name, uint8_t vanilla_item, + ItemCheckResolution* out_resolution); } ItemService; MOD_DECLARE_SERVICE(ItemService, svc_item, ITEM_SERVICE_ID, ITEM_SERVICE_MAJOR, ITEM_SERVICE_MINOR); diff --git a/src/d/actor/d_a_demo_item.cpp b/src/d/actor/d_a_demo_item.cpp index 465532a5f0..0c092cf59b 100644 --- a/src/d/actor/d_a_demo_item.cpp +++ b/src/d/actor/d_a_demo_item.cpp @@ -462,7 +462,7 @@ int daDitem_c::create() { m_itemNo = daDitem_prm::getNo(this); #if TARGET_PC - const auto [item, displayItem] = dusk::mods::item_check_resolve(mItemGiveTag, m_itemNo, this); + const auto [item, displayItem, _] = dusk::mods::item_check_resolve(mItemGiveTag, m_itemNo, this); m_itemNo = item; setDisplayItemNo(displayItem); const char* arc_name = dItem_data::getArcName(displayItem); @@ -550,7 +550,7 @@ static int daDitem_Execute(daDitem_c* i_this) { } int daDitem_c::draw() { - switch (m_itemNo) { + switch (DUSK_IF_ELSE(getDisplayItemNo(), m_itemNo)) { case dItemNo_WOOD_STICK_e: draw_WOOD_STICK(); break; diff --git a/src/d/actor/d_a_e_po.cpp b/src/d/actor/d_a_e_po.cpp index a7a7be6dd1..112ad2d56f 100644 --- a/src/d/actor/d_a_e_po.cpp +++ b/src/d/actor/d_a_e_po.cpp @@ -7,6 +7,9 @@ #include "d/actor/d_a_e_po.h" #include "d/actor/d_a_obj_poFire.h" +#if TARGET_PC +#include "d/actor/d_a_alink.h" +#endif #include "d/d_cc_d.h" #include "d/d_cc_uty.h" #include "f_op/f_op_actor_enemy.h" diff --git a/src/d/actor/d_a_npc_gra.cpp b/src/d/actor/d_a_npc_gra.cpp index e5e0d6eed0..d57ce3ab2b 100644 --- a/src/d/actor/d_a_npc_gra.cpp +++ b/src/d/actor/d_a_npc_gra.cpp @@ -4022,16 +4022,53 @@ BOOL daNpc_grA_c::talk(void*) { if (r26 && talkProc(NULL, TRUE, NULL)) { if (mFlow.getEventId(&sp8) == 1) { #if TARGET_PC + const u8 originalItem = sp8; u32 itemGiveTag = 0; - if (sp8 == dItemNo_BOMB_IN_BAG_e) { + bool isItemCheck = false; + if (originalItem == dItemNo_BOMB_IN_BAG_e) { const auto itemCheck = - dusk::mods::item_check_commit("goron_reward:F_SP113", sp8, this); + dusk::mods::item_check_commit("goron_reward:F_SP113", originalItem, this); sp8 = itemCheck.itemNo; itemGiveTag = itemCheck.tag; + isItemCheck = true; + } else { + const char* stage = dComIfGp_getStartStageName(); + const bool isAdultGoronShop = (strcmp(stage, "R_SP160") == 0 && originalItem == dItemNo_HYLIA_SHIELD_e) || + (strcmp(stage, "F_SP116") == 0 && originalItem == dItemNo_ARROW_30_e); + if (isAdultGoronShop) { + const auto itemCheck = dusk::mods::item_check_commit( + dusk::mods::item_give_tag_shop(originalItem), originalItem, this); + sp8 = itemCheck.itemNo; + itemGiveTag = itemCheck.tag; + isItemCheck = true; + } } -#endif + + if (isItemCheck && sp8 == dItemNo_NONE_e) { + dusk::mods::item_check_complete({itemGiveTag, dItemNo_NONE_e}, this); + r29 = 1; + if (mType == 0xb) { + field_0x1691 = 1; + } + } else { + field_0x1480 = fopAcM_createItemForPresentDemo( + ¤t.pos, sp8, 0, -1, -1, NULL, NULL, itemGiveTag); + if (field_0x1480 != fpcM_ERROR_PROCESS_ID_e) { + s16 r25 = + dComIfGp_getEventManager().getEventIdx(this, "DEFAULT_GETITEM", 0xff); + dComIfGp_getEvent()->reset(this); + fopAcM_orderChangeEventId(this, r25, 1, -1); + field_0x9ec = 1; + r29 = 1; + mOrderNewEvt = 1; + if (mType == 0xb) { + field_0x1691 = 1; + } + } + } +#else field_0x1480 = fopAcM_createItemForPresentDemo(¤t.pos, sp8, 0, -1, -1, NULL, - NULL IF_DUSK_ARG(itemGiveTag)); + NULL); if (field_0x1480 != fpcM_ERROR_PROCESS_ID_e) { s16 r25 = dComIfGp_getEventManager().getEventIdx(this, "DEFAULT_GETITEM", 0xff); dComIfGp_getEvent()->reset(this); @@ -4043,6 +4080,7 @@ BOOL daNpc_grA_c::talk(void*) { field_0x1691 = 1; } } +#endif } else { if (mType == 0xa && field_0x1486 == 0 && daNpcF_chkEvtBit(0x187)) { dComIfGp_getEvent()->reset(this); diff --git a/src/d/actor/d_a_npc_grc.cpp b/src/d/actor/d_a_npc_grc.cpp index 2435f13c77..47ea7490c0 100644 --- a/src/d/actor/d_a_npc_grc.cpp +++ b/src/d/actor/d_a_npc_grc.cpp @@ -8,6 +8,9 @@ #include "d/actor/d_a_npc_grc.h" #include "d/actor/d_a_npc.h" #include "Z2AudioLib/Z2Instances.h" +#if TARGET_PC +#include "mods/items.h" +#endif #include enum grC_RES_File_ID { @@ -1476,8 +1479,27 @@ BOOL daNpc_grC_c::talk(void* param_1) { rv = TRUE; if (mFlow.getEventId(&i_itemNo) == 1) { - mItemID = fopAcM_createItemForPresentDemo(¤t.pos, i_itemNo, 0, -1, -1, NULL, NULL); +#if TARGET_PC + const bool isCastleTownShop = + strcmp(dComIfGp_getStartStageName(), "R_SP160") == 0 && + (i_itemNo == dItemNo_RED_BOTTLE_e || i_itemNo == dItemNo_OIL_BOTTLE_e); + u32 itemGiveTag = 0; + if (isCastleTownShop) { + const auto itemCheck = dusk::mods::item_check_commit( + dusk::mods::item_give_tag_shop(i_itemNo), i_itemNo, this); + i_itemNo = itemCheck.itemNo; + itemGiveTag = itemCheck.tag; + } + if (isCastleTownShop && i_itemNo == dItemNo_NONE_e) { + dusk::mods::item_check_complete({itemGiveTag, dItemNo_NONE_e}, this); + } else { + mItemID = fopAcM_createItemForPresentDemo( + ¤t.pos, i_itemNo, 0, -1, -1, NULL, NULL, itemGiveTag); + } +#else + mItemID = fopAcM_createItemForPresentDemo(¤t.pos, i_itemNo, 0, -1, -1, NULL, NULL); +#endif if (mItemID != fpcM_ERROR_PROCESS_ID_e) { s16 i_eventID = dComIfGp_getEventManager().getEventIdx(this, "DEFAULT_GETITEM", 0xFF); dComIfGp_getEvent()->reset(this); diff --git a/src/d/actor/d_a_npc_kkri.cpp b/src/d/actor/d_a_npc_kkri.cpp index 755257bff7..97e375e4ec 100644 --- a/src/d/actor/d_a_npc_kkri.cpp +++ b/src/d/actor/d_a_npc_kkri.cpp @@ -7,6 +7,9 @@ #include "d/actor/d_a_npc_kkri.h" #include "d/actor/d_a_e_ym.h" +#if TARGET_PC +#include "mods/items.h" +#endif #include static DUSK_CONSTEXPR int l_bmdData[2][2] = { @@ -1183,16 +1186,39 @@ int daNpc_Kkri_c::talk(void*) { if (mItemPartnerId == fpcM_ERROR_PROCESS_ID_e) { #if TARGET_PC u32 itemGiveTag = 0; - if (item_no == dItemNo_OIL_BOTTLE3_e) { - const auto itemCheck = - dusk::mods::item_check_commit("coro_bottle", item_no, this); + const char* itemCheckName = nullptr; + switch (item_no) { + case dItemNo_OIL_BOTTLE3_e: + itemCheckName = ITEM_CHECK_CORO_BOTTLE; + break; + case dItemNo_KANTERA_e: + itemCheckName = ITEM_CHECK_CORO_LANTERN; + break; + case dItemNo_KEY_OF_FILONE_e: + itemCheckName = ITEM_CHECK_CORO_GATE_KEY; + break; + } + + if (itemCheckName != nullptr) { + const auto itemCheck = dusk::mods::item_check_commit( + itemCheckName, item_no, this); item_no = itemCheck.itemNo; itemGiveTag = itemCheck.tag; } + + if (item_no == dItemNo_NONE_e && itemCheckName != nullptr) { + dusk::mods::item_check_complete({itemGiveTag, dItemNo_NONE_e}, this); + field_0xfd5 = 1; + mEvtNo = 1; + evtChange(); + } else { + mItemPartnerId = fopAcM_createItemForPresentDemo( + ¤t.pos, item_no, 0, -1, -1, NULL, NULL, itemGiveTag); + } +#else + mItemPartnerId = fopAcM_createItemForPresentDemo( + ¤t.pos, item_no, 0, -1, -1, NULL, NULL); #endif - mItemPartnerId = fopAcM_createItemForPresentDemo(¤t.pos, item_no, - 0, -1, -1, NULL, - NULL IF_DUSK_ARG(itemGiveTag)); } if (fopAcM_IsExecuting(mItemPartnerId)) { diff --git a/src/d/actor/d_a_obj_item.cpp b/src/d/actor/d_a_obj_item.cpp index fba0ad7d91..e06eb37e50 100644 --- a/src/d/actor/d_a_obj_item.cpp +++ b/src/d/actor/d_a_obj_item.cpp @@ -268,7 +268,7 @@ int daItem_c::_daItem_create() { const u32 params = fopAcM_GetParam(this); mOriginalItemNo = params & 0xFF; mItemGiveTag = dusk::mods::item_give_tag_freestanding(daItem_prm::getItemBitNo(this)); - const auto [item, displayItem] = + const auto [item, displayItem, _] = dusk::mods::item_check_resolve(mItemGiveTag, mOriginalItemNo, this); mItemOverridden = item != mOriginalItemNo; setDisplayItemNo(displayItem); @@ -935,10 +935,6 @@ void daItem_c::itemGet() { mItemOverridden = m_itemNo != mOriginalItemNo; #endif switch (m_itemNo) { -#if TARGET_PC - case dItemNo_UTAWA_HEART_e: - case dItemNo_KAKERA_HEART_e: -#endif case dItemNo_HEART_e: mDoAud_seStart(Z2SE_HEART_PIECE_GET, NULL, 0, 0); execItemGet(m_itemNo IF_DUSK_ARG(mItemGiveTag) IF_DUSK_ARG(this)); @@ -980,9 +976,6 @@ void daItem_c::itemGet() { case dItemNo_PACHINKO_SHOT_e: mDoAud_seStart(Z2SE_CONSUMP_ITEM_GET, NULL, 0, 0); execItemGet(m_itemNo IF_DUSK_ARG(mItemGiveTag) IF_DUSK_ARG(this)); -#if TARGET_PC - break; -#endif default: #if TARGET_PC if (mItemOverridden) { diff --git a/src/d/actor/d_a_obj_life_container.cpp b/src/d/actor/d_a_obj_life_container.cpp index b2eb30167a..85553cda28 100644 --- a/src/d/actor/d_a_obj_life_container.cpp +++ b/src/d/actor/d_a_obj_life_container.cpp @@ -99,6 +99,15 @@ int daObjLife_c::Create() { mRotateSpeed = 7000; #if TARGET_PC + // Restore speeds that were skipped if created from a boss with create instead of fastCreate + auto bossItemSpeeds = dusk::mods::get_boss_item_actor_speeds(); + if (bossItemSpeeds.f != 0.f || bossItemSpeeds.y != 0.f) { + mOverrideHover = false; + speedF = bossItemSpeeds.f; + speed.y = bossItemSpeeds.y; + dusk::mods::set_boss_item_actor_speeds(0.f, 0.f); + } + if (mOverrideHover) { fopAcM_SetGravity(this, 0.0f); mRotateSpeed = 550; @@ -153,20 +162,20 @@ int daObjLife_c::create() { if (mItemGiveOriginalNo == dItemNo_NONE_e) { mOriginalItemNo = parameterItemNo; mItemGiveTag = dusk::mods::item_give_tag_freestanding(getSaveBitNo()); - const auto [item, displayItem] = + const auto [item, displayItem, was_resolved] = dusk::mods::item_check_resolve(mItemGiveTag, mOriginalItemNo, this); setDisplayItemNo(displayItem); - mItemOverridden = item != mOriginalItemNo; + mItemOverridden = was_resolved; if (mItemOverridden) { fopAcM_SetParam(this, (params & 0xFFFFFF00) | item); } } else if (mGoldenWolfItem) { mOriginalItemNo = mItemGiveOriginalNo; mItemGiveTag = dusk::mods::item_give_tag_golden_wolf(static_cast(field_0x938)); - const auto [item, displayItem] = + const auto [item, displayItem, was_resolved] = dusk::mods::item_check_resolve(mItemGiveTag, mOriginalItemNo, this); setDisplayItemNo(displayItem); - mItemOverridden = item != mOriginalItemNo; + mItemOverridden = was_resolved; if (item != parameterItemNo) { fopAcM_SetParam(this, (params & 0xFFFFFF00) | item); } diff --git a/src/d/actor/d_a_obj_master_sword.cpp b/src/d/actor/d_a_obj_master_sword.cpp index 36fa786808..a1ef6b1709 100644 --- a/src/d/actor/d_a_obj_master_sword.cpp +++ b/src/d/actor/d_a_obj_master_sword.cpp @@ -151,11 +151,7 @@ void daObjMasterSword_c::create_init() { int daObjMasterSword_c::create() { fopAcM_ct(this, daObjMasterSword_c); -#if TARGET_PC - if (dComIfGs_isEventBit(dSv_event_flag_c::F_0264)) { -#else if (dComIfGs_isEventBit(dSv_event_flag_c::saveBitLabels[getFlagNo()])) { -#endif return cPhs_ERROR_e; } @@ -199,7 +195,7 @@ int daObjMasterSword_c::execute() { #if TARGET_PC const auto masterSword = dusk::mods::item_check_commit( ITEM_CHECK_MASTER_SWORD, dItemNo_MASTER_SWORD_e, this); - if (masterSword.itemNo == dItemNo_MASTER_SWORD_e) { + if (!masterSword.was_resolved) { dComIfGs_onItemFirstBit(dItemNo_MASTER_SWORD_e); dMeter2Info_setSword(dItemNo_MASTER_SWORD_e, false); dComIfGs_setSelectEquipSword(dItemNo_MASTER_SWORD_e); @@ -214,7 +210,7 @@ int daObjMasterSword_c::execute() { const auto shadowCrystal = dusk::mods::item_check_commit( ITEM_CHECK_SHADOW_CRYSTAL, dItemNo_SHADOW_CRYSTAL_e, this); - if (shadowCrystal.itemNo == dItemNo_SHADOW_CRYSTAL_e) { + if (!shadowCrystal.was_resolved) { execItemGet(shadowCrystal.itemNo, shadowCrystal.tag, this); } else if (shadowCrystal.itemNo == dItemNo_NONE_e) { dusk::mods::item_check_complete(shadowCrystal, this); @@ -222,15 +218,14 @@ int daObjMasterSword_c::execute() { dusk::mods::item_check_enqueue(shadowCrystal, dusk::mods::ItemGiveMode::Demo); } - dComIfGs_onEventBit(dSv_event_flag_c::F_0264); #else dComIfGs_onItemFirstBit(dItemNo_MASTER_SWORD_e); dMeter2Info_setSword(dItemNo_MASTER_SWORD_e, false); dComIfGs_setSelectEquipSword(dItemNo_MASTER_SWORD_e); dComIfGp_setItemLifeCount(dComIfGs_getMaxLife(), 0); - dComIfGs_onEventBit(dSv_event_flag_c::saveBitLabels[getFlagNo()]); #endif + dComIfGs_onEventBit(dSv_event_flag_c::saveBitLabels[getFlagNo()]); fopAcM_delete(this); } diff --git a/src/d/actor/d_a_obj_smallkey.cpp b/src/d/actor/d_a_obj_smallkey.cpp index 6914cee5f0..1fd6025ce6 100644 --- a/src/d/actor/d_a_obj_smallkey.cpp +++ b/src/d/actor/d_a_obj_smallkey.cpp @@ -157,7 +157,7 @@ int daKey_c::create() { #if TARGET_PC mItemGiveTag = dusk::mods::item_give_tag_freestanding(getSaveBitNo()); - const auto [item, displayItem] = + const auto [item, displayItem, _] = dusk::mods::item_check_resolve(mItemGiveTag, dItemNo_SMALL_KEY_e, this); m_itemNo = item; if (m_itemNo == dItemNo_NONE_e) { diff --git a/src/d/actor/d_a_shop_item.cpp b/src/d/actor/d_a_shop_item.cpp index a7a159ab1c..edd16b9ecf 100644 --- a/src/d/actor/d_a_shop_item.cpp +++ b/src/d/actor/d_a_shop_item.cpp @@ -106,8 +106,9 @@ const char* daShopItem_c::getShopArcname() { if (m_itemNo != dItemNo_NONE_e && mItemGiveOriginalNo == dItemNo_NONE_e) { mItemGiveOriginalNo = m_itemNo; mItemGiveTag = dusk::mods::item_give_tag_shop(mItemGiveOriginalNo); - const auto [_, displayItem] = + const auto [_, displayItem, was_resolved] = dusk::mods::item_check_resolve(mItemGiveTag, mItemGiveOriginalNo, this); + setDisplayItemNo(displayItem); mItemOverridden = displayItem != mItemGiveOriginalNo; if (mItemOverridden) { mOverrideData = mData[mShopItemID]; diff --git a/src/d/d_item.cpp b/src/d/d_item.cpp index a388ef155c..f89d4f37e8 100644 --- a/src/d/d_item.cpp +++ b/src/d/d_item.cpp @@ -269,7 +269,10 @@ static void (*item_func_ptr[256])() = { item_func_noentry, }; -inline void getItemFunc(u8 i_itemNo) { +#if !TARGET_PC +inline +#endif +void getItemFunc(u8 i_itemNo) { dComIfGs_onItemFirstBit(i_itemNo); item_func_ptr[i_itemNo](); } diff --git a/src/dusk/game_combos.cpp b/src/dusk/game_combos.cpp index 90f4fb0770..a901dba285 100644 --- a/src/dusk/game_combos.cpp +++ b/src/dusk/game_combos.cpp @@ -18,7 +18,7 @@ static daAlink_c* getPlayer() { return (daAlink_c*)dComIfGp_getPlayer(0); } -static void consumeButtons(u32 mask) { +static void consumeButtons(u16 mask) { mDoCPd_c::getCpadInfo(PAD_1).mPressedButtonFlags &= ~mask; mDoCPd_c::getCpadInfo(PAD_1).mButtonFlags &= ~mask; } @@ -107,8 +107,8 @@ void processGameCombos() { getTransientSettings().moveLinkActive = false; } - const u32 held = mDoCPd_c::getHold(PAD_1); - const u32 trig = mDoCPd_c::getTrig(PAD_1); + const u16 held = mDoCPd_c::getHold(PAD_1) & 0xFFFF; + const u16 trig = mDoCPd_c::getTrig(PAD_1) & 0xFFFF; for (const auto& combo : kCombos) { if ((held & combo.holdMask) != combo.holdMask) { diff --git a/src/dusk/game_combos.h b/src/dusk/game_combos.h index ed247fe4e4..5306cb447c 100644 --- a/src/dusk/game_combos.h +++ b/src/dusk/game_combos.h @@ -8,12 +8,12 @@ struct GameCombo { using ConditionFn = bool(*)(); using ActionFn = void(*)(); - u32 holdMask; // all of these must be held (getHold) - u32 trigMask; // at least one must be newly triggered (getTrig); 0 = fires every frame while holdMask is held + u16 holdMask; // all of these must be held (getHold) + u16 trigMask; // at least one must be newly triggered (getTrig); 0 = fires every frame while holdMask is held bool strict; // if true: (held & ~trigMask) must equal holdMask exactly, no extra buttons held ConditionFn condition; // extra game-state guard; nullptr = no extra check ActionFn action; // runs when the combo is fired - u32 consumeMask; // buttons to clear after firing; 0 = pass-through + u16 consumeMask; // buttons to clear after firing; 0 = pass-through bool exclusive; // stop evaluating future combos if this fires }; diff --git a/src/dusk/mods/item.hpp b/src/dusk/mods/item.hpp index bda0d4f7ee..1b8897ae00 100644 --- a/src/dusk/mods/item.hpp +++ b/src/dusk/mods/item.hpp @@ -20,6 +20,7 @@ struct ItemCheckResult { uint32_t tag = 0; uint8_t itemNo = 0; uint8_t displayItemNo = 0; + bool was_resolved = false; }; ItemCheckResolution item_check_resolve(const char* name, uint8_t itemNo, fopAc_ac_c* giver); @@ -57,6 +58,13 @@ uint32_t item_check_message(uint16_t group, uint32_t messageId); bool item_give_queue_dispatching(); uint32_t item_give_queue_take_tag(); +struct BossItemActorSpeeds { + f32 f; + f32 y; +}; +void set_boss_item_actor_speeds(f32 f, f32 y); +BossItemActorSpeeds get_boss_item_actor_speeds(); + namespace detail { struct CommittedCheck { uint8_t vanillaItem = 0; diff --git a/src/dusk/mods/item_actor.cpp b/src/dusk/mods/item_actor.cpp new file mode 100644 index 0000000000..dc0feab472 --- /dev/null +++ b/src/dusk/mods/item_actor.cpp @@ -0,0 +1,15 @@ +#include "item.hpp" + +namespace dusk::mods { + +static BossItemActorSpeeds bossItemActorSpeeds{}; +void set_boss_item_actor_speeds(f32 f, f32 y) { + bossItemActorSpeeds.f = f; + bossItemActorSpeeds.y = y; +} + +BossItemActorSpeeds get_boss_item_actor_speeds() { + return bossItemActorSpeeds; +} + +} diff --git a/src/dusk/mods/item_checks.cpp b/src/dusk/mods/item_checks.cpp index fb145a48df..dc0a66d209 100644 --- a/src/dusk/mods/item_checks.cpp +++ b/src/dusk/mods/item_checks.cpp @@ -120,6 +120,12 @@ constexpr std::array kMessageChecks{ .vanillaItem = dItemNo_HORSE_FLUTE_e, .enqueueAtDisplay = false, }, + MessageCheck{ + .group = 2, + .messageId = 6531, + .name = ITEM_CHECK_SHAD_DOMINION_ROD, + .vanillaItem = dItemNo_COPY_ROD_2_e, + } }; std::unordered_map s_modChecks; @@ -152,7 +158,7 @@ std::string poe_check_name(uint8_t bitNo) { } std::string shop_check_name(uint8_t itemNo) { - return fmt::format("shop:{}:{}", current_stage_name(), itemNo); + return fmt::format("shop:{}:{}:{}", current_stage_name(), dStage_roomControl_c::getStayNo(), itemNo); } std::string bug_check_name(uint8_t insectId) { @@ -229,6 +235,7 @@ ItemCheckResolution item_check_resolve(const char* name, uint8_t itemNo, fopAc_a .vanilla_item = itemNo, .current_item = itemNo, .current_display_item = itemNo, + .was_resolved = false, }; for (const auto& resolve : resolves) { if (!resolve.mod->active) { @@ -237,6 +244,7 @@ ItemCheckResolution item_check_resolve(const char* name, uint8_t itemNo, fopAc_a if (resolve.fixedValue) { info.current_item = resolve.itemNo; info.current_display_item = resolve.itemNo; + info.was_resolved = true; continue; } @@ -251,6 +259,7 @@ ItemCheckResolution item_check_resolve(const char* name, uint8_t itemNo, fopAc_a } info.current_item = resolution.item; info.current_display_item = resolution.display_item; + info.was_resolved = true; } } catch (const std::exception& e) { fail_mod(*resolve.mod, MOD_ERROR, @@ -263,6 +272,7 @@ ItemCheckResolution item_check_resolve(const char* name, uint8_t itemNo, fopAc_a return { .item = info.current_item, .display_item = info.current_display_item, + .was_resolved = info.was_resolved, }; } diff --git a/src/dusk/mods/item_gives.cpp b/src/dusk/mods/item_gives.cpp index 5d75dcfc15..8feb0a7847 100644 --- a/src/dusk/mods/item_gives.cpp +++ b/src/dusk/mods/item_gives.cpp @@ -265,6 +265,7 @@ ItemCheckResult item_check_commit(uint32_t giveTag, uint8_t itemNo, fopAc_ac_c* .tag = giveTag, .itemNo = committed->resolution.item, .displayItemNo = committed->resolution.display_item, + .was_resolved = committed->resolution.was_resolved, }; } @@ -274,6 +275,7 @@ ItemCheckResult item_check_commit(uint32_t giveTag, uint8_t itemNo, fopAc_ac_c* .tag = giveTag, .itemNo = committed.resolution.item, .displayItemNo = committed.resolution.display_item, + .was_resolved = committed.resolution.was_resolved, }; } diff --git a/src/dusk/mods/loader/native_module.cpp b/src/dusk/mods/loader/native_module.cpp index f6adf20c60..0d4eb6a984 100644 --- a/src/dusk/mods/loader/native_module.cpp +++ b/src/dusk/mods/loader/native_module.cpp @@ -6,14 +6,6 @@ #include #endif -#if defined(__SANITIZE_ADDRESS__) -#define ADDRESS_SANITIZER 1 -#elif defined(__has_feature) -#if __has_feature(address_sanitizer) -#define ADDRESS_SANITIZER 1 -#endif -#endif - namespace { #if defined(_WIN32) void* pl_dlopen(const std::filesystem::path& p) { @@ -39,11 +31,7 @@ std::string pl_dlerror() { #else #include void* pl_dlopen(const std::filesystem::path& p) { - int flags = RTLD_LAZY | RTLD_LOCAL; -#if defined(RTLD_DEEPBIND) && !defined(ADDRESS_SANITIZER) - flags |= RTLD_DEEPBIND; -#endif - return dlopen(p.c_str(), flags); + return dlopen(p.c_str(), RTLD_LAZY | RTLD_LOCAL); } void* pl_dlsym(void* h, const char* name) { return dlsym(h, name); diff --git a/src/dusk/mods/svc/file.cpp b/src/dusk/mods/svc/file.cpp index 1650c7afca..f1ede94a3c 100644 --- a/src/dusk/mods/svc/file.cpp +++ b/src/dusk/mods/svc/file.cpp @@ -568,6 +568,11 @@ void file_initialize() { config::Register(s_pickerOverride); } +bool file_available() { + const auto capabilities = borealis::file_select::capabilities(); + return capabilities.canOpenFile || capabilities.canOpenFolder || capabilities.canExportFile; +} + ModResult copy_picker_override( std::string_view source, std::string_view destination, std::string& error) { try { @@ -688,6 +693,7 @@ constinit const ServiceModule g_fileModule{ .majorVersion = FILE_SERVICE_MAJOR, .minorVersion = FILE_SERVICE_MINOR, .service = &s_fileService, + .available = file_available, .initialize = file_initialize, .modDetached = file_remove_mod, .frameBegin = file_frame_begin, diff --git a/src/dusk/mods/svc/http.cpp b/src/dusk/mods/svc/http.cpp new file mode 100644 index 0000000000..337758d5d4 --- /dev/null +++ b/src/dusk/mods/svc/http.cpp @@ -0,0 +1,577 @@ +#include "registry.hpp" + +#include "slot_map.hpp" + +#include "dusk/app_info.hpp" +#include "dusk/main.h" +#include "dusk/mods/loader/loader.hpp" +#include "mods/svc/http.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dusk::mods::svc { +namespace { + +constexpr size_t MaxRequestsPerMod = 16; +constexpr size_t MaxUrlBytes = 8 * 1024; +constexpr size_t MaxHeaders = 64; +constexpr size_t MaxHeaderBytes = 16 * 1024; +constexpr size_t MaxRequestBodyBytes = 16 * 1024 * 1024; +constexpr size_t DefaultResponseBodyBytes = 1024 * 1024; +constexpr size_t MaxResponseBodyBytes = 64 * 1024 * 1024; +constexpr std::chrono::milliseconds DefaultTimeout{10000}; + +struct PendingRequest { + HttpCompleteFn callback = nullptr; + void* userData = nullptr; + borealis::Task task; + std::filesystem::path stagingPath; + std::filesystem::path downloadPath; + bool completing = false; +}; + +static_assert(std::is_nothrow_move_constructible_v); + +SlotMap s_requests; + +bool ascii_iequals(std::string_view left, std::string_view right) { + return left.size() == right.size() && std::ranges::equal(left, right, [](char a, char b) { + return std::tolower(static_cast(a)) == + std::tolower(static_cast(b)); + }); +} + +bool is_reserved_header(std::string_view name) { + constexpr std::string_view reserved[]{ + "User-Agent", + "Host", + "Content-Length", + "Connection", + "Accept-Encoding", + "Range", + "If-Range", + }; + return std::ranges::any_of( + reserved, [&](std::string_view value) { return ascii_iequals(name, value); }); +} + +bool valid_header_name(std::string_view name) { + constexpr std::string_view separators{"()<>@,;:\\\"/[]?={} \t"}; + return !name.empty() && std::ranges::all_of(name, [&](unsigned char value) { + return value > 32 && value < 127 && + separators.find(static_cast(value)) == std::string_view::npos; + }); +} + +bool valid_url(std::string_view url) { + constexpr std::string_view scheme{"https://"}; + if (!url.starts_with(scheme) || url.size() <= scheme.size() || url.size() > MaxUrlBytes) { + return false; + } + if (std::ranges::any_of(url, [](unsigned char value) { return value <= 32 || value == 127; })) { + return false; + } + const auto authorityEnd = url.find_first_of("/?#", scheme.size()); + const auto authority = url.substr(scheme.size(), authorityEnd - scheme.size()); + return !authority.empty(); +} + +bool declares_http_import(const LoadedMod& mod) { + return std::ranges::any_of( + mod.manifestInfo.imports, [](const ModManifestInfo::Import& serviceImport) { + return serviceImport.id == HTTP_SERVICE_ID; + }); +} + +std::filesystem::path normalized_absolute(const std::filesystem::path& path, std::error_code& ec) { + auto result = std::filesystem::absolute(path, ec); + return ec ? std::filesystem::path{} : result.lexically_normal(); +} + +bool path_is_below(const std::filesystem::path& path, const std::filesystem::path& directory) { + const auto [directoryEnd, pathPosition] = + std::mismatch(directory.begin(), directory.end(), path.begin(), path.end()); + return directoryEnd == directory.end() && pathPosition != path.end(); +} + +bool path_is_at_or_below( + const std::filesystem::path& path, const std::filesystem::path& directory) { + const auto [directoryEnd, pathPosition] = + std::mismatch(directory.begin(), directory.end(), path.begin(), path.end()); + (void)pathPosition; + return directoryEnd == directory.end(); +} + +std::filesystem::path data_root(const LoadedMod& mod, std::error_code& ec) { + if (!mod.dataDirUtf8.empty()) { + return normalized_absolute(borealis::io::fs_path_from_utf8(mod.dataDirUtf8), ec); + } + return normalized_absolute(ConfigPath / "mod_data" / mod.metadata.id, ec); +} + +std::optional validate_download_path( + const LoadedMod& mod, const char* rawPath) { + if (rawPath == nullptr) { + return std::filesystem::path{}; + } + const auto supplied = borealis::io::fs_path_from_utf8(rawPath); + if (!supplied.is_absolute()) { + return std::nullopt; + } + + std::error_code ec; + const auto path = normalized_absolute(supplied, ec); + if (ec) { + return std::nullopt; + } + const auto modRoot = normalized_absolute(mod.dir, ec); + if (ec) { + return std::nullopt; + } + const auto dataRoot = data_root(mod, ec); + if (ec) { + return std::nullopt; + } + const auto stagingRoot = (modRoot / "downloads").lexically_normal(); + if ((!path_is_below(path, modRoot) && !path_is_below(path, dataRoot)) || + path_is_at_or_below(path, stagingRoot)) + { + return std::nullopt; + } + return path; +} + +std::filesystem::path staging_path(const LoadedMod& mod, std::string_view url) { + const auto& modId = mod.metadata.id; + const auto modHash = XXH64(modId.data(), modId.size(), 0); + const auto hash = XXH64(url.data(), url.size(), modHash); + return mod.dir / "downloads" / fmt::format("{:016x}.part", hash); +} + +HttpError map_error(borealis::http::Error error) { + switch (error) { + case borealis::http::Error::None: + return HTTP_ERROR_NONE; + case borealis::http::Error::InvalidUrl: + return HTTP_ERROR_INVALID_URL; + case borealis::http::Error::UnsupportedScheme: + return HTTP_ERROR_UNSUPPORTED_SCHEME; + case borealis::http::Error::Timeout: + return HTTP_ERROR_TIMEOUT; + case borealis::http::Error::TooLarge: + return HTTP_ERROR_TOO_LARGE; + case borealis::http::Error::Canceled: + return HTTP_ERROR_CANCELED; + case borealis::http::Error::Io: + return HTTP_ERROR_IO; + case borealis::http::Error::NoBackend: + case borealis::http::Error::NotInitialized: + case borealis::http::Error::Network: + return HTTP_ERROR_NETWORK; + default: + return HTTP_ERROR_NETWORK; + } +} + +std::optional borealis_method(HttpMethod method) { + switch (method) { + case HTTP_METHOD_GET: + return borealis::http::Method::Get; + case HTTP_METHOD_POST: + return borealis::http::Method::Post; + case HTTP_METHOD_HEAD: + return borealis::http::Method::Head; + } + return std::nullopt; +} + +borealis::http::Result publish_download(borealis::http::Result result, + const std::filesystem::path& staging, const std::filesystem::path& destination) noexcept { + if (result.error != borealis::http::Error::None) { + return result; + } + + try { + std::string renameError; + if (borealis::io::atomic_replace(staging, destination, renameError)) { + return result; + } + + std::filesystem::path temporary = destination; + temporary += "." + borealis::io::fs_path_to_string(staging.filename()) + ".part"; + std::error_code ec; + std::filesystem::copy_file( + staging, temporary, std::filesystem::copy_options::overwrite_existing, ec); + if (ec) { + const std::string copyError = ec.message(); + std::error_code ignored; + std::filesystem::remove(temporary, ignored); + result.error = borealis::http::Error::Io; + result.message = "Failed to publish download: " + copyError; + return result; + } + + std::string replaceError; + if (!borealis::io::atomic_replace(temporary, destination, replaceError)) { + std::filesystem::remove(temporary, ec); + result.error = borealis::http::Error::Io; + result.message = "Failed to publish download: " + replaceError; + return result; + } + std::filesystem::remove(staging, ec); + return result; + } catch (const std::exception& exception) { + result.error = borealis::http::Error::Io; + result.message = std::string{"Failed to publish download: "} + exception.what(); + return result; + } catch (...) { + result.error = borealis::http::Error::Io; + result.message = "Failed to publish download"; + return result; + } +} + +void http_frame_begin() { + std::vector ready; + s_requests.for_each([&](const HttpRequestHandle handle, const auto& entry) { + const auto& pending = entry.value; + if (!pending.completing && pending.task.ready()) { + ready.push_back(handle); + } + }); + + for (const auto handle : ready) { + auto* entry = s_requests.find(handle); + if (entry == nullptr || !entry->owner->active || entry->value.completing) { + continue; + } + auto& pending = entry->value; + borealis::http::Result result; + try { + auto completed = pending.task.try_take(); + if (!completed.has_value()) { + continue; + } + result = std::move(*completed); + } catch (const std::exception& exception) { + result = { + .error = borealis::http::Error::Io, + .message = exception.what(), + }; + } catch (...) { + result = { + .error = borealis::http::Error::Io, + .message = "HTTP request completion failed", + }; + } + + auto* owner = entry->owner; + const auto callback = pending.callback; + const auto userData = pending.userData; + pending.completing = true; + + std::vector headers; + headers.reserve(result.response.headers.size()); + for (const auto& header : result.response.headers) { + headers.push_back({.name = header.name.c_str(), .value = header.value.c_str()}); + } + const bool downloadSucceeded = + !pending.downloadPath.empty() && result.error == borealis::http::Error::None; + const auto publishedPath = downloadSucceeded ? + borealis::io::fs_path_to_string(pending.downloadPath) : + std::string{}; + const HttpResult snapshot{ + .struct_size = sizeof(HttpResult), + .error = map_error(result.error), + .error_message = result.message.c_str(), + .status_code = result.response.statusCode, + .headers = headers.empty() ? nullptr : headers.data(), + .header_count = static_cast(headers.size()), + .body = pending.downloadPath.empty() && !result.response.body.empty() ? + result.response.body.data() : + nullptr, + .body_size = pending.downloadPath.empty() ? result.response.body.size() : 0, + .download_path = downloadSucceeded ? publishedPath.c_str() : nullptr, + }; + + try { + callback(owner->context.get(), handle, &snapshot, userData); + } catch (const std::exception& exception) { + fail_mod(*owner, MOD_ERROR, + std::string{"exception in HTTP completion callback: "} + exception.what()); + } catch (...) { + fail_mod(*owner, MOD_ERROR, "unknown exception in HTTP completion callback"); + } + s_requests.erase(handle); + } +} + +size_t active_request_count(const LoadedMod& mod) { + size_t count = 0; + s_requests.for_each([&](HttpRequestHandle, const auto& entry) { + if (entry.owner == &mod && !entry.value.completing) { + ++count; + } + }); + return count; +} + +bool staging_path_in_use(const LoadedMod& mod, const std::filesystem::path& path) { + bool inUse = false; + s_requests.for_each([&](HttpRequestHandle, const auto& entry) { + if (entry.owner == &mod && !entry.value.completing && entry.value.stagingPath == path) { + inUse = true; + } + }); + return inUse; +} + +std::string user_agent_version(std::string_view version) { + std::string result{version}; + for (char& ch : result) { + const auto value = static_cast(ch); + if (value <= 32 || value >= 127) { + ch = '_'; + } + } + return result; +} + +ModResult start_request(LoadedMod& mod, const HttpRequestDesc& desc, HttpCompleteFn callback, + void* userData, HttpRequestHandle& outHandle) { + const std::string_view url{desc.url}; + const auto method = borealis_method(desc.method); + if (!valid_url(url) || !method.has_value() || + (desc.header_count != 0 && desc.headers == nullptr) || + (desc.body_size != 0 && desc.body == nullptr) || desc.body_size > MaxRequestBodyBytes || + ((desc.method == HTTP_METHOD_GET || desc.method == HTTP_METHOD_HEAD) && + desc.body_size != 0) || + (desc.method == HTTP_METHOD_HEAD && desc.download_path != nullptr) || + desc.header_count > MaxHeaders) + { + return MOD_INVALID_ARGUMENT; + } + size_t headerBytes = 0; + for (uint32_t i = 0; i < desc.header_count; ++i) { + const auto& header = desc.headers[i]; + if (header.name == nullptr || header.value == nullptr) { + return MOD_INVALID_ARGUMENT; + } + const std::string_view name{header.name}; + const std::string_view value{header.value}; + const bool invalidValue = std::ranges::any_of( + value, [](unsigned char ch) { return (ch < 32 && ch != '\t') || ch == 127; }); + if (!valid_header_name(name) || invalidValue || is_reserved_header(name) || + name.size() > MaxHeaderBytes - headerBytes) + { + return MOD_INVALID_ARGUMENT; + } + headerBytes += name.size(); + if (value.size() > MaxHeaderBytes - headerBytes) { + return MOD_INVALID_ARGUMENT; + } + headerBytes += value.size(); + } + + auto downloadPath = validate_download_path(mod, desc.download_path); + if (!downloadPath.has_value() || + (downloadPath->empty() && desc.max_body_bytes > MaxResponseBodyBytes)) + { + return MOD_INVALID_ARGUMENT; + } + if (active_request_count(mod) >= MaxRequestsPerMod) { + return MOD_CONFLICT; + } + + std::filesystem::path staging; + if (!downloadPath->empty()) { + staging = staging_path(mod, url); + if (staging_path_in_use(mod, staging)) { + return MOD_CONFLICT; + } + std::error_code ec; + std::filesystem::create_directories(staging.parent_path(), ec); + if (ec) { + return MOD_ERROR; + } + std::filesystem::create_directories(downloadPath->parent_path(), ec); + if (ec) { + return MOD_ERROR; + } + } + + PendingRequest pending{ + .callback = callback, + .userData = userData, + .stagingPath = staging, + .downloadPath = *downloadPath, + }; + + if (!borealis::http::available()) { + return MOD_UNAVAILABLE; + } + borealis::http::Request request{ + .method = *method, + .url = std::string{url}, + .body = desc.body_size != 0 ? + std::string{static_cast(desc.body), desc.body_size} : + std::string{}, + .downloadTo = staging, + .connectTimeout = desc.connect_timeout_ms != 0 ? + std::chrono::milliseconds{desc.connect_timeout_ms} : + DefaultTimeout, + .idleTimeout = desc.idle_timeout_ms != 0 ? + std::chrono::milliseconds{desc.idle_timeout_ms} : + DefaultTimeout, + .totalTimeout = desc.total_timeout_ms != 0 ? + std::optional{std::chrono::milliseconds{desc.total_timeout_ms}} : + std::nullopt, + .maxBodyBytes = + desc.max_body_bytes != 0 ? desc.max_body_bytes : DefaultResponseBodyBytes, + }; + request.headers.reserve(desc.header_count + 1); + for (uint32_t i = 0; i < desc.header_count; ++i) { + request.headers.push_back({desc.headers[i].name, desc.headers[i].value}); + } + request.headers.push_back({ + .name = "User-Agent", + .value = fmt::format("{}/{} {}/{}", AppName, BOREALIS_APP_VERSION, mod.metadata.id, + user_agent_version(mod.metadata.version)), + }); + + auto task = borealis::http::start(std::move(request)); + if (task.ready()) { + auto immediate = task.try_take(); + if (!immediate.has_value()) { + return MOD_UNAVAILABLE; + } + if (immediate->error == borealis::http::Error::NoBackend || + immediate->error == borealis::http::Error::NotInitialized) + { + return MOD_UNAVAILABLE; + } + task = borealis::detail::make_ready_task(std::move(*immediate)); + } + if (!downloadPath->empty()) { + task = std::move(task).map([staging, destination = *downloadPath](auto&& result) { + return publish_download(std::move(result), staging, destination); + }); + } + pending.task = std::move(task); + + outHandle = s_requests.emplace(mod, std::move(pending)); + return MOD_OK; +} + +ModResult http_request(ModContext* context, const HttpRequestDesc* desc, HttpCompleteFn callback, + void* userData, HttpRequestHandle* outHandle) { + if (outHandle != nullptr) { + *outHandle = 0; + } + auto* mod = mod_from_context(context); + if (mod == nullptr || desc == nullptr || desc->struct_size < sizeof(HttpRequestDesc) || + desc->url == nullptr || callback == nullptr || outHandle == nullptr) + { + return MOD_INVALID_ARGUMENT; + } + if (!declares_http_import(*mod)) { + return MOD_UNSUPPORTED; + } + try { + return start_request(*mod, *desc, callback, userData, *outHandle); + } catch (...) { + return MOD_ERROR; + } +} + +ModResult http_progress(ModContext* context, HttpRequestHandle handle, HttpProgress* outProgress) { + const uint32_t structSize = outProgress != nullptr ? outProgress->struct_size : 0; + auto* mod = mod_from_context(context); + if (mod == nullptr || outProgress == nullptr || structSize < sizeof(HttpProgress)) { + return MOD_INVALID_ARGUMENT; + } + *outProgress = HttpProgress{.struct_size = structSize}; + const auto* entry = s_requests.find_owned(handle, *mod); + if (entry == nullptr) { + return MOD_UNAVAILABLE; + } + + const auto progress = entry->value.task.progress(); + outProgress->completed_bytes = progress.completed; + outProgress->total_bytes = progress.total.value_or(0); + outProgress->total_known = progress.total.has_value(); + return MOD_OK; +} + +ModResult http_cancel(ModContext* context, HttpRequestHandle handle) { + auto* mod = mod_from_context(context); + if (mod == nullptr) { + return MOD_INVALID_ARGUMENT; + } + auto* entry = s_requests.find_owned(handle, *mod); + if (entry == nullptr) { + return MOD_UNAVAILABLE; + } + entry->value.task.cancel(); + return MOD_OK; +} + +void http_mod_deactivating(LoadedMod& mod) { + (void)s_requests.take_all(mod); +} + +void http_mod_detached(LoadedMod& mod) { + bool found = false; + s_requests.for_each( + [&](HttpRequestHandle, const auto& entry) { found = found || entry.owner == &mod; }); + assert(!found); +} + +void http_shutdown() { + s_requests = {}; +} + +bool http_available() { + return borealis::http::available() && borealis::http::initialize(); +} + +constexpr HttpService s_httpService{ + .header = SERVICE_HEADER(HttpService, HTTP_SERVICE_MAJOR, HTTP_SERVICE_MINOR), + .request = http_request, + .progress = http_progress, + .cancel = http_cancel, +}; + +} // namespace + +constinit const ServiceModule g_httpModule{ + .id = HTTP_SERVICE_ID, + .majorVersion = HTTP_SERVICE_MAJOR, + .minorVersion = HTTP_SERVICE_MINOR, + .service = &s_httpService, + .available = http_available, + .modDeactivating = http_mod_deactivating, + .modDetached = http_mod_detached, + .frameBegin = http_frame_begin, + .shutdown = http_shutdown, +}; + +} // namespace dusk::mods::svc diff --git a/src/dusk/mods/svc/item.cpp b/src/dusk/mods/svc/item.cpp index f80fc16b9b..44b0eff37e 100644 --- a/src/dusk/mods/svc/item.cpp +++ b/src/dusk/mods/svc/item.cpp @@ -75,6 +75,17 @@ ModResult item_resolve_check( return MOD_OK; } +ModResult item_resolve_check_full(ModContext* context, const char* name, uint8_t originalItemNo, + ItemCheckResolution* outResolution) { + if (mod_from_context(context) == nullptr || !is_valid_check_name(name) || + outResolution == nullptr) + { + return MOD_INVALID_ARGUMENT; + } + *outResolution = item_check_resolve(name, originalItemNo, nullptr); + return MOD_OK; +} + ModResult item_give_item( ModContext* context, const char* checkName, uint8_t itemNo, uint32_t flags) { auto* mod = mod_from_context(context); @@ -130,6 +141,7 @@ constexpr ItemService s_itemService{ .give_item = item_give_item, .observe_gives = item_observe_gives, .unobserve_gives = item_unobserve_gives, + .resolve_check_full = item_resolve_check_full, }; } // namespace diff --git a/src/dusk/mods/svc/registry.cpp b/src/dusk/mods/svc/registry.cpp index 26c67699f1..13c042af3d 100644 --- a/src/dusk/mods/svc/registry.cpp +++ b/src/dusk/mods/svc/registry.cpp @@ -9,10 +9,6 @@ #include #include -#if defined(__APPLE__) -#include -#endif - namespace dusk::mods::svc { namespace { @@ -142,6 +138,9 @@ const ServiceRecord* find_service_record(const char* serviceId, const uint16_t m } ModResult register_module(const ServiceModule& module) { + if (module.available != nullptr && !module.available()) { + return MOD_UNAVAILABLE; + } const auto result = register_service( module.id, module.majorVersion, module.minorVersion, module.service, nullptr, false); if (result != MOD_OK) { @@ -214,9 +213,8 @@ void ModLoader::init_services() { &svc::g_hostModule, &svc::g_logModule, &svc::g_resourceModule, -#if !defined(__APPLE__) || !TARGET_OS_TV &svc::g_fileModule, -#endif + &svc::g_httpModule, &svc::g_hookModule, &svc::g_overlayModule, &svc::g_textureModule, diff --git a/src/dusk/mods/svc/registry.hpp b/src/dusk/mods/svc/registry.hpp index 7a4b07ad21..68ec9353cd 100644 --- a/src/dusk/mods/svc/registry.hpp +++ b/src/dusk/mods/svc/registry.hpp @@ -26,6 +26,8 @@ struct ServiceModule { uint16_t minorVersion = 0; const void* service = nullptr; + // False prevents registration when a platform dependency is unavailable. + bool (*available)() = nullptr; // One-time setup, at registration (ModLoader::init_services). void (*initialize)() = nullptr; // A mod is beginning deactivation: stop callbacks that may execute concurrently. Service state @@ -69,6 +71,7 @@ extern const ServiceModule g_hostModule; extern const ServiceModule g_logModule; extern const ServiceModule g_resourceModule; extern const ServiceModule g_fileModule; +extern const ServiceModule g_httpModule; extern const ServiceModule g_hookModule; extern const ServiceModule g_overlayModule; extern const ServiceModule g_textureModule; diff --git a/src/dusk/mods/svc/save.cpp b/src/dusk/mods/svc/save.cpp index 360cdf6dca..209c0037fa 100644 --- a/src/dusk/mods/svc/save.cpp +++ b/src/dusk/mods/svc/save.cpp @@ -200,6 +200,7 @@ void save_slot_written(uint32_t slot, const void* slotData) { store.snapshotCrc = utils::crc32(slotData, kQuestLogSize); } flush_sidecar(); + s_currentSlot = static_cast(slot); notify(slot, &SaveObserverRecord::onWritten, "save-written"); } diff --git a/src/dusk/ui/mods_window.cpp b/src/dusk/ui/mods_window.cpp index 8b8891cbe1..757fa42b62 100644 --- a/src/dusk/ui/mods_window.cpp +++ b/src/dusk/ui/mods_window.cpp @@ -5,12 +5,14 @@ #include "fmt/format.h" #include "logs_window.hpp" #include "mod_texture_provider.hpp" +#include "mods/svc/http.h" #include "pane.hpp" #include "Z2AudioLib/Z2SeMgr.h" #include "m_Do/m_Do_audio.h" #include +#include #include #include @@ -39,6 +41,13 @@ ModStatus mod_status(const mods::LoadedMod& mod) { return {"", "Disabled"}; } +bool mod_uses_network(const mods::LoadedMod& mod) { + return std::ranges::any_of( + mod.manifestInfo.imports, [](const mods::ModManifestInfo::Import& serviceImport) { + return serviceImport.id == HTTP_SERVICE_ID; + }); +} + // Truncates to at most maxBytes without splitting a UTF-8 sequence. std::string snippet(std::string_view text, size_t maxBytes) { if (text.size() <= maxBytes) { @@ -63,16 +72,19 @@ public: iconRml = R"()"; } const auto status = mod_status(mod); + const auto networkBadge = mod_uses_network(mod) ? + R"(Network)" : + Rml::String{}; mRoot->SetInnerRML(fmt::format( R"({})" R"()", iconRml, escape(mod.metadata.name), escape(mod.metadata.version), - escape(mod.metadata.author), status.badgeClass, status.text, + escape(mod.metadata.author), status.badgeClass, status.text, networkBadge, escape(snippet(mod.metadata.description, 90)))); mRoot->SetClass("inactive", !mod.active); mRoot->SetClass("failed", mod.loadFailed); @@ -225,6 +237,9 @@ void ModsWindow::build_detail(Pane& pane, mods::LoadedMod& mod) { statusBadge = fmt::format( R"( {})", status.badgeClass, status.text); } + if (mod_uses_network(mod)) { + statusBadge += R"( Network)"; + } pane.add_rml(fmt::format(R"(
{} )" R"(v{}{}
)" R"(
by {}
)", diff --git a/src/f_op/f_op_actor_mng.cpp b/src/f_op/f_op_actor_mng.cpp index 3097b9294f..207a0471b3 100644 --- a/src/f_op/f_op_actor_mng.cpp +++ b/src/f_op/f_op_actor_mng.cpp @@ -1621,6 +1621,7 @@ fpc_ProcID fopAcM_createItemForBoss(const cXyz* i_pos, int i_itemNo, int i_roomN if (i_itemNo != originalItemNo) { const u32 params = 0xFFFF0000 | param_8 << 8 | (i_itemNo & 0xFF); + dusk::mods::set_boss_item_actor_speeds(i_speedF, i_speedY); return fopAcM_create(fpcNm_Obj_LifeContainer_e, params, i_pos, i_roomNo, i_angle, i_scale, -1, giveTag, originalItemNo); } diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 22a9d87a33..dcc6787f4b 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -769,6 +770,10 @@ int game_main(int argc, char* argv[]) { return 0; } + if (borealis::http::available() && !borealis::http::initialize()) { + DuskLog.warn("Failed to initialize the HTTP worker pool"); + } + if (dusk::getSettings().game.enableHighQualityMinimapTextures.getValue()) { dusk::hq_minimap::set_active(true); } @@ -885,6 +890,7 @@ int game_main(int argc, char* argv[]) { // pre game launch ui main loop if (!launchUILoop()) { + borealis::http::shutdown(); borealis::sentry::shutdown(); borealis::log::shutdown(); fflush(stdout); @@ -975,6 +981,7 @@ int game_main(int argc, char* argv[]) { OSReport("Starting main01 (Game Loop)...\n"); main01(); + borealis::http::shutdown(); // We need to cleanly shut down the threads to avoid crashes on shutdown. if (daMP_c::m_myObj) {