diff --git a/.github/actions/canary-ndk/action.yml b/.github/actions/canary-ndk/action.yml new file mode 100644 index 0000000..6454ad5 --- /dev/null +++ b/.github/actions/canary-ndk/action.yml @@ -0,0 +1,35 @@ +name: "Setup canary ndk" +description: "Sets up canary ndk" +outputs: + ndk-path: + value: ${{ steps.path.outputs.path }} + description: "Output path of the ndk" + cache-hit: + value: ${{ steps.cache.outputs.cache-hit }} + description: "Whether a cache hit occurred for the ndk" +runs: + using: "composite" + steps: + - name: NDK cache + id: cache + uses: actions/cache@v3 + with: + path: ${HOME}/android-ndk-r27-canary/ + key: ${{ runner.os }}-ndk-r27-canary + + - name: Download canary ndk + if: ${{ !steps.cache.outputs.cache-hit }} + env: + CANARY_URL: https://github.com/QuestPackageManager/ndk-canary-archive/releases/download/27.0.1/android-ndk-10883340-linux-x86_64.zip + run: wget ${CANARY_URL} -O ${HOME}/ndk.zip + shell: bash + + - name: Unzip ndk + if: ${{ !steps.cache.outputs.cache-hit }} + run: 7z x "${HOME}/ndk.zip" -o"${HOME}/" + shell: bash + + - name: Set output + id: path + shell: bash + run: echo "path=${HOME}/android-ndk-r27-canary" >> ${GITHUB_OUTPUT} \ No newline at end of file diff --git a/.github/workflows/build-ndk.yml b/.github/workflows/build-ndk.yml index 215e614..6aca019 100644 --- a/.github/workflows/build-ndk.yml +++ b/.github/workflows/build-ndk.yml @@ -38,11 +38,24 @@ jobs: - uses: seanmiddleditch/gha-setup-ninja@v3 + # Use canary NDK to avoid lesser known compile bugs + - name: Setup canary NDK + id: setup-ndk + uses: ./.github/actions/canary-ndk + - name: Create ndkpath.txt run: | - echo "$ANDROID_NDK_LATEST_HOME" > ${GITHUB_WORKSPACE}/ndkpath.txt + echo ${{ steps.setup-ndk.outputs.ndk-path }} > ${GITHUB_WORKSPACE}/ndkpath.txt cat ${GITHUB_WORKSPACE}/ndkpath.txt + # get version from pushed tag + - name: Extract version + if: startsWith(github.ref, 'refs/tags/v') + id: version + run: | + echo "TAG=${GITHUB_REF#refs/tags/}" >> ${GITHUB_OUTPUT} + echo "VERSION=${GITHUB_REF#refs/tags/v}" >> ${GITHUB_OUTPUT} + - name: Setup qpm uses: Fernthedev/qpm-action@main with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a482b96..eee9da2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,11 +22,24 @@ jobs: - uses: seanmiddleditch/gha-setup-ninja@v3 + # Use canary NDK to avoid lesser known compile bugs + - name: Setup canary NDK + id: setup-ndk + uses: ./.github/actions/canary-ndk + - name: Create ndkpath.txt run: | - echo "$ANDROID_NDK_LATEST_HOME" > ${GITHUB_WORKSPACE}/ndkpath.txt + echo ${{ steps.setup-ndk.outputs.ndk-path }} > ${GITHUB_WORKSPACE}/ndkpath.txt cat ${GITHUB_WORKSPACE}/ndkpath.txt + # get version from pushed tag + - name: Extract version + if: startsWith(github.ref, 'refs/tags/v') + id: version + run: | + echo "TAG=${GITHUB_REF#refs/tags/}" >> ${GITHUB_OUTPUT} + echo "VERSION=${GITHUB_REF#refs/tags/v}" >> ${GITHUB_OUTPUT} + - name: Get Tag Version id: get_tag_version run: | diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 739d33f..420f54d 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,6 +1,6 @@ { "env": { - "ndkPath": "D:/User/Repositories/GitHubQuestModding/android-ndk-r24" + "ndkPath": "D:/User/Repositories/GitHubQuestModding/android-ndk-r27-canary" }, "configurations": [ { @@ -13,7 +13,7 @@ ], "includePath": [ "${workspaceFolder}/extern/includes/libil2cpp/il2cpp/libil2cpp", - "${workspaceFolder}/extern/includes/codegen/include", + "${workspaceFolder}/extern/includes/bs-cordl/include", "${workspaceFolder}/extern/includes", "${workspaceFolder}/include", "${workspaceFolder}/shared", diff --git a/.vscode/settings.json b/.vscode/settings.json index 9624ff3..17a6f4e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -123,7 +123,8 @@ "stop_token": "cpp", "__std_stream": "cpp", "memory_resource": "cpp", - "ranges": "cpp" + "ranges": "cpp", + "__verbose_abort": "cpp" }, "editor.formatOnSave": false, "editor.trimAutoWhitespace": true, diff --git a/CMakeLists.txt b/CMakeLists.txt index 44450a9..3b4888e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ # include some defines automatically made by qpm include(qpm_defines.cmake) +include(${EXTERN_DIR}/includes/kaleb/shared/cmake/assets.cmake) add_definitions(-DCP_SDK_BMBF) add_definitions(-DDEBUG_SCENES) @@ -32,10 +33,34 @@ set(SHARED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shared) # compile options used add_compile_options(-frtti -fexceptions) add_compile_options(-O3) + +# get git info +execute_process(COMMAND git config user.name OUTPUT_VARIABLE GIT_USER) +execute_process(COMMAND git branch --show-current OUTPUT_VARIABLE GIT_BRANCH) +execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_COMMIT) +execute_process(COMMAND git diff-index --quiet HEAD RESULT_VARIABLE GIT_MODIFIED) + +string(STRIP "${GIT_USER}" GIT_USER) +string(STRIP "${GIT_BRANCH}" GIT_BRANCH) +string(STRIP "${GIT_COMMIT}" GIT_COMMIT) +string(STRIP "${GIT_MODIFIED}" GIT_MODIFIED) + +message(STATUS "GIT_USER: ${GIT_USER}") +message(STATUS "GIT_BRANCH: ${GIT_BRANCH}") +message(STATUS "GIT_COMMIT: 0x${GIT_COMMIT}") +message(STATUS "GIT_MODIFIED: ${GIT_MODIFIED}") + +# set git defines +add_compile_definitions(GIT_USER=\"${GIT_USER}\") +add_compile_definitions(GIT_BRANCH=\"${GIT_BRANCH}\") +add_compile_definitions(GIT_COMMIT=0x${GIT_COMMIT}) +add_compile_definitions(GIT_MODIFIED=${GIT_MODIFIED}) + # compile definitions used add_compile_definitions(VERSION=\"${MOD_VERSION}\") add_compile_definitions(MOD_ID=\"${MOD_ID}\") add_compile_definitions(__USE_LARGEFILE64) +add_compile_definitions(BEATSABER_1_29_4_OR_NEWER) # recursively get all src files RECURSE_FILES(h_file_lista ${INCLUDE_DIR}/*.hpp) @@ -58,6 +83,9 @@ add_library( ${c_file_list} ) +# Add any assets +add_assets(assets_${COMPILE_ID} STATIC ${CMAKE_CURRENT_LIST_DIR}/assets ${INCLUDE_DIR}/assets.hpp) + # get the vcpkg dir from env variables if(EXISTS $ENV{VCPKG_ROOT}) set(VCPKG_ROOT $ENV{VCPKG_ROOT}) @@ -77,6 +105,7 @@ target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR}) target_include_directories(${COMPILE_ID} PRIVATE ${EXTERN_DIR}/includes/${CODEGEN_ID}/include) target_link_libraries(${COMPILE_ID} PRIVATE -llog) +target_link_libraries(${COMPILE_ID} PRIVATE assets_${COMPILE_ID}) # add extern stuff like libs and other includes include(extern.cmake) @@ -120,7 +149,4 @@ add_custom_command(TARGET ${COMPILE_ID} POST_BUILD add_custom_command(TARGET ${COMPILE_ID} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${a_file} debug/${file} COMMENT "Copy a files for ndk stack") - endforeach() - - -include(assets_include.cmake) \ No newline at end of file + endforeach() \ No newline at end of file diff --git a/README.md b/README.md index 3fb083e..8e0b3aa 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ And to initilize the module #include "MyModule.hpp" #include -#include +#include #include #include diff --git a/assets/QuestFonts.bundle b/assets/QuestFonts.bundle index 27481f0..48820f4 100644 Binary files a/assets/QuestFonts.bundle and b/assets/QuestFonts.bundle differ diff --git a/assets_include.cmake b/assets_include.cmake deleted file mode 100644 index c9d5ce0..0000000 --- a/assets_include.cmake +++ /dev/null @@ -1,116 +0,0 @@ -# credit goes to https://github.com/Lauriethefish for this -# Directory where our arbitrary asset files are stored -set(ASSETS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets) -# Directory to save the object files generated by llvm-objcopy -set(ASSET_BINARIES_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/binaryAssets) -# Directory to save the prepended files to -set(PREPENDED_ASSETS_DIR ${CMAKE_CURRENT_BINARY_DIR}/prependedAssets) -set(ASSET_HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include/assets.hpp") - -# Define a macro which we will use for defining the symbols to access our asset files below -set(ASSET_HEADER_DATA -"#pragma once - -#include -#include \"beatsaber-hook/shared/utils/typedefs.h\" - -struct IncludedAsset { - - IncludedAsset(uint8_t* start, uint8_t* end) : array(reinterpret_cast*>(start)) { - array->klass = nullptr; - array->monitor = nullptr; - array->bounds = nullptr; - array->max_length = end - start - 33; - *(end - 1)= '\\0'; - } - - operator ArrayW() const { - init(); - return array; - } - - Array* Raw() const { - init(); - return array; - } - - operator std::string_view() const { - return { reinterpret_cast(array->values), array->Length() }; - } - - operator std::span() const { - return { array->values, array->Length() }; - } - - void init() const { - if(!array->klass) - array->klass = classof(Array*); - } - - private: - Array* array; - -}; - -#define DECLARE_FILE(name) \\ - extern \"C\" uint8_t _binary_##name##_start[]; \\ - extern \"C\" uint8_t _binary_##name##_end[]; \\ - const IncludedAsset name { _binary_##name##_start, _binary_##name##_end}; - -namespace IncludedAssets { -\n") - -if (EXISTS ${ASSETS_DIRECTORY}) - file(MAKE_DIRECTORY ${ASSET_BINARIES_DIRECTORY}) - file(MAKE_DIRECTORY ${PREPENDED_ASSETS_DIR}) - file(GLOB ASSETS LIST_DIRECTORIES false ${ASSETS_DIRECTORY}/*) - - # Iterate through each file in the assets directory. TODO: This could be recursive - foreach(FILE IN LISTS ASSETS) - message("-- Including asset: ${FILE}") - get_filename_component(ASSET ${FILE} NAME) # Find the asset's file name - - # make a copy of the file with 32 bytes added in the build dir - add_custom_command( - OUTPUT ${PREPENDED_ASSETS_DIR}/${ASSET} - COMMAND ${CMAKE_COMMAND} -E echo_append " " > ${PREPENDED_ASSETS_DIR}/${ASSET} - COMMAND ${CMAKE_COMMAND} -E cat ${ASSETS_DIRECTORY}/${ASSET} >> ${PREPENDED_ASSETS_DIR}/${ASSET} - COMMAND ${CMAKE_COMMAND} -E echo_append " " >> ${PREPENDED_ASSETS_DIR}/${ASSET} - DEPENDS ${ASSETS_DIRECTORY}/${ASSET} - ) - - set(OUTPUT_FILE "${ASSET_BINARIES_DIRECTORY}/${ASSET}.o") # Save our asset in the asset binaries directory - - # Use llvm-objcopy to create an object file that stores our binary asset - # The resulting file contains 3 symbols: _binary__start, _binary__size and _binary__end - # We only use the first two - add_custom_command( - OUTPUT ${OUTPUT_FILE} - COMMAND ${CMAKE_OBJCOPY} ${ASSET} ${OUTPUT_FILE} --input-target binary --output-target elf64-aarch64 --set-section-flags binary=strings - DEPENDS ${PREPENDED_ASSETS_DIR}/${ASSET} - WORKING_DIRECTORY ${PREPENDED_ASSETS_DIR} - ) - list(APPEND BINARY_ASSET_FILES ${OUTPUT_FILE}) - - # Find the correct objcopy symbol name, this is always the file name with any non-alphanumeric characters replaced with _ - string(REGEX REPLACE "[^a-zA-Z0-9]" "_" FIXED_ASSET ${ASSET}) - # Add to our assets header - set(ASSET_HEADER_DATA "${ASSET_HEADER_DATA}\tDECLARE_FILE(${FIXED_ASSET})\n") - endforeach() - set(ASSET_HEADER_DATA "${ASSET_HEADER_DATA}\n}\n") - - # check if at least 1 asset file, otherwise ignore - list(LENGTH BINARY_ASSET_FILES COUNT) - if (${COUNT} GREATER 0) - # Generate the assets header file - file(GENERATE OUTPUT ${ASSET_HEADER_PATH} CONTENT "${ASSET_HEADER_DATA}") - - # Add our assets files to the final SO - add_library(asset_files OBJECT ${BINARY_ASSET_FILES}) - set_target_properties(asset_files PROPERTIES LINKER_LANGUAGE CXX) - target_link_libraries(${COMPILE_ID} PRIVATE asset_files ${BINARY_ASSET_FILES}) - endif() -else() - message("-- Removing '${ASSET_HEADER_PATH}' as no assets have been found in '${ASSETS_DIRECTORY}'") - file(REMOVE ${ASSET_HEADER_PATH}) -endif() diff --git a/copy.ps1 b/copy.ps1 index 312152c..aeabc97 100644 --- a/copy.ps1 +++ b/copy.ps1 @@ -56,12 +56,22 @@ $modFiles = $modJson.modFiles foreach ($fileName in $modFiles) { if ($useDebug -eq $true) { - & adb push build/debug/$fileName /sdcard/Android/data/com.beatgames.beatsaber/files/mods/$fileName + & adb push build/debug/$fileName /sdcard/ModData/com.beatgames.beatsaber/Modloader/mods/$fileName } else { - & adb push build/$fileName /sdcard/Android/data/com.beatgames.beatsaber/files/mods/$fileName + & adb push build/$fileName /sdcard/ModData/com.beatgames.beatsaber/Modloader/mods/$fileName } } +$modFiles = $modJson.lateModFiles +foreach ($fileName in $modFiles) { + if ($useDebug -eq $true) { + & adb push build/debug/$fileName /sdcard/ModData/com.beatgames.beatsaber/Modloader/mods/$fileName + } else { + & adb push build/$fileName /sdcard/ModData/com.beatgames.beatsaber/Modloader/mods/$fileName + } +} + + & $PSScriptRoot/restart-game.ps1 if ($log -eq $true) { diff --git a/createqmod.ps1 b/createqmod.ps1 index cd8280d..79b25f8 100644 --- a/createqmod.ps1 +++ b/createqmod.ps1 @@ -21,30 +21,35 @@ if ((-not ($cover -eq "./")) -and (Test-Path $cover)) $fileList += ,$cover } -foreach ($mod in $modJson.modFiles) -{ +foreach ($mod in $modJson.modFiles) { + $path = "./build/" + $mod + if (-not (Test-Path $path)) { + $path = "./extern/libs/" + $mod + } + if (-not (Test-Path $path)) { + Write-Output "Error: could not find dependency: $path" + exit 1 + } + $filelist += $path +} +foreach ($mod in $modJson.lateModFiles) { $path = "./build/" + $mod - if (-not (Test-Path $path)) - { + if (-not (Test-Path $path)) { $path = "./extern/libs/" + $mod } - if (-not (Test-Path $path)) - { + if (-not (Test-Path $path)) { Write-Output "Error: could not find dependency: $path" exit 1 } $filelist += $path } -foreach ($lib in $modJson.libraryFiles) -{ +foreach ($lib in $modJson.libraryFiles) { $path = "./build/" + $lib - if (-not (Test-Path $path)) - { + if (-not (Test-Path $path)) { $path = "./extern/libs/" + $lib } - if (-not (Test-Path $path)) - { + if (-not (Test-Path $path)) { Write-Output "Error: could not find dependency: $path" exit 1 } diff --git a/include/assets.hpp b/include/assets.hpp index 58b4d24..c9df435 100644 --- a/include/assets.hpp +++ b/include/assets.hpp @@ -1,75 +1,26 @@ #pragma once - -#include -#include "beatsaber-hook/shared/utils/typedefs.h" - -struct IncludedAsset { - - IncludedAsset(uint8_t* start, uint8_t* end) : array(reinterpret_cast*>(start)) { - array->klass = nullptr; - array->monitor = nullptr; - array->bounds = nullptr; - array->max_length = end - start - 33; - *(end - 1)= '\0'; - } - - operator ArrayW() const { - init(); - return array; - } - - Array* Raw() const { - init(); - return array; - } - - operator std::string_view() const { - return { reinterpret_cast(array->values), array->Length() }; - } - - operator std::span() const { - return { array->values, array->Length() }; - } - - void init() const { - if(!array->klass) - array->klass = classof(Array*); - } - - private: - Array* array; - -}; - -#define DECLARE_FILE(name) \ - extern "C" uint8_t _binary_##name##_start[]; \ - extern "C" uint8_t _binary_##name##_end[]; \ - const IncludedAsset name { _binary_##name##_start, _binary_##name##_end}; - -namespace IncludedAssets { - - DECLARE_FILE(ChatPlexLogoLoading_webp) - DECLARE_FILE(ChatPlexLogoTransparent_png) - DECLARE_FILE(DefaultPackCover_png) - DECLARE_FILE(Heart_png) - DECLARE_FILE(NJS_png) - DECLARE_FILE(Offset_png) - DECLARE_FILE(QuestFonts_bundle) - DECLARE_FILE(UIButton_png) - DECLARE_FILE(UIColorPickerFBG_png) - DECLARE_FILE(UIColorPickerHBG_png) - DECLARE_FILE(UIColorPickerSBG_png) - DECLARE_FILE(UIColorPickerVBG_png) - DECLARE_FILE(UIDownArrow_png) - DECLARE_FILE(UIIconGear_png) - DECLARE_FILE(UIIconLocked_png) - DECLARE_FILE(UIIconUnlocked_png) - DECLARE_FILE(UIRectBG_png) - DECLARE_FILE(UIRoundBG_png) - DECLARE_FILE(UIRoundRectLeftBG_png) - DECLARE_FILE(UIRoundRectRightBG_png) - DECLARE_FILE(UIRoundSmoothFrame_png) - DECLARE_FILE(UISliderBG_png) - DECLARE_FILE(UISliderHandle_png) - -} +#include "kaleb/shared/kaleb.hpp" + +DECLARE_FILE(_binary_ChatPlexLogoLoading_webp, Assets, ChatPlexLogoLoading_webp); +DECLARE_FILE(_binary_ChatPlexLogoTransparent_png, Assets, ChatPlexLogoTransparent_png); +DECLARE_FILE(_binary_DefaultPackCover_png, Assets, DefaultPackCover_png); +DECLARE_FILE(_binary_Heart_png, Assets, Heart_png); +DECLARE_FILE(_binary_NJS_png, Assets, NJS_png); +DECLARE_FILE(_binary_Offset_png, Assets, Offset_png); +DECLARE_FILE(_binary_QuestFonts_bundle, Assets, QuestFonts_bundle); +DECLARE_FILE(_binary_UIButton_png, Assets, UIButton_png); +DECLARE_FILE(_binary_UIColorPickerFBG_png, Assets, UIColorPickerFBG_png); +DECLARE_FILE(_binary_UIColorPickerHBG_png, Assets, UIColorPickerHBG_png); +DECLARE_FILE(_binary_UIColorPickerSBG_png, Assets, UIColorPickerSBG_png); +DECLARE_FILE(_binary_UIColorPickerVBG_png, Assets, UIColorPickerVBG_png); +DECLARE_FILE(_binary_UIDownArrow_png, Assets, UIDownArrow_png); +DECLARE_FILE(_binary_UIIconGear_png, Assets, UIIconGear_png); +DECLARE_FILE(_binary_UIIconLocked_png, Assets, UIIconLocked_png); +DECLARE_FILE(_binary_UIIconUnlocked_png, Assets, UIIconUnlocked_png); +DECLARE_FILE(_binary_UIRectBG_png, Assets, UIRectBG_png); +DECLARE_FILE(_binary_UIRoundBG_png, Assets, UIRoundBG_png); +DECLARE_FILE(_binary_UIRoundRectLeftBG_png, Assets, UIRoundRectLeftBG_png); +DECLARE_FILE(_binary_UIRoundRectRightBG_png, Assets, UIRoundRectRightBG_png); +DECLARE_FILE(_binary_UIRoundSmoothFrame_png, Assets, UIRoundSmoothFrame_png); +DECLARE_FILE(_binary_UISliderBG_png, Assets, UISliderBG_png); +DECLARE_FILE(_binary_UISliderHandle_png, Assets, UISliderHandle_png); diff --git a/include/main.hpp b/include/main.hpp index 725a611..af1fe18 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -1,7 +1,7 @@ #pragma once // Include the modloader header, which allows us to tell the modloader which mod this is, and the version etc. -#include "modloader/shared/modloader.hpp" +#include "scotland2/shared/modloader.h" // beatsaber-hook is a modding framework that lets us call functions and fetch field values from in the game // It also allows creating objects, configuration, and importantly, hooking methods to modify their values diff --git a/mod.json b/mod.json index a58ef47..d2f9cfd 100644 --- a/mod.json +++ b/mod.json @@ -1,40 +1,42 @@ { - "_QPVersion": "0.1.2", + "_QPVersion": "0.1.1", "name": "ChatPlexSDK-BS", "id": "chatplex-sdk-bs", + "modloader": "Scotland2", "author": "HardCPP", - "version": "6.2.0", + "version": "6.3.0", "packageId": "com.beatgames.beatsaber", - "packageVersion": "1.28.0_4124311467", + "packageVersion": "1.35.0_8016709773", "description": "ChatPlex BeatSaber modding SDK (Dependence for other mods)", "coverImage": "cover.png", "dependencies": [ { - "version": "^0.33.0", - "id": "codegen", - "downloadIfMissing": "https://github.com/sc2ad/BeatSaber-Quest-Codegen/releases/download/v0.33.0/Codegen.qmod" - }, - { - "version": "^0.15.24", + "version": "^0.17.6", "id": "custom-types", - "downloadIfMissing": "https://github.com/sc2ad/Il2CppQuestTypePatching/releases/download/v0.15.24/CustomTypes.qmod" + "downloadIfMissing": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.7/CustomTypes.qmod" }, { - "version": "^0.3.1", + "version": "^0.4.20", "id": "bsml", - "downloadIfMissing": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.3.3/BSML.qmod" + "downloadIfMissing": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.31/BSML.qmod" + }, + { + "version": "=1.1.4", + "id": "songcore", + "downloadIfMissing": "https://github.com/raineio/Quest-SongCore/releases/download/v1.1.4/SongCore.qmod" }, { - "version": "^0.10.17", - "id": "songloader", - "downloadIfMissing": "https://github.com/darknight1050/SongLoader/releases/download/v0.10.17/SongLoader.qmod" + "version": "^3.6.3", + "id": "paper", + "downloadIfMissing": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.3/paperlog.qmod" } ], - "modFiles": [ + "modFiles": [], + "lateModFiles": [ "libchatplex-sdk-bs.so" ], "libraryFiles": [ - "libbeatsaber-hook_3_14_0.so" + "libbeatsaber-hook_5_1_6.so" ], "fileCopies": [], "copyExtensions": [] diff --git a/mod.template.json b/mod.template.json index 1836945..6b636a6 100644 --- a/mod.template.json +++ b/mod.template.json @@ -1,12 +1,12 @@ { "$schema": "https://raw.githubusercontent.com/Lauriethefish/QuestPatcher.QMod/main/QuestPatcher.QMod/Resources/qmod.schema.json", - "_QPVersion": "0.1.2", + "_QPVersion": "0.1.1", "name": "${mod_name}", "id": "${mod_id}", "author": "HardCPP", "version": "${version}", "packageId": "com.beatgames.beatsaber", - "packageVersion": "1.28.0_4124311467", + "packageVersion": "1.35.0_8016709773", "description": "ChatPlex BeatSaber modding SDK (Dependence for other mods)", "coverImage": "cover.png", "dependencies": [], diff --git a/qpm.json b/qpm.json index 9060786..b9d56db 100644 --- a/qpm.json +++ b/qpm.json @@ -1,91 +1,101 @@ { + "version": "0.1.0", "sharedDir": "shared", "dependenciesDir": "extern", "info": { "name": "ChatPlexSDK-BS", "id": "chatplex-sdk-bs", - "version": "6.2.0", + "version": "6.3.0", "url": "https://github.com/hardcpp/QuestChatPlexSDK-BS", "additionalData": { "overrideSoName": "libchatplex-sdk-bs.so", "cmake": true } }, + "workspace": { + "scripts": { + "build": [ + "pwsh ./build.ps1" + ], + "clean": [ + "pwsh ./build.ps1 -clean" + ], + "copy": [ + "pwsh ./copy.ps1" + ], + "log": [ + "pwsh ./start-logging.ps1" + ], + "qmod": [ + "pwsh ./build.ps1 -clean", + "pwsh ./createqmod.ps1 -clean" + ], + "qmod_backup": [ + "pwsh ./build.ps1 -clean", + "qpm qmod build", + "pwsh ./createqmod.ps1 -clean" + ] + } + }, "dependencies": [ { "id": "beatsaber-hook", - "versionRange": "^3.14.0", - "additionalData": { - "extraFiles": [ - "src/inline-hook" - ] - } + "versionRange": "^5.1.6", + "additionalData": {} }, { - "id": "codegen", - "versionRange": "^0.33.0", + "id": "bs-cordl", + "versionRange": "^3500.0.0", "additionalData": {} }, { "id": "custom-types", - "versionRange": "^0.15.24", + "versionRange": "^0.17.6", "additionalData": {} }, { - "id": "modloader", - "versionRange": "^1.2.3", - "additionalData": {} + "id": "scotland2", + "versionRange": "^0.1.4", + "additionalData": { + "includeQmod": false, + "private": true + } }, { "id": "bsml", - "versionRange": "^0.3.1", + "versionRange": "^0.4.20", "additionalData": { "private": true } }, { "id": "libil2cpp", - "versionRange": "^0.2.3", + "versionRange": "^0.3.1", "additionalData": {} }, { - "id": "songloader", - "versionRange": "^0.10.17", + "id": "songcore", + "versionRange": "=1.1.4", "additionalData": { "private": true } }, { "id": "conditional-dependencies", - "versionRange": "*", + "versionRange": "^0.3.0", "additionalData": { "private": true } + }, + { + "id": "paper", + "versionRange": "^3.6.3", + "additionalData": {} + }, + { + "id": "kaleb", + "versionRange": "^0.1.9", + "additionalData": {} } - ], - "workspace": { - "scripts": { - "copy": [ - "pwsh ./copy.ps1" - ], - "build": [ - "pwsh ./build.ps1" - ], - "log": [ - "pwsh ./start-logging.ps1" - ], - "clean": [ - "pwsh ./build.ps1 -clean" - ], - "qmod": [ - "pwsh ./build.ps1 -clean", - "pwsh ./createqmod.ps1 -clean" - ], - "qmod_backup": [ - "pwsh ./build.ps1 -clean", - "qpm qmod build", - "pwsh ./createqmod.ps1 -clean" - ] - } - } + ] } \ No newline at end of file diff --git a/qpm.shared.json b/qpm.shared.json index 90450b3..438c6b8 100644 --- a/qpm.shared.json +++ b/qpm.shared.json @@ -1,222 +1,281 @@ { "config": { + "version": "0.1.0", "sharedDir": "shared", "dependenciesDir": "extern", "info": { "name": "ChatPlexSDK-BS", "id": "chatplex-sdk-bs", - "version": "6.2.0", + "version": "6.3.0", "url": "https://github.com/hardcpp/QuestChatPlexSDK-BS", "additionalData": { "overrideSoName": "libchatplex-sdk-bs.so", "cmake": true } }, + "workspace": { + "scripts": { + "build": [ + "pwsh ./build.ps1" + ], + "clean": [ + "pwsh ./build.ps1 -clean" + ], + "copy": [ + "pwsh ./copy.ps1" + ], + "log": [ + "pwsh ./start-logging.ps1" + ], + "qmod": [ + "pwsh ./build.ps1 -clean", + "pwsh ./createqmod.ps1 -clean" + ], + "qmod_backup": [ + "pwsh ./build.ps1 -clean", + "qpm qmod build", + "pwsh ./createqmod.ps1 -clean" + ] + }, + "qmodIncludeDirs": [], + "qmodIncludeFiles": [], + "qmodOutput": null + }, "dependencies": [ { "id": "beatsaber-hook", - "versionRange": "^3.14.0", - "additionalData": { - "extraFiles": [ - "src/inline-hook" - ] - } + "versionRange": "^5.1.6", + "additionalData": {} }, { - "id": "codegen", - "versionRange": "^0.33.0", + "id": "bs-cordl", + "versionRange": "^3500.0.0", "additionalData": {} }, { "id": "custom-types", - "versionRange": "^0.15.24", + "versionRange": "^0.17.6", "additionalData": {} }, { - "id": "modloader", - "versionRange": "^1.2.3", - "additionalData": {} + "id": "scotland2", + "versionRange": "^0.1.4", + "additionalData": { + "includeQmod": false, + "private": true + } }, { "id": "bsml", - "versionRange": "^0.3.1", + "versionRange": "^0.4.20", "additionalData": { "private": true } }, { "id": "libil2cpp", - "versionRange": "^0.2.3", + "versionRange": "^0.3.1", "additionalData": {} }, { - "id": "songloader", - "versionRange": "^0.10.17", + "id": "songcore", + "versionRange": "=1.1.4", "additionalData": { "private": true } }, { "id": "conditional-dependencies", - "versionRange": "*", + "versionRange": "^0.3.0", "additionalData": { "private": true } + }, + { + "id": "paper", + "versionRange": "^3.6.3", + "additionalData": {} + }, + { + "id": "kaleb", + "versionRange": "^0.1.9", + "additionalData": {} } - ], - "workspace": { - "scripts": { - "build": [ - "pwsh ./build.ps1" - ], - "clean": [ - "pwsh ./build.ps1 -clean" - ], - "copy": [ - "pwsh ./copy.ps1" - ], - "log": [ - "pwsh ./start-logging.ps1" - ], - "qmod": [ - "pwsh ./build.ps1 -clean", - "pwsh ./createqmod.ps1 -clean" - ], - "qmod_backup": [ - "pwsh ./build.ps1 -clean", - "qpm qmod build", - "pwsh ./createqmod.ps1 -clean" - ] - } - } + ] }, "restoredDependencies": [ { "dependency": { - "id": "bsml", - "versionRange": "=0.3.3", + "id": "paper", + "versionRange": "=3.6.3", "additionalData": { - "soLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.3.3/libbsml.so", - "debugSoLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.3.3/debug_libbsml.so", - "overrideSoName": "libbsml.so", - "modLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.3.3/BSML.qmod", - "branchName": "version-v0.3.3" + "soLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.3/libpaperlog.so", + "debugSoLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.3/debug_libpaperlog.so", + "overrideSoName": "libpaperlog.so", + "modLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.3/paperlog.qmod", + "branchName": "version/v3_6_3", + "compileOptions": { + "systemIncludes": [ + "shared/utfcpp/source" + ] + }, + "cmake": false } }, - "version": "0.3.3" + "version": "3.6.3" }, { "dependency": { "id": "libil2cpp", - "versionRange": "=0.2.3", + "versionRange": "=0.3.2", "additionalData": { - "headersOnly": true + "headersOnly": true, + "cmake": false } }, - "version": "0.2.3" + "version": "0.3.2" }, { "dependency": { - "id": "modloader", - "versionRange": "=1.2.3", + "id": "bsml", + "versionRange": "=0.4.31", "additionalData": { - "soLink": "https://github.com/sc2ad/QuestLoader/releases/download/v1.2.3/libmodloader64.so", - "overrideSoName": "libmodloader.so", - "branchName": "version-v1.2.3" + "soLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.31/libbsml.so", + "debugSoLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.31/debug_libbsml.so", + "overrideSoName": "libbsml.so", + "modLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.31/BSML.qmod", + "branchName": "version/v0_4_31", + "cmake": true } }, - "version": "1.2.3" + "version": "0.4.31" }, { "dependency": { - "id": "songloader", - "versionRange": "=0.10.17", + "id": "custom-types", + "versionRange": "=0.17.7", "additionalData": { - "soLink": "https://github.com/darknight1050/SongLoader/releases/download/v0.10.17/libsongloader.so", - "debugSoLink": "https://github.com/darknight1050/SongLoader/releases/download/v0.10.17/debug_libsongloader.so", - "overrideSoName": "libsongloader.so", - "modLink": "https://github.com/darknight1050/SongLoader/releases/download/v0.10.17/SongLoader.qmod", - "branchName": "version-v0.10.17" + "soLink": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.7/libcustom-types.so", + "debugSoLink": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.7/debug_libcustom-types.so", + "overrideSoName": "libcustom-types.so", + "modLink": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.7/CustomTypes.qmod", + "branchName": "version/v0_17_7", + "compileOptions": { + "cppFlags": [ + "-Wno-invalid-offsetof" + ] + }, + "cmake": true } }, - "version": "0.10.17" + "version": "0.17.7" }, { "dependency": { - "id": "custom-types", - "versionRange": "=0.15.24", + "id": "kaleb", + "versionRange": "=0.1.9", "additionalData": { - "soLink": "https://github.com/sc2ad/Il2CppQuestTypePatching/releases/download/v0.15.24/libcustom-types.so", - "debugSoLink": "https://github.com/sc2ad/Il2CppQuestTypePatching/releases/download/v0.15.24/debug_libcustom-types.so", - "overrideSoName": "libcustom-types.so", - "modLink": "https://github.com/sc2ad/Il2CppQuestTypePatching/releases/download/v0.15.24/CustomTypes.qmod", - "branchName": "version-v0.15.24" + "headersOnly": true, + "branchName": "version/v0_1_9", + "compileOptions": { + "cppFlags": [ + "-DKALEB_VERSION=\"0.1.9\"" + ] + }, + "cmake": false } }, - "version": "0.15.24" + "version": "0.1.9" }, { "dependency": { - "id": "paper", - "versionRange": "=1.2.14", + "id": "bs-cordl", + "versionRange": "=3500.0.0", "additionalData": { - "soLink": "https://github.com/Fernthedev/paperlog/releases/download/v1.2.14/libpaperlog.so", - "debugSoLink": "https://github.com/Fernthedev/paperlog/releases/download/v1.2.14/debug_libpaperlog.so", - "overrideSoName": "libpaperlog.so", - "modLink": "https://github.com/Fernthedev/paperlog/releases/download/v1.2.14/paperlog.qmod", - "branchName": "version/v1_2_14" + "headersOnly": true, + "branchName": "version/v3500_0_0", + "compileOptions": { + "includePaths": [ + "include" + ], + "cppFeatures": [], + "cppFlags": [ + "-DNEED_UNSAFE_CSHARP", + "-fdeclspec", + "-DUNITY_2021", + "-DHAS_CODEGEN" + ] + } } }, - "version": "1.2.14" + "version": "3500.0.0" }, { "dependency": { - "id": "gif-lib", - "versionRange": "=5.2.2", + "id": "conditional-dependencies", + "versionRange": "=0.3.0", "additionalData": { - "staticLinking": true, - "soLink": "https://github.com/RedBrumbler/gif-lib-QPM/releases/download/v5.2.2/libgif-lib.a", - "debugSoLink": "https://github.com/RedBrumbler/gif-lib-QPM/releases/download/v5.2.2/debug_libgif-lib.a", - "overrideSoName": "libgif-lib.a", - "branchName": "version-v5.2.2" + "headersOnly": true, + "branchName": "version/v0_3_0", + "cmake": false } }, - "version": "5.2.2" + "version": "0.3.0" }, { "dependency": { - "id": "conditional-dependencies", - "versionRange": "=0.1.0", + "id": "songcore", + "versionRange": "=1.1.4", "additionalData": { - "headersOnly": true + "soLink": "https://github.com/raineio/Quest-SongCore/releases/download/v1.1.4/libsongcore.so", + "debugSoLink": "https://github.com/raineio/Quest-SongCore/releases/download/v1.1.4/debug_libsongcore.so", + "overrideSoName": "libsongcore.so", + "modLink": "https://github.com/raineio/Quest-SongCore/releases/download/v1.1.4/SongCore.qmod", + "branchName": "version/v1_1_4" } }, - "version": "0.1.0" + "version": "1.1.4" }, { "dependency": { "id": "beatsaber-hook", - "versionRange": "=3.14.0", + "versionRange": "=5.1.6", "additionalData": { - "soLink": "https://github.com/sc2ad/beatsaber-hook/releases/download/v3.14.0/libbeatsaber-hook_3_14_0.so", - "debugSoLink": "https://github.com/sc2ad/beatsaber-hook/releases/download/v3.14.0/debug_libbeatsaber-hook_3_14_0.so", - "branchName": "version-v3.14.0" + "soLink": "https://github.com/QuestPackageManager/beatsaber-hook/releases/download/v5.1.6/libbeatsaber-hook_5_1_6.so", + "debugSoLink": "https://github.com/QuestPackageManager/beatsaber-hook/releases/download/v5.1.6/debug_libbeatsaber-hook_5_1_6.so", + "branchName": "version/v5_1_6", + "cmake": true } }, - "version": "3.14.0" + "version": "5.1.6" }, { "dependency": { - "id": "codegen", - "versionRange": "=0.33.0", + "id": "scotland2", + "versionRange": "=0.1.4", "additionalData": { - "soLink": "https://github.com/sc2ad/BeatSaber-Quest-Codegen/releases/download/v0.33.0/libcodegen.so", - "overrideSoName": "libcodegen.so", - "modLink": "https://github.com/sc2ad/BeatSaber-Quest-Codegen/releases/download/v0.33.0/Codegen.qmod", - "branchName": "version-v0.33.0" + "soLink": "https://github.com/sc2ad/scotland2/releases/download/v0.1.4/libsl2.so", + "debugSoLink": "https://github.com/sc2ad/scotland2/releases/download/v0.1.4/debug_libsl2.so", + "overrideSoName": "libsl2.so", + "branchName": "version/v0_1_4" } }, - "version": "0.33.0" + "version": "0.1.4" + }, + { + "dependency": { + "id": "tinyxml2", + "versionRange": "=10.0.0", + "additionalData": { + "soLink": "https://github.com/MillzyDev/NDK-tinyxml2/releases/download/v10.0.0/libtinyxml2.so", + "debugSoLink": "https://github.com/MillzyDev/NDK-tinyxml2/releases/download/v10.0.0/debug_libtinyxml2.so", + "overrideSoName": "libtinyxml2.so", + "modLink": "https://github.com/MillzyDev/NDK-tinyxml2/releases/download/v10.0.0/tinyxml2.qmod", + "branchName": "version/v10_0_0", + "cmake": true + } + }, + "version": "10.0.0" }, { "dependency": { @@ -236,20 +295,6 @@ } }, "version": "10.0.0" - }, - { - "dependency": { - "id": "tinyxml2", - "versionRange": "=9.0.5", - "additionalData": { - "soLink": "https://github.com/MillzyDev/NDK-tinyxml2/releases/download/v9.0.5/libtinyxml2.so", - "debugSoLink": "https://github.com/MillzyDev/NDK-tinyxml2/releases/download/v9.0.5/debug_libtinyxml2.so", - "overrideSoName": "libtinyxml2.so", - "modLink": "https://github.com/MillzyDev/NDK-tinyxml2/releases/download/v9.0.5/tinyxml2.qmod", - "branchName": "version-v9.0.5" - } - }, - "version": "9.0.5" } ] } \ No newline at end of file diff --git a/shared/CP_SDK/Animation/AnimationControllerInstance.hpp b/shared/CP_SDK/Animation/AnimationControllerInstance.hpp index ce7f679..6493b48 100644 --- a/shared/CP_SDK/Animation/AnimationControllerInstance.hpp +++ b/shared/CP_SDK/Animation/AnimationControllerInstance.hpp @@ -25,7 +25,7 @@ namespace CP_SDK::Animation { } /// @brief Animation controller data object - class AnimationControllerInstance + class CP_SDK_EXPORT_VISIBILITY AnimationControllerInstance { CP_SDK_NO_COPYMOVE_CTORS(AnimationControllerInstance); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK/Animation/AnimationInfo.hpp b/shared/CP_SDK/Animation/AnimationInfo.hpp index fb3fabb..667b142 100644 --- a/shared/CP_SDK/Animation/AnimationInfo.hpp +++ b/shared/CP_SDK/Animation/AnimationInfo.hpp @@ -1,6 +1,7 @@ #pragma once #include "../Utils/Il2cpp.hpp" +#include "../Utils/MonoPtr.hpp" #include #include @@ -16,8 +17,13 @@ namespace CP_SDK::Animation { using namespace UnityEngine; } + namespace _v + { + using namespace CP_SDK::Utils; + } + /// @brief Animation frame info - class AnimationInfo + class CP_SDK_EXPORT_VISIBILITY AnimationInfo { CP_SDK_NO_COPYMOVE_CTORS(AnimationInfo); CP_SDK_PRIV_TAG(); @@ -26,10 +32,10 @@ namespace CP_SDK::Animation { using Ptr = std::shared_ptr; public: - int32_t Width; - int32_t Height; - std::vector<_u::Color32*> Frames; - std::vector Delays; + int32_t Width; + int32_t Height; + std::vector<_v::MonoPtr>> Frames; + std::vector Delays; public: /// @brief Constructor diff --git a/shared/CP_SDK/Animation/AnimationLoader.hpp b/shared/CP_SDK/Animation/AnimationLoader.hpp index 2bc4110..2ce420a 100644 --- a/shared/CP_SDK/Animation/AnimationLoader.hpp +++ b/shared/CP_SDK/Animation/AnimationLoader.hpp @@ -31,7 +31,7 @@ namespace CP_SDK::Animation { }; /// @brief Animation loader - class AnimationLoader + class CP_SDK_EXPORT_VISIBILITY AnimationLoader { CP_SDK_NO_DEF_CTORS(AnimationLoader); diff --git a/shared/CP_SDK/Animation/WEBP/WEBPDecoder.hpp b/shared/CP_SDK/Animation/WEBP/WEBPDecoder.hpp index 9d69aab..831c237 100644 --- a/shared/CP_SDK/Animation/WEBP/WEBPDecoder.hpp +++ b/shared/CP_SDK/Animation/WEBP/WEBPDecoder.hpp @@ -19,7 +19,7 @@ namespace CP_SDK::Animation::WEBP { } /// @brief WEBP decoder - class WEBPDecoder + class CP_SDK_EXPORT_VISIBILITY WEBPDecoder { CP_SDK_NO_DEF_CTORS(WEBPDecoder); diff --git a/shared/CP_SDK/Chat/Service.hpp b/shared/CP_SDK/Chat/Service.hpp index d36137f..c912274 100644 --- a/shared/CP_SDK/Chat/Service.hpp +++ b/shared/CP_SDK/Chat/Service.hpp @@ -4,7 +4,7 @@ namespace CP_SDK::Chat { - class Service + class CP_SDK_EXPORT_VISIBILITY Service { CP_SDK_NO_DEF_CTORS(Service); diff --git a/shared/CP_SDK/ChatPlexSDK.hpp b/shared/CP_SDK/ChatPlexSDK.hpp index e574f27..2e5e66d 100644 --- a/shared/CP_SDK/ChatPlexSDK.hpp +++ b/shared/CP_SDK/ChatPlexSDK.hpp @@ -24,7 +24,7 @@ namespace CP_SDK { }; /// ChatPlex SDK main class - class ChatPlexSDK + class CP_SDK_EXPORT_VISIBILITY ChatPlexSDK { CP_SDK_NO_DEF_CTORS(ChatPlexSDK); diff --git a/shared/CP_SDK/Logging/BMBFLogger.hpp b/shared/CP_SDK/Logging/PaperLogger.hpp similarity index 63% rename from shared/CP_SDK/Logging/BMBFLogger.hpp rename to shared/CP_SDK/Logging/PaperLogger.hpp index 6eacad2..a0246d9 100644 --- a/shared/CP_SDK/Logging/BMBFLogger.hpp +++ b/shared/CP_SDK/Logging/PaperLogger.hpp @@ -4,18 +4,20 @@ #include +#include "paper/shared/logger.hpp" + namespace CP_SDK::Logging { - /// @brief BMBF Logger - class BMBFLogger : public ILogger + /// @brief Paper Logger + class PaperLogger : public ILogger { public: /// @brief Constructor - /// @param p_BMBFLogger BMBF logger instance - BMBFLogger(Logger* p_BMBFLogger); + /// @param p_Name Paper Logger name + PaperLogger(const std::string& p_Name); - /// @brief Get BMBF Logger - Logger* GetBMBFLogger() const { return m_BMBFLogger; } + /// @brief Get Paper Logger + Paper::LoggerContext* GetPaperLogger() const { return m_PaperLogger; } protected: /// @brief Log implementation @@ -28,7 +30,7 @@ namespace CP_SDK::Logging { void LogImplementation(ELogType p_Type, const std::exception& p_Data) override; private: - Logger* m_BMBFLogger; ///< BMBF logger instance + Paper::LoggerContext* m_PaperLogger; ///< Paper logger instance }; diff --git a/shared/CP_SDK/Misc/FastCancellationToken.hpp b/shared/CP_SDK/Misc/FastCancellationToken.hpp index fb7494f..b2d8238 100644 --- a/shared/CP_SDK/Misc/FastCancellationToken.hpp +++ b/shared/CP_SDK/Misc/FastCancellationToken.hpp @@ -8,7 +8,7 @@ namespace CP_SDK::Misc { /// @brief Fast cancellation token - class FastCancellationToken + class CP_SDK_EXPORT_VISIBILITY FastCancellationToken { CP_SDK_NO_DEF_CTORS(FastCancellationToken); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK/Misc/Time.hpp b/shared/CP_SDK/Misc/Time.hpp index 740777b..a5d412c 100644 --- a/shared/CP_SDK/Misc/Time.hpp +++ b/shared/CP_SDK/Misc/Time.hpp @@ -29,7 +29,7 @@ namespace CP_SDK::Misc { }; /// @brief Time helper - class Time + class CP_SDK_EXPORT_VISIBILITY Time { CP_SDK_NO_DEF_CTORS(Time); diff --git a/shared/CP_SDK/Network/WebClientUnity.hpp b/shared/CP_SDK/Network/WebClientUnity.hpp index 6745822..5357c39 100644 --- a/shared/CP_SDK/Network/WebClientUnity.hpp +++ b/shared/CP_SDK/Network/WebClientUnity.hpp @@ -22,7 +22,7 @@ namespace CP_SDK::Network { } /// @brief WebClientUnity using unity web requests - class WebClientUnity : public IWebClient, public std::enable_shared_from_this + class CP_SDK_EXPORT_VISIBILITY WebClientUnity : public IWebClient, public std::enable_shared_from_this { CP_SDK_NO_COPYMOVE_CTORS(WebClientUnity); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK/Network/WebContent.hpp b/shared/CP_SDK/Network/WebContent.hpp index 7e7b063..e98ff09 100644 --- a/shared/CP_SDK/Network/WebContent.hpp +++ b/shared/CP_SDK/Network/WebContent.hpp @@ -14,7 +14,7 @@ namespace CP_SDK::Network { } /// @brief WebContent - class WebContent + class CP_SDK_EXPORT_VISIBILITY WebContent { CP_SDK_NO_COPYMOVE_CTORS(WebContent); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK/UI/Components/CFLayout.hpp b/shared/CP_SDK/UI/Components/CFLayout.hpp index 01dd7f7..84065dd 100644 --- a/shared/CP_SDK/UI/Components/CFLayout.hpp +++ b/shared/CP_SDK/UI/Components/CFLayout.hpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include namespace CP_SDK::UI::Components { diff --git a/shared/CP_SDK/UI/Data/ListCellPrefabs.hpp b/shared/CP_SDK/UI/Data/ListCellPrefabs.hpp index ed5412a..dc4f28d 100644 --- a/shared/CP_SDK/UI/Data/ListCellPrefabs.hpp +++ b/shared/CP_SDK/UI/Data/ListCellPrefabs.hpp @@ -19,7 +19,7 @@ namespace CP_SDK::UI::Data { /// @brief List cell prefabs getter /// @tparam t_ListCellType List cell type template - class ListCellPrefabs + class CP_SDK_EXPORT_VISIBILITY ListCellPrefabs { private: static _v::MonoPtr m_Prefab; @@ -35,8 +35,8 @@ namespace CP_SDK::UI::Data { return m_Prefab.Ptr(); m_Prefab = _u::GameObject::New_ctor(std::string(classof(t_ListCellType*)->name) + "ListCellPrefab", ArrayW<_u::Type*>({ - reinterpret_cast<_u::Type*>(csTypeOf(_u::RectTransform*)), - reinterpret_cast<_u::Type*>(csTypeOf(t_ListCellType*)) + reinterpret_cast<_u::Type*>(csTypeOf(_u::RectTransform*).convert()), + reinterpret_cast<_u::Type*>(csTypeOf(t_ListCellType*).convert()) }))->GetComponent(); _u::GameObject::DontDestroyOnLoad(m_Prefab->get_gameObject()); diff --git a/shared/CP_SDK/UI/Data/TextListItem.hpp b/shared/CP_SDK/UI/Data/TextListItem.hpp index 4d7d8c6..705e96a 100644 --- a/shared/CP_SDK/UI/Data/TextListItem.hpp +++ b/shared/CP_SDK/UI/Data/TextListItem.hpp @@ -7,7 +7,7 @@ namespace CP_SDK::UI::Data { /// @brief Abstract List Item - class TextListItem : public IListItem + class CP_SDK_EXPORT_VISIBILITY TextListItem : public IListItem { CP_SDK_NO_DEF_CTORS(TextListItem); diff --git a/shared/CP_SDK/UI/DefaultComponents/DefaultCFLayout.hpp b/shared/CP_SDK/UI/DefaultComponents/DefaultCFLayout.hpp index 5c0d3c1..bd348d5 100644 --- a/shared/CP_SDK/UI/DefaultComponents/DefaultCFLayout.hpp +++ b/shared/CP_SDK/UI/DefaultComponents/DefaultCFLayout.hpp @@ -2,6 +2,8 @@ #include "../Components/CFLayout.hpp" #include "../../Utils/Event.hpp" +#include +#include namespace CP_SDK::UI::DefaultComponents { diff --git a/shared/CP_SDK/UI/DefaultComponents/DefaultCSlider.hpp b/shared/CP_SDK/UI/DefaultComponents/DefaultCSlider.hpp index f3dc3dc..f0fe47a 100644 --- a/shared/CP_SDK/UI/DefaultComponents/DefaultCSlider.hpp +++ b/shared/CP_SDK/UI/DefaultComponents/DefaultCSlider.hpp @@ -5,6 +5,10 @@ #include "../Components/Generics/CPOrSButton.hpp" #include "../../Utils/Event.hpp" +#include +#include +#include +#include #include #include #include @@ -12,7 +16,7 @@ #include #include #include -#include +#include namespace CP_SDK::UI::DefaultComponents { diff --git a/shared/CP_SDK/UI/DefaultComponents/Subs/SubStackLayoutGroup.hpp b/shared/CP_SDK/UI/DefaultComponents/Subs/SubStackLayoutGroup.hpp index 932bb11..927a155 100644 --- a/shared/CP_SDK/UI/DefaultComponents/Subs/SubStackLayoutGroup.hpp +++ b/shared/CP_SDK/UI/DefaultComponents/Subs/SubStackLayoutGroup.hpp @@ -3,6 +3,8 @@ #include "../../../Utils/Il2cpp.hpp" #include +#include +#include namespace CP_SDK::UI::DefaultComponents::Subs { diff --git a/shared/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.hpp b/shared/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.hpp index 189f180..10d3cf6 100644 --- a/shared/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.hpp +++ b/shared/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.hpp @@ -4,7 +4,6 @@ #include "../../../Utils/Il2cpp.hpp" #include -#include #include namespace CP_SDK::UI::DefaultComponents::Subs { diff --git a/shared/CP_SDK/UI/FlowCoordinator.hpp b/shared/CP_SDK/UI/FlowCoordinator.hpp index a82b8f6..1035fb6 100644 --- a/shared/CP_SDK/UI/FlowCoordinator.hpp +++ b/shared/CP_SDK/UI/FlowCoordinator.hpp @@ -6,6 +6,8 @@ #include +#include + #define CP_SDK_UI_FLOW_COORDINATOR_INSTANCE() public: static CP_SDK::Utils::MonoPtr<___TargetType>& Instance() { return _Instance<___TargetType>(); } #define CP_SDK_UI_FLOW_COORDINATOR_DESTROY() public: static void Destroy() { _Destroy <___TargetType>(); } @@ -22,7 +24,7 @@ namespace CP_SDK::UI { } /// @brief Flow coordinator base class - class FlowCoordinator : public IFlowCoordinator + class CP_SDK_EXPORT_VISIBILITY FlowCoordinator : public IFlowCoordinator { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI", FlowCoordinator, IFlowCoordinator); CP_SDK_IL2CPP_DECLARE_CTOR_CHILD(FlowCoordinator); @@ -35,31 +37,20 @@ namespace CP_SDK::UI { template requires(std::is_assignable_v) static _v::MonoPtr& _Instance() { - auto l_Type = reinterpret_cast<_u::Type*>(csTypeOf(t_Base*)); - if (l_Type && m_Instances.contains(l_Type)) - return *reinterpret_cast<_v::MonoPtr*>(&m_Instances[l_Type]); - - auto l_Ptr = reinterpret_cast(_u::GameObject::New_ctor("[CP_SDK.UI.FlowCoordinator<" + l_Type->get_FullName() + ">]", ArrayW<_u::Type*>({ - l_Type - }))->GetComponent(l_Type)); - _u::GameObject::DontDestroyOnLoad(l_Ptr->get_gameObject()); + auto l_Type = reinterpret_cast<_u::Type*>(csTypeOf(t_Base*).convert()); + auto& l_Ptr = _InstanceEx(l_Type); - m_Instances[l_Type] = l_Ptr; - return *reinterpret_cast<_v::MonoPtr*>(&m_Instances[l_Type]); + return *reinterpret_cast<_v::MonoPtr*>(&l_Ptr); } + static _v::MonoPtr& _InstanceEx(_u::Type* p_Type); + template requires(std::is_assignable_v) static void _Destroy() { - auto l_Type = reinterpret_cast<_u::Type*>(csTypeOf(t_Base*)); - auto l_It = m_Instances.find(l_Type); - if (!l_Type || l_It == m_Instances.end()) - return; - - if (m_Instances[l_Type]) - _u::GameObject::Destroy(m_Instances[l_Type]->get_gameObject()); - - m_Instances.erase(l_It); + auto l_Type = reinterpret_cast<_u::Type*>(csTypeOf(t_Base*).convert()); + _DestroyEx(l_Type); } + static void _DestroyEx(_u::Type* p_Type); }; diff --git a/shared/CP_SDK/UI/FlowCoordinators/MainFlowCoordinator.hpp b/shared/CP_SDK/UI/FlowCoordinators/MainFlowCoordinator.hpp index 6b033af..ad24323 100644 --- a/shared/CP_SDK/UI/FlowCoordinators/MainFlowCoordinator.hpp +++ b/shared/CP_SDK/UI/FlowCoordinators/MainFlowCoordinator.hpp @@ -16,7 +16,7 @@ namespace CP_SDK::UI::FlowCoordinators { } /// @brief UI flow coordinator - class MainFlowCoordinator : public FlowCoordinator + class CP_SDK_EXPORT_VISIBILITY MainFlowCoordinator : public FlowCoordinator { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI.FlowCoordinators", MainFlowCoordinator, FlowCoordinator); CP_SDK_IL2CPP_DECLARE_CTOR_CHILD(MainFlowCoordinator); diff --git a/shared/CP_SDK/UI/LoadingProgressBar.hpp b/shared/CP_SDK/UI/LoadingProgressBar.hpp index a58a0ad..189eb98 100644 --- a/shared/CP_SDK/UI/LoadingProgressBar.hpp +++ b/shared/CP_SDK/UI/LoadingProgressBar.hpp @@ -26,7 +26,7 @@ namespace CP_SDK::UI { } /// @brief Loading progress bar - class LoadingProgressBar : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY LoadingProgressBar : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI", LoadingProgressBar, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(LoadingProgressBar); diff --git a/shared/CP_SDK/UI/ModButton.hpp b/shared/CP_SDK/UI/ModButton.hpp index da7ad60..9dad2fb 100644 --- a/shared/CP_SDK/UI/ModButton.hpp +++ b/shared/CP_SDK/UI/ModButton.hpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI { } /// @brief Mod button - class ModButton + class CP_SDK_EXPORT_VISIBILITY ModButton { CP_SDK_NO_DEF_CTORS(ModButton); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK/UI/ModMenu.hpp b/shared/CP_SDK/UI/ModMenu.hpp index 9f51daa..3b15185 100644 --- a/shared/CP_SDK/UI/ModMenu.hpp +++ b/shared/CP_SDK/UI/ModMenu.hpp @@ -19,7 +19,7 @@ namespace CP_SDK::UI { } /// @brief Mod menu - class ModMenu : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY ModMenu : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI", ModMenu, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(ModMenu); diff --git a/shared/CP_SDK/UI/ScreenSystem.hpp b/shared/CP_SDK/UI/ScreenSystem.hpp index 6b92640..b755c6a 100644 --- a/shared/CP_SDK/UI/ScreenSystem.hpp +++ b/shared/CP_SDK/UI/ScreenSystem.hpp @@ -16,7 +16,7 @@ namespace CP_SDK::UI { } /// @brief ScreenSystem widget - class ScreenSystem : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY ScreenSystem : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI", ScreenSystem, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(ScreenSystem); diff --git a/shared/CP_SDK/UI/Tooltip.hpp b/shared/CP_SDK/UI/Tooltip.hpp index d6f4e3a..2108ed6 100644 --- a/shared/CP_SDK/UI/Tooltip.hpp +++ b/shared/CP_SDK/UI/Tooltip.hpp @@ -22,7 +22,7 @@ namespace CP_SDK::UI { } /// @brief Tooltip widget - class Tooltip : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY Tooltip : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI", Tooltip, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(Tooltip); diff --git a/shared/CP_SDK/UI/UIIl2cpp.hpp b/shared/CP_SDK/UI/UIIl2cpp.hpp index b4742d6..cb3d6a9 100644 --- a/shared/CP_SDK/UI/UIIl2cpp.hpp +++ b/shared/CP_SDK/UI/UIIl2cpp.hpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace CP_SDK::UI { @@ -32,7 +32,6 @@ namespace CP_SDK::UI { template struct UIFieldDefault { - static_assert(std::is_assignable_v); static Utils::MonoPtr Value; }; template Utils::MonoPtr UIFieldDefault::Value; diff --git a/shared/CP_SDK/UI/UISystem.hpp b/shared/CP_SDK/UI/UISystem.hpp index 5a96727..bb909e4 100644 --- a/shared/CP_SDK/UI/UISystem.hpp +++ b/shared/CP_SDK/UI/UISystem.hpp @@ -44,7 +44,7 @@ namespace CP_SDK::UI { } /// @brief UI system main class - class UISystem + class CP_SDK_EXPORT_VISIBILITY UISystem { CP_SDK_NO_DEF_CTORS(UISystem); @@ -148,7 +148,7 @@ namespace CP_SDK::UI { template requires(std::is_assignable_v) static t_ViewController CreateViewController() { - return reinterpret_cast(_CreateViewController(reinterpret_cast<_u::Type*>(csTypeOf(t_ViewController)))); + return reinterpret_cast(_CreateViewController(reinterpret_cast<_u::Type*>(csTypeOf(t_ViewController).convert()))); } static IViewController* _CreateViewController(_u::Type* p_Type); diff --git a/shared/CP_SDK/UI/ValueFormatters.hpp b/shared/CP_SDK/UI/ValueFormatters.hpp index 95f09c7..c69df7c 100644 --- a/shared/CP_SDK/UI/ValueFormatters.hpp +++ b/shared/CP_SDK/UI/ValueFormatters.hpp @@ -1,10 +1,12 @@ #pragma once +#include "../Utils/Il2cpp.hpp" + #include namespace CP_SDK::UI { - class ValueFormatters + class CP_SDK_EXPORT_VISIBILITY ValueFormatters { public: static std::u16string Percentage(float p_Value); diff --git a/shared/CP_SDK/UI/ViewController.hpp b/shared/CP_SDK/UI/ViewController.hpp index be9164d..3befc6d 100644 --- a/shared/CP_SDK/UI/ViewController.hpp +++ b/shared/CP_SDK/UI/ViewController.hpp @@ -26,7 +26,7 @@ namespace CP_SDK::UI { } /// @brief IViewController interface - class ViewController : public IViewController + class CP_SDK_EXPORT_VISIBILITY ViewController : public IViewController { CP_SDK_IL2CPP_INHERIT("CP_SDK.UI", ViewController, IViewController); CP_SDK_IL2CPP_DECLARE_CTOR_CHILD(ViewController); @@ -54,19 +54,16 @@ namespace CP_SDK::UI { template requires(std::is_assignable_v) static _v::MonoPtr& _Instance() { - auto l_Type = reinterpret_cast<_u::Type*>(csTypeOf(t_Base*)); - if (l_Type && m_Instances.contains(l_Type)) - return *reinterpret_cast<_v::MonoPtr*>(&m_Instances[l_Type]); + auto l_Type = reinterpret_cast<_u::Type*>(csTypeOf(t_Base*).convert()); + auto& l_Ptr = _InstanceEx(l_Type); - return UIFieldDefault::Value; - } - static ViewController* _Instance(_u::Type* p_Type) - { - if (p_Type && m_Instances.contains(p_Type)) - return m_Instances[p_Type].Ptr(false); + if (l_Ptr) + return *reinterpret_cast<_v::MonoPtr*>(&l_Ptr); - return nullptr; + return UIFieldDefault::Value; } + static ViewController* _Instance(_u::Type* p_Type); + static _v::MonoPtr& _InstanceEx(_u::Type* p_Type); public: /// @brief Can UI be updated @@ -108,7 +105,7 @@ namespace CP_SDK::UI { template t_ModalType* CreateModal() { - return reinterpret_cast(CreateModal_Impl(reinterpret_cast<_u::Type*>(csTypeOf(t_ModalType*)))); + return reinterpret_cast(CreateModal_Impl(reinterpret_cast<_u::Type*>(csTypeOf(t_ModalType*).convert()))); } private: diff --git a/shared/CP_SDK/Unity/EnhancedImage.hpp b/shared/CP_SDK/Unity/EnhancedImage.hpp index ef1074d..164633c 100644 --- a/shared/CP_SDK/Unity/EnhancedImage.hpp +++ b/shared/CP_SDK/Unity/EnhancedImage.hpp @@ -21,7 +21,7 @@ namespace CP_SDK::Unity { } /// @brief Enhanced image info - class EnhancedImage + class CP_SDK_EXPORT_VISIBILITY EnhancedImage { CP_SDK_NO_COPYMOVE_CTORS(EnhancedImage); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK/Unity/Extensions/ColorU.hpp b/shared/CP_SDK/Unity/Extensions/ColorU.hpp index 44dfe07..644abc6 100644 --- a/shared/CP_SDK/Unity/Extensions/ColorU.hpp +++ b/shared/CP_SDK/Unity/Extensions/ColorU.hpp @@ -15,7 +15,7 @@ namespace CP_SDK::Unity::Extensions { } /// @brief Unity Color tools - class ColorU + class CP_SDK_EXPORT_VISIBILITY ColorU { public: /// @brief Get color with alpha @@ -53,6 +53,7 @@ namespace CP_SDK::Unity::Extensions { inline static _u::Color32 Convert(_u::Color p_Src) { return _u::Color32( + 0, (uint8_t)(p_Src.r * 255.0f), (uint8_t)(p_Src.g * 255.0f), (uint8_t)(p_Src.b * 255.0f), @@ -83,7 +84,7 @@ namespace CP_SDK::Unity::Extensions { if ((l_Length - l_Offset) > 6) l_A = (ConvertSingleByte(p_Src, l_Length, l_Offset + 6) << 4) | ConvertSingleByte(p_Src, l_Length, l_Offset + 7); - *p_Color = Convert(_u::Color32((uint8_t)l_R, (uint8_t)l_G, (uint8_t)l_B, (uint8_t)l_A)); + *p_Color = Convert(_u::Color32(0, (uint8_t)l_R, (uint8_t)l_G, (uint8_t)l_B, (uint8_t)l_A)); return true; } diff --git a/shared/CP_SDK/Unity/Extensions/GameObjectU.hpp b/shared/CP_SDK/Unity/Extensions/GameObjectU.hpp index 9fb5c37..eda4d15 100644 --- a/shared/CP_SDK/Unity/Extensions/GameObjectU.hpp +++ b/shared/CP_SDK/Unity/Extensions/GameObjectU.hpp @@ -17,7 +17,7 @@ namespace CP_SDK::Unity::Extensions { } /// @brief Unity GameObject tools - class GameObjectU + class CP_SDK_EXPORT_VISIBILITY GameObjectU { public: /// @brief Change the layer of a GameObject and all his childs @@ -34,7 +34,7 @@ namespace CP_SDK::Unity::Extensions { for (auto l_I = 0; l_I < l_ChildCount; ++l_I) { auto l_Child = p_This->get_transform()->GetChild(l_I)->get_gameObject(); - if (_v::IsUnityPtrValid(l_Child)) + if (l_Child.isAlive()) ChangerLayerRecursive(l_Child, p_Layer); } } @@ -47,10 +47,10 @@ namespace CP_SDK::Unity::Extensions { return nullptr; auto l_LeftTransform = p_Left->get_transform(); - while (_v::IsUnityPtrValid(l_LeftTransform)) + while (l_LeftTransform.isAlive()) { auto l_RightTransform = p_Right->get_transform(); - while (_v::IsUnityPtrValid(l_RightTransform)) + while (l_RightTransform.isAlive()) { if (l_LeftTransform == l_RightTransform) return l_LeftTransform->get_gameObject(); @@ -67,7 +67,7 @@ namespace CP_SDK::Unity::Extensions { /// @param p_This Instance inline static void DestroyChilds(_u::GameObject* p_This) { - if (!p_This) + if (!_v::IsUnityPtrValid(p_This)) return; auto l_ChildCount = p_This->get_transform()->get_childCount(); diff --git a/shared/CP_SDK/Unity/FontManager.hpp b/shared/CP_SDK/Unity/FontManager.hpp index 9500d75..996e3f9 100644 --- a/shared/CP_SDK/Unity/FontManager.hpp +++ b/shared/CP_SDK/Unity/FontManager.hpp @@ -20,7 +20,7 @@ namespace CP_SDK::Unity { } /// @brief Open type to TextMeshPro font manager - class FontManager + class CP_SDK_EXPORT_VISIBILITY FontManager { CP_SDK_NO_DEF_CTORS(FontManager); @@ -29,7 +29,8 @@ namespace CP_SDK::Unity { private: static bool m_IsInitialized; static _v::MonoPtr<_u::AssetBundle> m_AssetBundle; - static _v::MonoPtr<_u::TMP_FontAsset> m_BundleFont; + static _v::MonoPtr<_u::TMP_FontAsset> m_BundleMainFont; + static _v::MonoPtr<_u::TMP_FontAsset> m_BundleChatFont; static _v::MonoPtr<_u::TMP_FontAsset> m_MainFont; static _v::MonoPtr<_u::TMP_FontAsset> m_ChatFont; static _v::Func<_u::TMP_FontAsset*, _u::TMP_FontAsset*> m_TMPFontAssetSetup; diff --git a/shared/CP_SDK/Unity/MTCoroutineStarter.hpp b/shared/CP_SDK/Unity/MTCoroutineStarter.hpp index b5b3cf9..145513b 100644 --- a/shared/CP_SDK/Unity/MTCoroutineStarter.hpp +++ b/shared/CP_SDK/Unity/MTCoroutineStarter.hpp @@ -23,7 +23,7 @@ namespace CP_SDK::Unity { } /// @brief MultiThreading coroutine starter - class MTCoroutineStarter : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY MTCoroutineStarter : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.Unity", MTCoroutineStarter, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(MTCoroutineStarter); diff --git a/shared/CP_SDK/Unity/MTMainThreadInvoker.hpp b/shared/CP_SDK/Unity/MTMainThreadInvoker.hpp index 1799451..c4987a8 100644 --- a/shared/CP_SDK/Unity/MTMainThreadInvoker.hpp +++ b/shared/CP_SDK/Unity/MTMainThreadInvoker.hpp @@ -21,7 +21,7 @@ namespace CP_SDK::Unity { } /// @brief Main thread task system - class MTMainThreadInvoker : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY MTMainThreadInvoker : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.Unity", MTMainThreadInvoker, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(MTMainThreadInvoker); diff --git a/shared/CP_SDK/Unity/MTThreadInvoker.hpp b/shared/CP_SDK/Unity/MTThreadInvoker.hpp index c768059..90e7de0 100644 --- a/shared/CP_SDK/Unity/MTThreadInvoker.hpp +++ b/shared/CP_SDK/Unity/MTThreadInvoker.hpp @@ -21,7 +21,7 @@ namespace CP_SDK::Unity { } /// @brief Thread task system - class MTThreadInvoker + class CP_SDK_EXPORT_VISIBILITY MTThreadInvoker { private: /// @brief Queue class @@ -32,12 +32,12 @@ namespace CP_SDK::Unity { }; private: - static bool m_RunCondition; ///< Run condition - static _v::MonoPtr<_u::Thread> m_UpdateThread; ///< Update thread - static Queue** m_Queues; ///< Queues instance - static bool m_Queued; ///< Have queued actions - static int m_FrontQueue; ///< Current front queue - static std::mutex m_Mutex; ///< Lock mutex + static bool m_RunCondition; ///< Run condition + static il2cpp_utils::il2cpp_aware_thread* m_UpdateThread; ///< Update thread + static Queue** m_Queues; ///< Queues instance + static bool m_Queued; ///< Have queued actions + static int m_FrontQueue; ///< Current front queue + static std::mutex m_Mutex; ///< Lock mutex public: /// @brief Initialize @@ -56,20 +56,4 @@ namespace CP_SDK::Unity { }; - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - /// @brief Dummy il2cpp object for thread start - class __MTThreadInvokerDummy : public Il2CppObject - { - CP_SDK_IL2CPP_INHERIT("CP_SDK.Unity", __MTThreadInvokerDummy, Il2CppObject); - - public: - /// @brief Dummy method for thread start - DECLARE_STATIC_METHOD(void, Dummy); - - }; - -} ///< namespace CP_SDK::Unity - -CP_SDK_IL2CPP_INHERIT_HELPERS(CP_SDK::Unity::__MTThreadInvokerDummy); \ No newline at end of file +} ///< namespace CP_SDK::Unity \ No newline at end of file diff --git a/shared/CP_SDK/Unity/MonoPtrHolder.hpp b/shared/CP_SDK/Unity/MonoPtrHolder.hpp index 812df10..c78d701 100644 --- a/shared/CP_SDK/Unity/MonoPtrHolder.hpp +++ b/shared/CP_SDK/Unity/MonoPtrHolder.hpp @@ -21,7 +21,7 @@ namespace CP_SDK::Unity { } /// @brief Il2Cpp pointers holder - class MonoPtrHolder : public _u::MonoBehaviour + class CP_SDK_EXPORT_VISIBILITY MonoPtrHolder : public _u::MonoBehaviour { CP_SDK_IL2CPP_INHERIT("CP_SDK.Unity", MonoPtrHolder, _u::MonoBehaviour); CP_SDK_IL2CPP_DECLARE_CTOR(MonoPtrHolder); diff --git a/shared/CP_SDK/Unity/Operators.hpp b/shared/CP_SDK/Unity/Operators.hpp new file mode 100644 index 0000000..ce524ca --- /dev/null +++ b/shared/CP_SDK/Unity/Operators.hpp @@ -0,0 +1,125 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +constexpr System::TimeSpan operator- (const System::DateTime& p_A, const System::DateTime& p_B) +{ + return System::DateTime::op_Subtraction(p_A, p_B); +} + +constexpr bool operator> (const System::DateTime& p_A, const System::DateTime& p_B) +{ + return System::DateTime::op_GreaterThan(p_A, p_B); +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +constexpr UnityEngine::Color operator+ (const UnityEngine::Color& p_A, const UnityEngine::Color& p_B) +{ + return UnityEngine::Color::op_Addition(p_A, p_B); +} +constexpr UnityEngine::Color operator+= (UnityEngine::Color& p_A, const UnityEngine::Color& p_B) +{ + return p_A = UnityEngine::Color::op_Addition(p_A, p_B); +} + +constexpr UnityEngine::Color operator- (const UnityEngine::Color& p_A, const UnityEngine::Color& p_B) +{ + return UnityEngine::Color::op_Subtraction(p_A, p_B); +} +constexpr UnityEngine::Color operator-= (UnityEngine::Color& p_A, const UnityEngine::Color& p_B) +{ + return p_A = UnityEngine::Color::op_Subtraction(p_A, p_B); +} + +constexpr UnityEngine::Color operator* (const UnityEngine::Color& p_A, const UnityEngine::Color& p_B) +{ + return UnityEngine::Color::op_Multiply(p_A, p_B); +} +constexpr UnityEngine::Color operator* (const UnityEngine::Color& p_A, const float& p_B) +{ + return UnityEngine::Color::op_Multiply(p_A, p_B); +} +constexpr UnityEngine::Color operator* (const float& p_A, const UnityEngine::Color& p_B) +{ + return UnityEngine::Color::op_Multiply(p_A, p_B); +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +constexpr UnityEngine::Vector2 operator+ (const UnityEngine::Vector2& p_A, const UnityEngine::Vector2& p_B) +{ + return UnityEngine::Vector2::op_Addition(p_A, p_B); +} +constexpr UnityEngine::Vector2 operator+= (UnityEngine::Vector2& p_A, const UnityEngine::Vector2& p_B) +{ + return p_A = UnityEngine::Vector2::op_Addition(p_A, p_B); +} + +constexpr UnityEngine::Vector2 operator- (const UnityEngine::Vector2& p_A, const UnityEngine::Vector2& p_B) +{ + return UnityEngine::Vector2::op_Subtraction(p_A, p_B); +} +constexpr UnityEngine::Vector2 operator-= (UnityEngine::Vector2& p_A, const UnityEngine::Vector2& p_B) +{ + return p_A = UnityEngine::Vector2::op_Subtraction(p_A, p_B); +} + +constexpr UnityEngine::Vector2 operator* (const UnityEngine::Vector2& p_A, const float& p_B) +{ + return UnityEngine::Vector2::op_Multiply(p_A, p_B); +} +constexpr UnityEngine::Vector2 operator* (const float& p_A, const UnityEngine::Vector2& p_B) +{ + return UnityEngine::Vector2::op_Multiply(p_A, p_B); +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +constexpr UnityEngine::Vector3 operator+ (const UnityEngine::Vector3& p_A, const UnityEngine::Vector3& p_B) +{ + return UnityEngine::Vector3::op_Addition(p_A, p_B); +} +constexpr UnityEngine::Vector3 operator+= (UnityEngine::Vector3& p_A, const UnityEngine::Vector3& p_B) +{ + return p_A = UnityEngine::Vector3::op_Addition(p_A, p_B); +} + +constexpr UnityEngine::Vector3 operator- (const UnityEngine::Vector3& p_A, const UnityEngine::Vector3& p_B) +{ + return UnityEngine::Vector3::op_Subtraction(p_A, p_B); +} +constexpr UnityEngine::Vector3 operator-= (UnityEngine::Vector3& p_A, const UnityEngine::Vector3& p_B) +{ + return p_A = UnityEngine::Vector3::op_Subtraction(p_A, p_B); +} + +constexpr UnityEngine::Vector3 operator* (const UnityEngine::Vector3& p_A, const float& p_B) +{ + return UnityEngine::Vector3::op_Multiply(p_A, p_B); +} +constexpr UnityEngine::Vector3 operator* (const float& p_A, const UnityEngine::Vector3& p_B) +{ + return UnityEngine::Vector3::op_Multiply(p_A, p_B); +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +constexpr UnityEngine::Quaternion operator* (const UnityEngine::Quaternion& p_A, const UnityEngine::Quaternion& p_B) +{ + return UnityEngine::Quaternion::op_Multiply(p_A, p_B); +} + +constexpr UnityEngine::Vector3 operator* (const UnityEngine::Quaternion& p_A, const UnityEngine::Vector3& p_B) +{ + return UnityEngine::Quaternion::op_Multiply(p_A, p_B); +} \ No newline at end of file diff --git a/shared/CP_SDK/Unity/SpriteU.hpp b/shared/CP_SDK/Unity/SpriteU.hpp index 470a784..66eaf7e 100644 --- a/shared/CP_SDK/Unity/SpriteU.hpp +++ b/shared/CP_SDK/Unity/SpriteU.hpp @@ -20,7 +20,7 @@ namespace CP_SDK::Unity { } /// @brief Sprite helper - class SpriteU + class CP_SDK_EXPORT_VISIBILITY SpriteU { CP_SDK_NO_DEF_CTORS(SpriteU); diff --git a/shared/CP_SDK/Unity/Texture2DU.hpp b/shared/CP_SDK/Unity/Texture2DU.hpp index 60f8d85..cfddf95 100644 --- a/shared/CP_SDK/Unity/Texture2DU.hpp +++ b/shared/CP_SDK/Unity/Texture2DU.hpp @@ -17,7 +17,7 @@ namespace CP_SDK::Unity { } /// @brief Texture2D helper - class Texture2DU + class CP_SDK_EXPORT_VISIBILITY Texture2DU { CP_SDK_NO_DEF_CTORS(Texture2DU); diff --git a/shared/CP_SDK/Unity/TextureRaw.hpp b/shared/CP_SDK/Unity/TextureRaw.hpp index 85b53de..f17eca3 100644 --- a/shared/CP_SDK/Unity/TextureRaw.hpp +++ b/shared/CP_SDK/Unity/TextureRaw.hpp @@ -14,7 +14,7 @@ namespace CP_SDK::Unity { } /// @brief Texture raw utilities - class TextureRaw + class CP_SDK_EXPORT_VISIBILITY TextureRaw { CP_SDK_NO_DEF_CTORS(TextureRaw); diff --git a/shared/CP_SDK/Utils/Il2cpp.hpp b/shared/CP_SDK/Utils/Il2cpp.hpp index 585e6e7..f35981f 100644 --- a/shared/CP_SDK/Utils/Il2cpp.hpp +++ b/shared/CP_SDK/Utils/Il2cpp.hpp @@ -3,7 +3,7 @@ #define __CP_SDK_U16STR(__mX) u##__mX #define CP_SDK_U16STR(__mX) __CP_SDK_U16STR(#__mX) -#include "../Logging/BMBFLogger.hpp" +#include "../Logging/PaperLogger.hpp" #include "Internals/Il2cpp_enum.hpp" #include "Internals/il2cpp_customtype.hpp" #include "Internals/il2cpp_hook.hpp" @@ -20,6 +20,8 @@ #include #include +#define CP_SDK_EXPORT_VISIBILITY CUSTOM_TYPES_EXPORT_VISIBILITY + //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -40,18 +42,18 @@ namespace CP_SDK::Utils { /// @brief Hook manager - class Hooks + class CP_SDK_EXPORT_VISIBILITY Hooks { CP_SDK_NO_DEF_CTORS(Hooks); private: /// @brief Registered hooks - static std::vector m_InstalledFuncs; + static std::vector m_InstalledFuncs; public: /// @brief Register a hook /// @param p_Function Function to register - static void Register(void (*p_Function)(Logger&)); + static void Register(void (*p_Function)(Paper::LoggerContext&)); /// @brief Install all hooks static void InstallHooks(); @@ -137,11 +139,11 @@ namespace CP_SDK::Utils { /// @brief Override a base class method with a custom BASECLASS__NAME method (PRESERVE CSHARP NAME) #define CP_SDK_IL2CPP_OVERRIDE_METHOD(__mBaseClass, __mRet, __mMethodName, ...) \ - __CP_SDK_IL2CPP_OVERRIDE_METHOD(__mBaseClass, __mRet, __mMethodName, il2cpp_utils::il2cpp_type_check::MetadataGetter<&__mBaseClass::__mMethodName>::get() __VA_OPT__(,) __VA_ARGS__) + __CP_SDK_IL2CPP_OVERRIDE_METHOD(__mBaseClass, __mRet, __mMethodName, il2cpp_utils::il2cpp_type_check::MetadataGetter<&__mBaseClass::__mMethodName>::methodInfo() __VA_OPT__(,) __VA_ARGS__) /// @brief Override a base class method with a custom BASECLASS__NAME method inside a namespace (PRESERVE CSHARP NAME) #define CP_SDK_IL2CPP_OVERRIDE_METHOD_EX(__mNamespace, __mBaseClass, __mRet, __mMethodName, ...) \ - __CP_SDK_IL2CPP_OVERRIDE_METHOD(__mBaseClass, __mRet, __mMethodName, il2cpp_utils::il2cpp_type_check::MetadataGetter<&__mNamespace::__mBaseClass::__mMethodName>::get() __VA_OPT__(,) __VA_ARGS__) + __CP_SDK_IL2CPP_OVERRIDE_METHOD(__mBaseClass, __mRet, __mMethodName, il2cpp_utils::il2cpp_type_check::MetadataGetter<&__mNamespace::__mBaseClass::__mMethodName>::methodInfo() __VA_OPT__(,) __VA_ARGS__) //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// diff --git a/shared/CP_SDK/Utils/Internals/il2cpp_customtype.hpp b/shared/CP_SDK/Utils/Internals/il2cpp_customtype.hpp index c11b9ed..459a031 100644 --- a/shared/CP_SDK/Utils/Internals/il2cpp_customtype.hpp +++ b/shared/CP_SDK/Utils/Internals/il2cpp_customtype.hpp @@ -39,12 +39,14 @@ namespace CP_SDK::Utils::Internals { //////////////////////////////////////////////////////////////////////////// #define __CP_SDK_IL2CPP_INHERIT(__mNamespace, __mName, __mBaseClass, ...) \ - protected: __mName() = default; \ - public: __mName(const __mName&) = delete; \ - public: __mName(__mName&&) = delete; \ + protected: __mName() = default; \ + public: __mName(const __mName&) = delete; \ + public: __mName(__mName&&) = delete; \ __CP_SDK_IL2CPP_CUSTOM_TYPE_DECLARE(__mNamespace, __mName, __mBaseClass, std::vector({ __VA_ARGS__ })) #define __CP_SDK_IL2CPP_INHERIT_HELPERS(__mName) \ + MARK_REF_PTR_T(__mName); \ + inline constexpr const int __mName::__IL2CPP_REFERENCE_TYPE_SIZE = sizeof(__mName); \ template<> struct ::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<::__mName*> { \ static inline Il2CppClass* get() { \ return ::__mName::___TypeRegistration::klass_ptr; \ @@ -174,6 +176,8 @@ namespace CP_SDK::Utils::Internals { constexpr static auto ___Base__Size = sizeof(__mBaseClass); \ friend ::custom_types::Register; \ public: \ + constexpr static bool __IL2CPP_IS_VALUE_TYPE = false; \ + static const int __IL2CPP_REFERENCE_TYPE_SIZE; \ struct ___TypeRegistration : ::custom_types::TypeRegistration { \ ___TypeRegistration() { \ ::custom_types::Register::AddType(this); \ @@ -185,7 +189,7 @@ namespace CP_SDK::Utils::Internals { } \ static void addField(::custom_types::FieldRegistrator* inst) { \ fields.push_back(inst); \ - ::custom_types::_logger().debug("Adding instance field: %s.%s new size: %lu", #__mName, inst->name(), fields.size()); \ + ::custom_types::logger.debug("Adding instance field: %s.%s new size: %lu", #__mName, inst->name(), fields.size()); \ } \ static inline std::vector<::custom_types::StaticFieldRegistrator*> staticFields; \ std::vector<::custom_types::StaticFieldRegistrator*> const getStaticFields() const override { \ @@ -193,7 +197,7 @@ namespace CP_SDK::Utils::Internals { } \ static void addStaticFieldInstance(::custom_types::StaticFieldRegistrator* inst) { \ staticFields.push_back(inst); \ - ::custom_types::_logger().debug("Adding static field: %s.%s new size: %lu", #__mName, inst->name(), staticFields.size()); \ + ::custom_types::logger.debug("Adding static field: %s.%s new size: %lu", #__mName, inst->name(), staticFields.size()); \ } \ static inline std::vector<::custom_types::MethodRegistrator*> methods; \ std::vector<::custom_types::MethodRegistrator*> const getMethods() const override { \ @@ -201,7 +205,7 @@ namespace CP_SDK::Utils::Internals { } \ static void addMethod(::custom_types::MethodRegistrator* inst) { \ methods.push_back(inst); \ - ::custom_types::_logger().debug("Adding method: %s.%s new size: %lu", #__mName, inst->name(), methods.size()); \ + ::custom_types::logger.debug("Adding method: %s.%s new size: %lu", #__mName, inst->name(), methods.size()); \ } \ static inline size_t staticFieldOffset; \ static size_t addStaticField(size_t sz) { \ @@ -226,7 +230,9 @@ namespace CP_SDK::Utils::Internals { return __mNamespace; \ } \ Il2CppClass* baseType() const override { \ - return ::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<__mBaseClass*>::get(); \ + auto klass = ::il2cpp_utils::il2cpp_type_check::il2cpp_no_arg_class<__mBaseClass*>::get(); \ + if (!klass->initialized) il2cpp_functions::Class_Init(klass); \ + return klass; \ } \ std::vector const interfaces() const override { \ return __mInterfaces; \ diff --git a/shared/CP_SDK/Utils/Internals/il2cpp_hook.hpp b/shared/CP_SDK/Utils/Internals/il2cpp_hook.hpp index 0441ff1..7f63112 100644 --- a/shared/CP_SDK/Utils/Internals/il2cpp_hook.hpp +++ b/shared/CP_SDK/Utils/Internals/il2cpp_hook.hpp @@ -29,7 +29,7 @@ using funcType = __mRetval (*)(__VA_ARGS__); \ static_assert(std::is_same_v::funcType>, "Hook method signature does not match!"); \ constexpr static const char* name() { return #__mName; } \ - static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter<__mPtr>::get(); } \ + static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter<__mPtr>::methodInfo(); } \ static funcType* trampoline() { return &__mName; } \ static inline __mRetval (*__mName)(__VA_ARGS__) = nullptr; \ static funcType hook() { return hook_##__mName; } \ @@ -44,7 +44,7 @@ using funcType = __mRetval (*)(__VA_ARGS__); \ static_assert(std::is_same_v::funcType>, "Hook method signature does not match!"); \ constexpr static const char* name() { return #__mName; } \ - static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter<__mPtr>::get(); } \ + static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter<__mPtr>::methodInfo(); } \ static funcType* trampoline() { return &__mName; } \ static inline __mRetval (*__mName)(__VA_ARGS__) = nullptr; \ static funcType hook() { return hook_##__mName; } \ diff --git a/shared/CP_SDK/Utils/Json.hpp b/shared/CP_SDK/Utils/Json.hpp index 20c8f4d..b55b508 100644 --- a/shared/CP_SDK/Utils/Json.hpp +++ b/shared/CP_SDK/Utils/Json.hpp @@ -64,7 +64,7 @@ namespace CP_SDK::Utils { /// @brief Json utils - class Json + class CP_SDK_EXPORT_VISIBILITY Json { CP_SDK_NO_DEF_CTORS(Json); diff --git a/shared/CP_SDK/Utils/MonoPtr.hpp b/shared/CP_SDK/Utils/MonoPtr.hpp index 42c16ec..ed29807 100644 --- a/shared/CP_SDK/Utils/MonoPtr.hpp +++ b/shared/CP_SDK/Utils/MonoPtr.hpp @@ -41,13 +41,13 @@ namespace CP_SDK::Utils { if constexpr (std::is_assignable_v) { auto l_UObject = reinterpret_cast(m_Wrapper->Ptr); - if (l_IsDead || !l_UObject->m_CachedPtr.m_value) + if (l_IsDead || !l_UObject->m_CachedPtr) l_IsDead = true; } if (p_Throw && l_IsDead) { - ChatPlexSDK::Logger()->Error(u"Dead pointer " + csTypeOf(t_Ptr*)->get_Name()); + //ChatPlexSDK::Logger()->Error(u"Dead pointer " + csTypeOf(t_Ptr*).convert()->get_Name()); throw NullHandleException(); } @@ -105,6 +105,8 @@ namespace CP_SDK::Utils { bool operator==(const MonoPtr& p_Other) const { return m_Wrapper == p_Other.m_Wrapper; } template bool operator==(t_OtherPtr* p_Pointer) const { return m_Wrapper && m_Wrapper->Ptr == p_Pointer; } + template + bool operator==(::UnityW p_Pointer) const { return Ptr(false) == p_Pointer.unsafePtr(); } public: Unity::MonoPtrHolder::Wrapper* m_Wrapper; @@ -123,17 +125,21 @@ namespace CP_SDK::Utils { ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// - template requires(std::is_assignable_v) + template static bool IsUnityPtrValid(t_Type* p_Ptr) { if (!p_Ptr) return false; auto l_UObject = reinterpret_cast(p_Ptr); - if (!l_UObject->m_CachedPtr.m_value) + if (!l_UObject->m_CachedPtr) return false; return true; } -} ///< namespace CP_SDK::Utils \ No newline at end of file +} ///< namespace CP_SDK::Utils + +template constexpr bool operator==(UnityW const& p_Left, CP_SDK::Utils::MonoPtr const& p_Right) { + return p_Left.isAlive() == p_Right.operator bool() && p_Left.unsafePtr() == p_Right.Ptr(false); +} \ No newline at end of file diff --git a/shared/CP_SDK/XUI/Templates.hpp b/shared/CP_SDK/XUI/Templates.hpp index b64bf09..6e7fba7 100644 --- a/shared/CP_SDK/XUI/Templates.hpp +++ b/shared/CP_SDK/XUI/Templates.hpp @@ -5,7 +5,7 @@ namespace CP_SDK::XUI { /// @brief XUI templates - class Templates + class CP_SDK_EXPORT_VISIBILITY Templates { public: /// @brief Modal rect layout diff --git a/shared/CP_SDK_BS/Game/BeatMaps/MapDetail.hpp b/shared/CP_SDK_BS/Game/BeatMaps/MapDetail.hpp index 6d1601d..3bac69e 100644 --- a/shared/CP_SDK_BS/Game/BeatMaps/MapDetail.hpp +++ b/shared/CP_SDK_BS/Game/BeatMaps/MapDetail.hpp @@ -21,7 +21,7 @@ namespace CP_SDK_BS::Game::BeatMaps { using namespace CP_SDK::Utils; } - struct MapDetail : public std::enable_shared_from_this + struct CP_SDK_EXPORT_VISIBILITY MapDetail : public std::enable_shared_from_this { MapDetail() = default; CP_SDK_NO_COPYMOVE_CTORS(MapDetail); diff --git a/shared/CP_SDK_BS/Game/BeatMapsClient.hpp b/shared/CP_SDK_BS/Game/BeatMapsClient.hpp index 2c5438a..7452332 100644 --- a/shared/CP_SDK_BS/Game/BeatMapsClient.hpp +++ b/shared/CP_SDK_BS/Game/BeatMapsClient.hpp @@ -20,7 +20,7 @@ namespace CP_SDK_BS::Game { } /// @brief BeatMaps client - class BeatMapsClient + class CP_SDK_EXPORT_VISIBILITY BeatMapsClient { CP_SDK_NO_DEF_CTORS(BeatMapsClient); diff --git a/shared/CP_SDK_BS/Game/LevelCompletionData.hpp b/shared/CP_SDK_BS/Game/LevelCompletionData.hpp index 27f7cc6..ef311bd 100644 --- a/shared/CP_SDK_BS/Game/LevelCompletionData.hpp +++ b/shared/CP_SDK_BS/Game/LevelCompletionData.hpp @@ -21,7 +21,7 @@ namespace CP_SDK_BS::Game { } /// @brief Level completion data - class LevelCompletionData + class CP_SDK_EXPORT_VISIBILITY LevelCompletionData { CP_SDK_NO_DEF_CTORS(LevelCompletionData); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK_BS/Game/LevelData.hpp b/shared/CP_SDK_BS/Game/LevelData.hpp index 1b7b157..212f2a9 100644 --- a/shared/CP_SDK_BS/Game/LevelData.hpp +++ b/shared/CP_SDK_BS/Game/LevelData.hpp @@ -20,7 +20,7 @@ namespace CP_SDK_BS::Game { } /// @brief Level data instance - class LevelData + class CP_SDK_EXPORT_VISIBILITY LevelData { CP_SDK_NO_DEF_CTORS(LevelData); CP_SDK_PRIV_TAG(); diff --git a/shared/CP_SDK_BS/Game/LevelSelection.hpp b/shared/CP_SDK_BS/Game/LevelSelection.hpp index 37cd554..21985fe 100644 --- a/shared/CP_SDK_BS/Game/LevelSelection.hpp +++ b/shared/CP_SDK_BS/Game/LevelSelection.hpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -21,18 +21,18 @@ namespace CP_SDK_BS::Game { } /// @brief Level selection filter - class LevelSelection + class CP_SDK_EXPORT_VISIBILITY LevelSelection { CP_SDK_NO_DEF_CTORS(LevelSelection); private: - static _v::MonoPtr<_u::CustomPreviewBeatmapLevel> m_PendingFilterSong; + static _v::MonoPtr<_u::BeatmapLevel> m_PendingFilterSong; static bool m_PreventLevelSearchViewController_didStartLoadingEvent; public: /// @brief Filter to specific song /// @param p_SongToFilter Song to filter - static bool FilterToSpecificSong(_u::CustomPreviewBeatmapLevel* p_SongToFilter); + static bool FilterToSpecificSong(_u::BeatmapLevel* p_SongToFilter); public: /// @brief Change current song view to all songs view diff --git a/shared/CP_SDK_BS/Game/Levels.hpp b/shared/CP_SDK_BS/Game/Levels.hpp index 66a2a97..9ba6dcd 100644 --- a/shared/CP_SDK_BS/Game/Levels.hpp +++ b/shared/CP_SDK_BS/Game/Levels.hpp @@ -8,16 +8,16 @@ #include -#include -#include +#include #include #include #include #include -#include -#include +#include #include #include +#include +#include #include #include #include @@ -36,20 +36,21 @@ namespace CP_SDK_BS::Game { } /// @brief Level helper - class Levels + class CP_SDK_EXPORT_VISIBILITY Levels { CP_SDK_NO_DEF_CTORS(Levels); private: static _v::MonoPtr<_u::Sprite> m_DefaultPackCover; - static _v::MonoPtr<_u::AdditionalContentModel> m_AdditionalContentModel; - static _v::MonoPtr<_u::BeatmapCharacteristicCollectionSO> m_BeatmapCharacteristicCollectionSO; + static _v::MonoPtr<_u::BeatmapCharacteristicCollection> m_BeatmapCharacteristicCollection; static _v::MonoPtr<_u::BeatmapLevelsModel> m_BeatmapLevelsModel; static _v::MonoPtr<_u::CancellationTokenSource> m_GetLevelCancellationTokenSource; static _v::MonoPtr<_u::CancellationTokenSource> m_GetLevelEntitlementStatusTokenSource; static _v::MonoPtr<_u::MenuTransitionsHelper> m_MenuTransitionsHelper; + static _v::MonoPtr<_u::SimpleLevelStarter> m_SimpleLevelStarter; + static bool m_ReloadSongsInitialized; static std::vector<_v::Action<>> m_ReloadSongsCallbacks; static std::mutex m_ReloadSongsCallbacksMutex; @@ -67,6 +68,26 @@ namespace CP_SDK_BS::Game { /// @return True or false static bool HasMappingCapability(std::u16string_view p_Capability); + public: + /// @brief Sanitize a level ID for case matching + /// @param p_LevelID Input level ID + /// @return Sanitized level ID + static std::u16string SanitizeLevelID(std::u16string_view p_LevelID); + /// @brief Try get hash from level ID + /// @param p_LevelID Input level ID + /// @param p_Hash OUT hash + /// @return true or false + static bool TryGetHashFromLevelID(std::u16string_view p_LevelID, std::u16string* p_Hash); + /// @brief Try get level ID from hash + /// @param p_Hash Input hash + /// @param p_LevelID OUT level ID + /// @return true or false + static bool TryGetLevelIDFromHash(std::u16string_view p_Hash, std::u16string* p_LevelID); + /// @brief Is level ID a custom level ID + /// @param p_LevelID Input level ID + /// @return true or false + static bool LevelID_IsCustom(std::u16string_view p_LevelID); + public: /// @brief Try get BeatmapCharacteristicSO by serialized name /// @param p_SerializedName Characteristic serialized name @@ -82,21 +103,6 @@ namespace CP_SDK_BS::Game { /// @return Sorting order or 1000 static int GetBeatmapCharacteristicSOOrdering(std::u16string_view p_SerializedName); - public: - /// @brief Is level ID a custom level ID - /// @param p_LevelID Input level ID - /// @return true or false - static bool LevelID_IsCustom(std::u16string_view p_LevelID); - /// @brief Try get hash from level ID - /// @param p_LevelID Input level ID - /// @param p_Hash OUT hash - /// @return true or false - static bool TryGetHashFromLevelID(std::u16string_view p_LevelID, std::u16string* p_Hash); - /// @brief Sanitize a level ID for case matching - /// @param p_LevelID Input level ID - /// @return Sanitized level ID - static std::u16string SanitizeLevelID(std::u16string_view p_LevelID); - public: /// @brief BeatmapDifficulty to BeatmapDifficulty enum name /// @param p_BeatmapDifficulty BeatmapDifficulty @@ -115,78 +121,98 @@ namespace CP_SDK_BS::Game { /// @return BeatmapDifficulty static _u::BeatmapDifficulty BeatmapDifficultySerializedNameToBeatmapDifficulty(std::u16string_view p_BeatmapDifficultySerializedName); - public: - /// @brief For each of PreviewDifficultyBeatmapSets for a PreviewBeatmapLevel - /// @param p_PreviewBeatmapLevel Input preview beatmap level - /// @param p_Functor Functor for each element, return true mean we continue iterating - static void PreviewDifficultyBeatmapSets_ForEach(_u::IPreviewBeatmapLevel* p_PreviewBeatmapLevel, _v::CFuncRef p_Functor); - /// @brief Try get preview difficulty beatmap set by CharacteristicSO - /// @param p_PreviewBeatmapLevel Input preview beatmap level - /// @param p_BeatmapCharacteristicSO Input characteristic SO - /// @param p_PreviewDifficultyBeatmapSet OUT result preview beatmap set - /// @return True or false - static bool TryGetPreviewDifficultyBeatmapSet(_u::IPreviewBeatmapLevel* p_PreviewBeatmapLevel, _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, _u::PreviewDifficultyBeatmapSet** p_PreviewDifficultyBeatmapSet); - /// @brief Check if a difficulty is present in a PreviewDifficultyBeatmapSet - /// @param p_PreviewDifficultyBeatmapSet Input PreviewDifficultyBeatmapSet - /// @param p_Difficulty Requested difficulty - /// @return True or false - static bool PreviewDifficultyBeatmapSet_HasDifficulty(_u::PreviewDifficultyBeatmapSet* p_PreviewDifficultyBeatmapSet, _u::BeatmapDifficulty p_Difficulty); - public: /// @brief Own a DLC level by level ID /// @param p_LevelID Level ID /// @param p_Callback Callback for success/failure - static void OwnDLCLevelByLevelID(std::u16string_view p_LevelID, _v::Action p_Callback); - /// @brief Try to get PreviewBeatmapLevel by level ID - /// @param p_LevelID ID of the level - /// @param p_PreviewBeatmapLevel OUT Found PreviewBeatmapLevel or nullptr + static void OwnDLCLevelByLevelID(std::u16string p_LevelID, _v::Action p_Callback); + + public: + /// @brief Try to get BeatmapLevel by level ID + /// @param p_LevelID ID of the level + /// @param p_BeatmapLevel OUT Found BeatmapLevel or nullptr + /// @return true or false + static bool TryGetBeatmapLevelForLevelID(std::u16string_view p_LevelID, _u::BeatmapLevel** p_BeatmapLevel); + /// @brief Try to get BeatmapLevel by hash + /// @param p_Hash Hash of the level + /// @param p_BeatmapLevel OUT Found BeatmapLevel or nullptr /// @return true or false - static bool TryGetPreviewBeatmapLevelForLevelID(std::u16string_view p_LevelID, _u::IPreviewBeatmapLevel** p_PreviewBeatmapLevel); - /// @brief Try get custom requirements for a IPreviewBeatmapLevel->BeatmapCharacteristicSO->BeatmapDifficulty + static bool TryGetBeatmapLevelForHash(std::u16string_view p_Hash, _u::BeatmapLevel** p_BeatmapLevel); + /// @brief For each of BeatmapKey for a BeatmapLevel + /// @param p_BeatmapLevel Input beatmap level + /// @param p_Functor Functor for each element, return true mean we continue iterating + static void BeatmapLevel_ForEachBeatmapKey(_u::BeatmapLevel* p_BeatmapLevel, _v::CFuncRef p_Functor); + + public: + /// @brief Check if a difficulty is present in a BeatmapLevel + /// @param p_BeatmapLevel Input beatmap level + /// @param p_BeatmapCharacteristicSO Desired BeatmapCharacteristicSO + /// @param p_BeatmapDifficulty Desired BeatmapDifficulty + /// @return True or false + static bool BeatmapLevel_HasDifficulty( _u::BeatmapLevel* p_BeatmapLevel, + _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, + _u::BeatmapDifficulty p_BeatmapDifficulty); + /// @brief Try get a beatmap key from a BeatmapLevel + /// @param p_BeatmapLevel Input beatmap level + /// @param p_BeatmapCharacteristicSO Desired BeatmapCharacteristicSO + /// @param p_BeatmapDifficulty Desired BeatmapDifficulty + /// @param p_BeatmapKey Out beatmap key + /// @return True or false + static bool BeatmapLevel_TryGetBeatmapKey( _u::BeatmapLevel* p_BeatmapLevel, + _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, + _u::BeatmapDifficulty p_BeatmapDifficulty, + _u::BeatmapKey* p_BeatmapKey); + /// @brief Try get custom requirements for a BeatmapLevel->BeatmapCharacteristicSO->BeatmapDifficulty /// @param p_PreviewBeatmapLevel Input preview beatmap level /// @param p_BeatmapCharacteristicSO Desired BeatmapCharacteristicSO /// @param p_BeatmapDifficulty Desired BeatmapDifficulty /// @param p_CustomRequirements OUT custom requirements /// @return true or false - static bool TryGetCustomRequirementsFor(_u::IPreviewBeatmapLevel* p_PreviewBeatmapLevel, + static bool TryGetCustomRequirementsFor(_u::BeatmapLevel* p_PreviewBeatmapLevel, _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, _u::BeatmapDifficulty p_BeatmapDifficulty, std::vector* p_CustomRequirements); - /// @brief Load a BeatmapLevel by level ID + + public: + /// @brief Try to load BeatmapLevel cover image async + /// @param p_BeatmapLevel Input BeatmapLevel + /// @param p_Callback Callback + static void TryLoadBeatmapLevelCoverAsync(_u::BeatmapLevel* p_BeatmapLevel, _v::Action p_Callback); + + public: + /// @brief Load a BeatmapLevelData by level ID /// @param p_LevelID ID of the level /// @param p_LoadCallback Load callback - static void LoadBeatmapLevelByLevelID( std::u16string_view p_LevelID, - _v::Action<_v::MonoPtr<_u::IBeatmapLevel, true>> p_LoadCallback); - /// @brief Try to load PreviewBeatmapLevel cover image async - /// @param p_PreviewBeatmapLevel Input PreviewBeatmapLevel - /// @param p_Callback Callback - static void TryLoadPreviewBeatmapLevelCoverAsync(_u::IPreviewBeatmapLevel* p_PreviewBeatmapLevel, _v::Action p_Callback); + static void LoadBeatmapLevelDataByLevelID( std::u16string p_LevelID, + _v::Action<_v::MonoPtr<_u::BeatmapLevel, true>, _v::MonoPtr<_u::IBeatmapLevelData, true>> p_LoadCallback); /// @brief Start a BeatmapLevel /// @param p_Level Loaded level /// @param p_Characteristic Beatmap game mode /// @param p_Difficulty Beatmap difficulty + /// @param p_BeatmapLevelData Beatmap level data /// @param p_OverrideEnvironmentSettings Environment settings /// @param p_ColorScheme Color scheme /// @param p_GameplayModifiers Modifiers /// @param p_PlayerSettings Player settings /// @param p_SongFinishedCallback Callback when the song is finished /// @param p_MenuButtonText Menu button text - static void StartBeatmapLevel( _u::IBeatmapLevel* p_Level, + static void StartBeatmapLevel( _u::BeatmapLevel* p_Level, _u::BeatmapCharacteristicSO* p_Characteristic, _u::BeatmapDifficulty p_Difficulty, + _u::IBeatmapLevelData* p_BeatmapLevelData, _u::OverrideEnvironmentSettings* p_OverrideEnvironmentSettings = nullptr, _u::ColorScheme* p_ColorScheme = nullptr, _u::GameplayModifiers* p_GameplayModifiers = nullptr, _u::PlayerSpecificSettings* p_PlayerSettings = nullptr, - _v::Action<_u::StandardLevelScenesTransitionSetupDataSO*, _u::LevelCompletionResults*, _u::IDifficultyBeatmap*> p_SongFinishedCallback = nullptr, + _v::Action<_u::StandardLevelScenesTransitionSetupDataSO*, _u::LevelCompletionResults*> p_SongFinishedCallback = nullptr, std::u16string_view p_MenuButtonText = u"Menu"); private: - /// @brief Get a BeatmapLevel from a level ID + /// @brief Load IBeatmapLevelData from a level ID /// @param p_LevelID Level ID /// @param p_Callback Callback for success/failure - static void GetBeatmapLevelFromLevelID( std::u16string_view p_LevelID, - _v::Action<_v::MonoPtr<_u::IBeatmapLevel, true>> p_Callback); + static void LoadIBeatmapLevelDataAsync( std::u16string p_LevelID, + _v::Action<_v::MonoPtr<_u::IBeatmapLevelData, true>> p_Callback); public: /// @brief Get accuracy @@ -203,7 +229,7 @@ namespace CP_SDK_BS::Game { /// @param p_HaveAnyScore OUT Have any score set /// @param p_HaveAllScores OUT Have all scores set /// @return Scores - static t_Scores GetScoresByLevelID(std::u16string_view p_SongHash, bool* p_HaveAnyScore, bool* p_HaveAllScores); + static t_Scores GetScoresByLevelID(std::u16string_view p_LevelID, bool* p_HaveAnyScore, bool* p_HaveAllScores); }; diff --git a/shared/CP_SDK_BS/Game/Logic.hpp b/shared/CP_SDK_BS/Game/Logic.hpp index f183450..75b28da 100644 --- a/shared/CP_SDK_BS/Game/Logic.hpp +++ b/shared/CP_SDK_BS/Game/Logic.hpp @@ -24,11 +24,11 @@ namespace CP_SDK_BS::Game { } /// @brief Game helper - class Logic + class CP_SDK_EXPORT_VISIBILITY Logic { CP_SDK_NO_DEF_CTORS(Logic); - using t_Delegate1 = System::Action_2<_u::ScenesTransitionSetupDataSO*, Zenject::DiContainer*>*; + using t_Delegate1 = System::Action_2, Zenject::DiContainer*>*; public: /// @brief Scenes diff --git a/shared/CP_SDK_BS/Game/PlayerAvatarPicture.hpp b/shared/CP_SDK_BS/Game/PlayerAvatarPicture.hpp index a4967a4..5a5bdd7 100644 --- a/shared/CP_SDK_BS/Game/PlayerAvatarPicture.hpp +++ b/shared/CP_SDK_BS/Game/PlayerAvatarPicture.hpp @@ -19,7 +19,7 @@ namespace CP_SDK_BS::Game { } /// @brief Player avatar picture provider - class PlayerAvatarPicture + class CP_SDK_EXPORT_VISIBILITY PlayerAvatarPicture { CP_SDK_NO_DEF_CTORS(PlayerAvatarPicture); diff --git a/shared/CP_SDK_BS/Game/Scoring.hpp b/shared/CP_SDK_BS/Game/Scoring.hpp index fb53910..cfc9c49 100644 --- a/shared/CP_SDK_BS/Game/Scoring.hpp +++ b/shared/CP_SDK_BS/Game/Scoring.hpp @@ -6,7 +6,7 @@ namespace CP_SDK_BS::Game { /// @brief Scoring utils - class Scoring + class CP_SDK_EXPORT_VISIBILITY Scoring { CP_SDK_NO_DEF_CTORS(Scoring); @@ -20,6 +20,7 @@ namespace CP_SDK_BS::Game { static bool m_IsBeatLeaderPresent; static t_BeatLeaderIsInReplay m_BeatLeaderIsInReplayFN; + public: static bool IsScoreSaberPresent(); static bool IsBeatLeaderPresent(); @@ -45,6 +46,11 @@ namespace CP_SDK_BS::Game { /// @param p_Is Is in replay? static void __SetScoreSaberIsInReplay(bool p_Is); + private: + /// @brief Check for mod precense by ID + /// @param p_ModID ID of the mod + static bool HasMod(std::string_view p_ModID); + }; } ///< namespace CP_SDK_BS::Game diff --git a/shared/CP_SDK_BS/Game/UserPlatform.hpp b/shared/CP_SDK_BS/Game/UserPlatform.hpp index aa35441..fac0eaf 100644 --- a/shared/CP_SDK_BS/Game/UserPlatform.hpp +++ b/shared/CP_SDK_BS/Game/UserPlatform.hpp @@ -7,7 +7,7 @@ namespace CP_SDK_BS::Game { /// UserPlatform helper - class UserPlatform + class CP_SDK_EXPORT_VISIBILITY UserPlatform { CP_SDK_NO_DEF_CTORS(UserPlatform); diff --git a/shared/CP_SDK_BS/UI/GameFont.hpp b/shared/CP_SDK_BS/UI/GameFont.hpp index 89e969d..2e79fe9 100644 --- a/shared/CP_SDK_BS/UI/GameFont.hpp +++ b/shared/CP_SDK_BS/UI/GameFont.hpp @@ -15,7 +15,7 @@ namespace CP_SDK_BS::UI { } /// @brief Helpers for game font - class GameFont + class CP_SDK_EXPORT_VISIBILITY GameFont { CP_SDK_NO_DEF_CTORS(GameFont); diff --git a/shared/CP_SDK_BS/UI/HMUIIconSegmentedControl.hpp b/shared/CP_SDK_BS/UI/HMUIIconSegmentedControl.hpp index 2ce2255..0c9a8b1 100644 --- a/shared/CP_SDK_BS/UI/HMUIIconSegmentedControl.hpp +++ b/shared/CP_SDK_BS/UI/HMUIIconSegmentedControl.hpp @@ -4,7 +4,6 @@ #include "CP_SDK/Utils/MonoPtr.hpp" #include -#include #include namespace CP_SDK_BS::UI { @@ -15,7 +14,7 @@ namespace CP_SDK_BS::UI { } /// @brief Vertical icon segmented control - class HMUIIconSegmentedControl + class CP_SDK_EXPORT_VISIBILITY HMUIIconSegmentedControl { CP_SDK_NO_DEF_CTORS(HMUIIconSegmentedControl); diff --git a/shared/CP_SDK_BS/UI/HMUITextSegmentedControl.hpp b/shared/CP_SDK_BS/UI/HMUITextSegmentedControl.hpp index 3ade558..a72c4ea 100644 --- a/shared/CP_SDK_BS/UI/HMUITextSegmentedControl.hpp +++ b/shared/CP_SDK_BS/UI/HMUITextSegmentedControl.hpp @@ -14,7 +14,7 @@ namespace CP_SDK_BS::UI { } /// @brief Text segmented control - class HMUITextSegmentedControl + class CP_SDK_EXPORT_VISIBILITY HMUITextSegmentedControl { CP_SDK_NO_DEF_CTORS(HMUITextSegmentedControl); diff --git a/shared/CP_SDK_BS/UI/HMUIUIUtils.hpp b/shared/CP_SDK_BS/UI/HMUIUIUtils.hpp index 0e9d18e..d566611 100644 --- a/shared/CP_SDK_BS/UI/HMUIUIUtils.hpp +++ b/shared/CP_SDK_BS/UI/HMUIUIUtils.hpp @@ -20,7 +20,7 @@ namespace CP_SDK_BS::UI { } /// @brief View controller utils - class HMUIUIUtils + class CP_SDK_EXPORT_VISIBILITY HMUIUIUtils { CP_SDK_NO_DEF_CTORS(HMUIUIUtils); @@ -38,7 +38,7 @@ namespace CP_SDK_BS::UI { template requires(std::is_assignable_v) static t_Base CreateFlowCoordinator() { - return reinterpret_cast(CreateFlowCoordinator(csTypeOf(t_Base))); + return reinterpret_cast(CreateFlowCoordinator(reinterpret_cast(csTypeOf(t_Base).convert()))); } /// @brief Create a flow coordinator /// @param p_Type Flow coordinator type @@ -49,7 +49,7 @@ namespace CP_SDK_BS::UI { template requires(std::is_assignable_v) static t_Base CreateViewController() { - return reinterpret_cast(CreateViewController(csTypeOf(t_Base))); + return reinterpret_cast(CreateViewController(reinterpret_cast(csTypeOf(t_Base).convert()))); } /// @brief Create a view controller /// @param p_Type View controller type diff --git a/shared/CP_SDK_BS/UI/HMUIViewFlowCoordinator.hpp b/shared/CP_SDK_BS/UI/HMUIViewFlowCoordinator.hpp index c36871a..f3a39cb 100644 --- a/shared/CP_SDK_BS/UI/HMUIViewFlowCoordinator.hpp +++ b/shared/CP_SDK_BS/UI/HMUIViewFlowCoordinator.hpp @@ -30,7 +30,7 @@ namespace CP_SDK_BS::UI { } /// @brief View flow coordinator base class - class HMUIViewFlowCoordinator : public HMUI::FlowCoordinator + class CP_SDK_EXPORT_VISIBILITY HMUIViewFlowCoordinator : public HMUI::FlowCoordinator { CP_SDK_IL2CPP_INHERIT("CP_SDK_BS.UI", HMUIViewFlowCoordinator, HMUI::FlowCoordinator); CP_SDK_IL2CPP_DECLARE_CTOR(HMUIViewFlowCoordinator); @@ -43,7 +43,7 @@ namespace CP_SDK_BS::UI { template requires(std::is_assignable_v) static _v::MonoPtr& _Instance() { - auto l_Type = reinterpret_cast(csTypeOf(t_Base*)); + auto l_Type = reinterpret_cast(csTypeOf(t_Base*).convert()); if (l_Type && m_Instances.contains(l_Type)) return *reinterpret_cast<_v::MonoPtr*>(&m_Instances[l_Type]); @@ -53,7 +53,7 @@ namespace CP_SDK_BS::UI { template requires(std::is_assignable_v) static void _Destroy() { - auto l_Type = reinterpret_cast(csTypeOf(t_Base*)); + auto l_Type = reinterpret_cast(csTypeOf(t_Base*).convert()); auto l_It = m_Instances.find(l_Type); if (!l_Type || l_It == m_Instances.end()) return; diff --git a/shared/CP_SDK_BS/UI/IHMUIViewController.hpp b/shared/CP_SDK_BS/UI/IHMUIViewController.hpp index a372bc2..a823cb7 100644 --- a/shared/CP_SDK_BS/UI/IHMUIViewController.hpp +++ b/shared/CP_SDK_BS/UI/IHMUIViewController.hpp @@ -7,6 +7,8 @@ #include #include #include +#include "System/Reflection/MemberInfo.hpp" +#include "System/Type.hpp" #include diff --git a/shared/CP_SDK_BS/UI/LevelDetail.hpp b/shared/CP_SDK_BS/UI/LevelDetail.hpp index bab9fad..c437c1b 100644 --- a/shared/CP_SDK_BS/UI/LevelDetail.hpp +++ b/shared/CP_SDK_BS/UI/LevelDetail.hpp @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -34,7 +34,7 @@ namespace CP_SDK_BS::UI { } /// @brief Song detail widget - class LevelDetail + class CP_SDK_EXPORT_VISIBILITY LevelDetail { CP_SDK_NO_COPYMOVE_CTORS(LevelDetail); @@ -65,7 +65,7 @@ namespace CP_SDK_BS::UI { _v::MonoPtr<_v::CSecondaryButton> m_SecondaryButton; _v::MonoPtr<_v::CPrimaryButton> m_PrimaryButton; _v::MonoPtr<_u::GameObject> m_FavoriteToggle; - _v::MonoPtr<_u::CustomPreviewBeatmapLevel> m_LocalBeatMap; + _v::MonoPtr<_u::BeatmapLevel> m_LocalBeatMap; Game::BeatMaps::MapDetail::Ptr m_BeatMap; private: @@ -85,7 +85,7 @@ namespace CP_SDK_BS::UI { _v::MonoPtr<_u::BeatmapCharacteristicSO> SelectedBeatmapCharacteristicSO; _u::BeatmapDifficulty SelectedBeatmapDifficulty; - _v::Event<_u::IDifficultyBeatmap*> OnActiveDifficultyChanged; + _v::Event<_u::BeatmapKey&> OnActiveDifficultyChanged; _v::Action<> OnSecondaryButton; _v::Action<> OnPrimaryButton; @@ -131,12 +131,12 @@ namespace CP_SDK_BS::UI { void SetActive(bool p_Active); public: - /// @brief Set from SongCore + /// @brief Set from game /// @param p_BeatMap BeatMap /// @param p_Cover Cover texture /// @param p_Characteristic Game mode /// @param p_Difficulty Difficulty - bool FromSongCore(_u::IBeatmapLevel* p_BeatMap, _u::Sprite* p_Cover, _u::BeatmapCharacteristicSO* p_Characteristic, _u::BeatmapDifficulty p_Difficulty); + bool FromGame(_u::BeatmapLevel* p_BeatMap, _u::Sprite* p_Cover, _u::BeatmapCharacteristicSO* p_Characteristic, _u::BeatmapDifficulty p_Difficulty); /// @brief Set from BeatSaver /// @param p_BeatMap BeatMap /// @param p_Cover Cover texture @@ -198,10 +198,6 @@ namespace CP_SDK_BS::UI { /// @brief Primary button on click void OnPrimaryButtonClicked(); - private: - /// @brief Get IDifficultyBeatmap - _u::IDifficultyBeatmap* GetIDifficultyBeatMap(); - }; } ///< namespace CP_SDK_BS::UI \ No newline at end of file diff --git a/shared/CP_SDK_BS/UI/Patches/PVRPointer.hpp b/shared/CP_SDK_BS/UI/Patches/PVRPointer.hpp index 488bb77..d395e32 100644 --- a/shared/CP_SDK_BS/UI/Patches/PVRPointer.hpp +++ b/shared/CP_SDK_BS/UI/Patches/PVRPointer.hpp @@ -12,7 +12,7 @@ namespace CP_SDK_BS::UI::Patches { using namespace VRUIControls; } - class PVRPointer + class CP_SDK_EXPORT_VISIBILITY PVRPointer { public: static CP_SDK::Utils::Event<_u::VRPointer*> OnActivated; diff --git a/shared/CP_SDK_BS/UI/ViewController.hpp b/shared/CP_SDK_BS/UI/ViewController.hpp index 6bf800c..688ebd4 100644 --- a/shared/CP_SDK_BS/UI/ViewController.hpp +++ b/shared/CP_SDK_BS/UI/ViewController.hpp @@ -31,7 +31,7 @@ namespace CP_SDK_BS::UI { } /// @brief View flow coordinator base class - class ViewController : public IHMUIViewController + class CP_SDK_EXPORT_VISIBILITY ViewController : public IHMUIViewController { CP_SDK_IL2CPP_INHERIT("CP_SDK_BS.UI", ViewController, IHMUIViewController); CP_SDK_IL2CPP_DECLARE_CTOR_CHILD(ViewController); @@ -58,7 +58,7 @@ namespace CP_SDK_BS::UI { template requires(std::is_assignable_v) static _v::MonoPtr& _Instance() { - auto l_Type = reinterpret_cast(csTypeOf(t_Base*)); + auto l_Type = reinterpret_cast(csTypeOf(t_Base*).convert()); if (l_Type && m_Instances.contains(l_Type)) return *reinterpret_cast<_v::MonoPtr*>(&m_Instances[l_Type]); @@ -99,7 +99,7 @@ namespace CP_SDK_BS::UI { template t_ModalType* CreateModal() { - return reinterpret_cast(CreateModal_Impl(reinterpret_cast(csTypeOf(t_ModalType*)))); + return reinterpret_cast(CreateModal_Impl(reinterpret_cast(csTypeOf(t_ModalType*).convert()))); } private: diff --git a/src/CP_SDK/Animation/AnimationControllerInstance.cpp b/src/CP_SDK/Animation/AnimationControllerInstance.cpp index bef7091..a278912 100644 --- a/src/CP_SDK/Animation/AnimationControllerInstance.cpp +++ b/src/CP_SDK/Animation/AnimationControllerInstance.cpp @@ -3,6 +3,7 @@ #include #include +#include using namespace UnityEngine; using namespace UnityEngine::UI; diff --git a/src/CP_SDK/Animation/AnimationInfo.cpp b/src/CP_SDK/Animation/AnimationInfo.cpp index 4f6139c..e785f7d 100644 --- a/src/CP_SDK/Animation/AnimationInfo.cpp +++ b/src/CP_SDK/Animation/AnimationInfo.cpp @@ -16,14 +16,11 @@ namespace CP_SDK::Animation { Delays.resize(p_FrameCount); for (int l_I = 0; l_I < p_FrameCount; ++l_I) - Frames.push_back(new Color32[p_Width * p_Height]); + Frames.push_back(Array::NewLength(4 * p_Width * p_Height)); } /// @brief Destructor AnimationInfo::~AnimationInfo() { - for (int l_I = 0; l_I < Frames.size(); ++l_I) - delete[] Frames[l_I]; - Frames.clear(); } diff --git a/src/CP_SDK/Animation/AnimationLoader.cpp b/src/CP_SDK/Animation/AnimationLoader.cpp index db0e54b..fed0d00 100644 --- a/src/CP_SDK/Animation/AnimationLoader.cpp +++ b/src/CP_SDK/Animation/AnimationLoader.cpp @@ -68,18 +68,19 @@ namespace CP_SDK::Animation { { auto l_FrameTexture = Texture2D::New_ctor(p_AnimationInfo->Width, p_AnimationInfo->Height, TextureFormat::RGBA32, false); l_FrameTexture->set_wrapMode(TextureWrapMode::Clamp); - l_FrameTexture->LoadRawTextureData(p_AnimationInfo->Frames[l_FrameI], sizeof(Color32) * p_AnimationInfo->Width * p_AnimationInfo->Height); - l_SubTextures->values[l_FrameI] = l_FrameTexture; + l_FrameTexture->LoadRawTextureData(p_AnimationInfo->Frames[l_FrameI].Ptr()); + + l_SubTextures->_values[l_FrameI] = l_FrameTexture; co_yield nullptr; } auto l_UVs = l_AtlasTexture->PackTextures(l_SubTextures.Ptr(), 2, l_MaxAtlasTextureSize, true); - for (int l_I = 0; l_I < l_SubTextures->Length(); ++l_I) + for (int l_I = 0; l_I < l_SubTextures->get_Length(); ++l_I) { - GameObject::Destroy(l_SubTextures->values[l_I]); - l_SubTextures->values[l_I] = nullptr; + GameObject::Destroy(l_SubTextures->_values[l_I]); + l_SubTextures->_values[l_I] = nullptr; } auto l_UVsVec = std::vector(l_UVs.begin(), l_UVs.end()); diff --git a/src/CP_SDK/Animation/WEBP/WEBPDecoder.cpp b/src/CP_SDK/Animation/WEBP/WEBPDecoder.cpp index bd27cbf..ad0f08f 100644 --- a/src/CP_SDK/Animation/WEBP/WEBPDecoder.cpp +++ b/src/CP_SDK/Animation/WEBP/WEBPDecoder.cpp @@ -22,7 +22,7 @@ namespace CP_SDK::Animation::WEBP { Unity::MTThreadInvoker::EnqueueOnThread([=]() -> void { WebPBitstreamFeatures l_Features = {}; - if (WebPGetFeatures(p_Raw->values, p_Raw->Length(), &l_Features) != VP8_STATUS_OK) + if (WebPGetFeatures(p_Raw->_values, p_Raw->get_Length(), &l_Features) != VP8_STATUS_OK) { ChatPlexSDK::Logger()->Error(u"[CP_SDK.Animation.WEBP][WEBP.ProcessingThread] Failed to get WebPFeatures"); p_Callback(nullptr); @@ -115,8 +115,8 @@ namespace CP_SDK::Animation::WEBP { ///l_Options.color_mode = Natives.WEBP.WEBP_CSP_MODE.MODE_RGBA; auto l_WebPData = WebPData(); - l_WebPData.bytes = p_Raw->values; - l_WebPData.size = p_Raw->Length(); + l_WebPData.bytes = p_Raw->_values; + l_WebPData.size = p_Raw->get_Length(); auto l_Decoder = WebPAnimDecoderNew(&l_WebPData, nullptr); if (l_Decoder) @@ -138,17 +138,18 @@ namespace CP_SDK::Animation::WEBP { break; } - auto l_TargetArray = l_AnimationInfo->Frames[l_FrameI]; + auto l_TargetArray = l_AnimationInfo->Frames[l_FrameI].Ptr(); for (int l_Line = 0; l_Line < l_Infos.canvas_height; ++l_Line) { for (int l_X = 0; l_X < l_Infos.canvas_width; ++l_X) { auto l_DestOffset = ((l_Infos.canvas_height - (l_Line + 1)) * l_Infos.canvas_width) + l_X; auto l_SourOffset = (l_Line * l_Infos.canvas_width * 4) + (l_X * 4); - l_TargetArray[l_DestOffset].r = l_Buffer[l_SourOffset + 0]; - l_TargetArray[l_DestOffset].g = l_Buffer[l_SourOffset + 1]; - l_TargetArray[l_DestOffset].b = l_Buffer[l_SourOffset + 2]; - l_TargetArray[l_DestOffset].a = l_Buffer[l_SourOffset + 3]; + + l_TargetArray->_values[(l_DestOffset * 4) + 0] = l_Buffer[l_SourOffset + 0]; + l_TargetArray->_values[(l_DestOffset * 4) + 1] = l_Buffer[l_SourOffset + 1]; + l_TargetArray->_values[(l_DestOffset * 4) + 2] = l_Buffer[l_SourOffset + 2]; + l_TargetArray->_values[(l_DestOffset * 4) + 3] = l_Buffer[l_SourOffset + 3]; } } diff --git a/src/CP_SDK/Logging/BMBFLogger.cpp b/src/CP_SDK/Logging/BMBFLogger.cpp deleted file mode 100644 index d675d67..0000000 --- a/src/CP_SDK/Logging/BMBFLogger.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#if CP_SDK_BMBF -#include "CP_SDK/Logging/BMBFLogger.hpp" - -#include -#include - -namespace CP_SDK::Logging { - - /// @brief Constructor - /// @param p_BMBFLogger BMBF logger instance - BMBFLogger::BMBFLogger(Logger * p_BMBFLogger) - : m_BMBFLogger(p_BMBFLogger) - { - - } - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - /// @brief Internal log method - /// @param p_Type Kind - /// @param p_Data Data - void BMBFLogger::LogImplementation(ELogType p_Type, std::u16string_view p_Data) - { - std::string l_UTF8Data; - std::wstring_convert, char16_t> l_Convertor; - l_UTF8Data = l_Convertor.to_bytes(p_Data.begin(), p_Data.end()); - - auto l_String = l_UTF8Data.c_str(); - switch (p_Type) - { - case ELogType::Error: m_BMBFLogger->error("%s", l_String); break; - case ELogType::Warning: m_BMBFLogger->warning("%s", l_String); break; - case ELogType::Info: m_BMBFLogger->info("%s", l_String); break; - case ELogType::Debug: m_BMBFLogger->debug("%s", l_String); break; - } - } - /// @brief Internal log method - /// @param p_Type Kind - /// @param p_Data Data - void BMBFLogger::LogImplementation(ELogType p_Type, const std::exception& p_Data) - { - auto l_String = p_Data.what(); - switch (p_Type) - { - case ELogType::Error: m_BMBFLogger->error("%s", l_String); break; - case ELogType::Warning: m_BMBFLogger->warning("%s", l_String); break; - case ELogType::Info: m_BMBFLogger->info("%s", l_String); break; - case ELogType::Debug: m_BMBFLogger->debug("%s", l_String); break; - } - } - -} ///< namespace CP_SDK::Logging -#endif \ No newline at end of file diff --git a/src/CP_SDK/Logging/PaperLogger.cpp b/src/CP_SDK/Logging/PaperLogger.cpp new file mode 100644 index 0000000..544ce6e --- /dev/null +++ b/src/CP_SDK/Logging/PaperLogger.cpp @@ -0,0 +1,54 @@ +#if CP_SDK_BMBF +#include "CP_SDK/Logging/PaperLogger.hpp" + +#include +#include + +namespace CP_SDK::Logging { + + /// @brief Constructor + /// @param p_Name Paper Logger name + PaperLogger::PaperLogger(const std::string& p_Name) + : m_PaperLogger(new Paper::LoggerContext(p_Name)) + { + + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Internal log method + /// @param p_Type Kind + /// @param p_Data Data + void PaperLogger::LogImplementation(ELogType p_Type, std::u16string_view p_Data) + { + std::string l_UTF8Data; + std::wstring_convert, char16_t> l_Convertor; + l_UTF8Data = l_Convertor.to_bytes(p_Data.begin(), p_Data.end()); + + auto l_String = l_UTF8Data.c_str(); + switch (p_Type) + { + case ELogType::Error: m_PaperLogger->error("{}", l_String); break; + case ELogType::Warning: m_PaperLogger->warn("{}", l_String); break; + case ELogType::Info: m_PaperLogger->info("{}", l_String); break; + case ELogType::Debug: m_PaperLogger->debug("{}", l_String); break; + } + } + /// @brief Internal log method + /// @param p_Type Kind + /// @param p_Data Data + void PaperLogger::LogImplementation(ELogType p_Type, const std::exception& p_Data) + { + auto l_String = p_Data.what(); + switch (p_Type) + { + case ELogType::Error: m_PaperLogger->error("{}", l_String); break; + case ELogType::Warning: m_PaperLogger->warn("{}", l_String); break; + case ELogType::Info: m_PaperLogger->info("{}", l_String); break; + case ELogType::Debug: m_PaperLogger->debug("{}", l_String); break; + } + } + +} ///< namespace CP_SDK::Logging +#endif \ No newline at end of file diff --git a/src/CP_SDK/Misc/Time.cpp b/src/CP_SDK/Misc/Time.cpp index cd132fa..4a142bc 100644 --- a/src/CP_SDK/Misc/Time.cpp +++ b/src/CP_SDK/Misc/Time.cpp @@ -17,42 +17,42 @@ namespace CP_SDK::Misc { /// @return Unix timestamp int64_t Time::UnixTimeNow() { - if (!s_Init) { s_UnixEpoch = _u::DateTime(1970, 1, 1, 0, 0, 0, 0, _u::DateTimeKind::Utc); s_Init = true; } - return static_cast((_u::DateTime::get_UtcNow() - s_UnixEpoch).get_TotalSeconds()); + if (!s_Init) { s_UnixEpoch = _u::DateTime::getStaticF_UnixEpoch(); s_Init = true; } + return static_cast((_u::DateTime::get_UtcNow().Subtract(s_UnixEpoch)).get_TotalSeconds()); } /// @brief Get UnixTimestamp /// @return Unix timestamp int64_t Time::UnixTimeNowMS() { - if (!s_Init) { s_UnixEpoch = _u::DateTime(1970, 1, 1, 0, 0, 0, 0, _u::DateTimeKind::Utc); s_Init = true; } - return static_cast((_u::DateTime::get_UtcNow() - s_UnixEpoch).get_TotalMilliseconds()); + if (!s_Init) { s_UnixEpoch = _u::DateTime::getStaticF_UnixEpoch(); s_Init = true; } + return static_cast((_u::DateTime::get_UtcNow().Subtract(s_UnixEpoch)).get_TotalMilliseconds()); } /// @brief Convert DateTime to UnixTimestamp /// @param p_DateTime The DateTime to convert int64_t Time::ToUnixTime(_u::DateTime p_DateTime) { - if (!s_Init) { s_UnixEpoch = _u::DateTime(1970, 1, 1, 0, 0, 0, 0, _u::DateTimeKind::Utc); s_Init = true; } + if (!s_Init) { s_UnixEpoch = _u::DateTime::getStaticF_UnixEpoch(); s_Init = true; } return static_cast(p_DateTime.ToUniversalTime().Subtract(s_UnixEpoch).get_TotalSeconds()); } /// @brief Convert DateTime to UnixTimestamp /// @param p_DateTime The DateTime to convert int64_t Time::ToUnixTimeMS(_u::DateTime p_DateTime) { - if (!s_Init) { s_UnixEpoch = _u::DateTime(1970, 1, 1, 0, 0, 0, 0, _u::DateTimeKind::Utc); s_Init = true; } + if (!s_Init) { s_UnixEpoch = _u::DateTime::getStaticF_UnixEpoch(); s_Init = true; } return static_cast(p_DateTime.ToUniversalTime().Subtract(s_UnixEpoch).get_TotalMilliseconds()); } /// @brief Convert UnixTimestamp to DateTime /// @param p_TimeStamp _u::DateTime Time::FromUnixTime(int64_t p_TimeStamp) { - if (!s_Init) { s_UnixEpoch = _u::DateTime(1970, 1, 1, 0, 0, 0, 0, _u::DateTimeKind::Utc); s_Init = true; } + if (!s_Init) { s_UnixEpoch = _u::DateTime::getStaticF_UnixEpoch(); s_Init = true; } return s_UnixEpoch.AddSeconds(p_TimeStamp).ToLocalTime(); } /// @brief Convert UnixTimestamp to DateTime /// @param p_TimeStamp _u::DateTime Time::FromUnixTimeMS(int64_t p_TimeStamp) { - if (!s_Init) { s_UnixEpoch = _u::DateTime(1970, 1, 1, 0, 0, 0, 0, _u::DateTimeKind::Utc); s_Init = true; } + if (!s_Init) { s_UnixEpoch = _u::DateTime::getStaticF_UnixEpoch(); s_Init = true; } return s_UnixEpoch.AddMilliseconds(p_TimeStamp).ToLocalTime(); } /// @brief Try parse international data diff --git a/src/CP_SDK/Network/WebClientUnity.cpp b/src/CP_SDK/Network/WebClientUnity.cpp index 06b4ac1..772c79c 100644 --- a/src/CP_SDK/Network/WebClientUnity.cpp +++ b/src/CP_SDK/Network/WebClientUnity.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +//#include #include #include @@ -192,8 +192,10 @@ namespace CP_SDK::Network { p_Request->set_timeout(p_IsDownload ? DownloadTimeout : m_Timeout); std::lock_guard l_Guard(m_HeadersLock); + + static auto s_UnityWebRequest_InternalSetRequestHeader = il2cpp_utils::resolve_icall("UnityEngine.Networking.UnityWebRequest::InternalSetRequestHeader"); for (auto const& [l_Header, l_Value] : m_Headers) - p_Request->SetRequestHeader(l_Header, l_Value); + s_UnityWebRequest_InternalSetRequestHeader(p_Request, l_Header, l_Value); } /// @brief Do request /// @param p_DebugName Method name for logs @@ -218,7 +220,7 @@ namespace CP_SDK::Network { ChatPlexSDK::Logger()->Debug(u"[CP_SDK.Network][WebClientUnity." + p_DebugName + u"] " + p_HttpMethod + u" " + p_URL); #endif - auto l_Reply = (WebResponse::Ptr)nullptr; + WebResponse::Ptr l_Reply = nullptr; for (int l_RetryI = 1; l_RetryI <= p_Self->MaxRetry; l_RetryI++) { if (p_Token.get_IsCancellationRequested()) @@ -229,22 +231,23 @@ namespace CP_SDK::Network { l_Request = UnityWebRequest::Get(p_URL); else if (p_HttpMethod == u"POST" || p_HttpMethod == u"PATCH") { - static auto s_UploadHandler_InternalSetContentType = il2cpp_utils::resolve_icall("UnityEngine.Networking.UploadHandler::InternalSetContentType"); + ChatPlexSDK::Logger()->Error(u"WebClientUnity POST & PATCH are disabled for now"); + throw std::runtime_error("WebClientUnity POST & PATCH are disabled for now"); + /// TODO Disabled until fixed + /*static auto s_UploadHandler_InternalSetContentType = il2cpp_utils::resolve_icall("UnityEngine.Networking.UploadHandler::InternalSetContentType"); auto l_UploadHandler = UploadHandlerRaw::New_ctor(p_Content->Bytes.Ptr()); s_UploadHandler_InternalSetContentType(l_UploadHandler, p_Content->Type); - l_Request = UnityWebRequest::New_ctor(p_URL, p_HttpMethod); - l_Request->set_uploadHandler(l_UploadHandler); - l_Request->set_downloadHandler(DownloadHandlerBuffer::New_ctor()); + l_Request = UnityWebRequest::New_ctor(p_URL, p_HttpMethod, DownloadHandlerBuffer::New_ctor(), l_UploadHandler);*/ } else if (p_HttpMethod == u"DELETE") - l_Request = UnityWebRequest::New_ctor(p_URL, p_HttpMethod); + l_Request = UnityWebRequest::New_ctor(p_URL, p_HttpMethod, nullptr, nullptr); p_Self->PrepareRequest(l_Request.Ptr(), p_HttpMethod == u"DOWNLOAD"); if (!p_Progress.IsValid()) - co_yield reinterpret_cast(l_Request->SendWebRequest()); + co_yield reinterpret_cast(l_Request->SendWebRequest()); else { try { p_Progress(0.0f); } catch (const std::exception&) { } @@ -253,10 +256,16 @@ namespace CP_SDK::Network { auto l_Waiter = WaitForSecondsRealtime::New_ctor(0.05f); do { - co_yield l_Waiter->i_IEnumerator(); - try { p_Progress(l_Request->get_downloadProgress()); } catch (const std::exception&) { } + co_yield l_Waiter->i___System__Collections__IEnumerator(); + try { + static auto s_UnityWebRequest_IsExecuting = il2cpp_utils::resolve_icall("UnityEngine.Networking.UnityWebRequest::IsExecuting"); + static auto s_UnityWebRequest_GetDownloadProgress = il2cpp_utils::resolve_icall("UnityEngine.Networking.UnityWebRequest::GetDownloadProgress"); + + auto l_Progress = (!s_UnityWebRequest_IsExecuting(l_Request.Ptr()) && !l_Request->get_isDone()) ? -1.0f : s_UnityWebRequest_GetDownloadProgress(l_Request.Ptr()); + p_Progress(l_Progress); + } catch (const std::exception&) { } - if (p_Token.get_IsCancellationRequested() || l_Request->get_isDone() || l_Request->get_isHttpError() || l_Request->get_isNetworkError()) + if (p_Token.get_IsCancellationRequested() || l_Request->get_isDone() || l_Request->get_result() == UnityWebRequest::Result::ProtocolError || l_Request->get_result() == UnityWebRequest::Result::ConnectionError) break; } while (true); } @@ -285,7 +294,7 @@ namespace CP_SDK::Network { if (!l_Reply->IsSuccessStatusCode()) { auto l_LogPrefix = u"[CP_SDK.Network][WebClientUnity." + p_DebugName + u"] Request " + p_Self->SafeURL(p_URL) + u" failed with code "; - l_LogPrefix += StringW(std::to_string((int)l_Reply->StatusCode())); + l_LogPrefix += StringW(std::to_string(l_Reply->StatusCode().value__)); l_LogPrefix += u":\"" + l_Reply->ReasonPhrase() + "\", "; if (!l_Reply->ShouldRetry() || p_DontRetry) @@ -296,7 +305,7 @@ namespace CP_SDK::Network { ChatPlexSDK::Logger()->Error(l_LogPrefix + u" next try in " + (std::u16string)StringW(std::to_string(p_Self->RetryInterval)) + u" seconds..."); - co_yield WaitForSecondsRealtime::New_ctor(p_Self->RetryInterval)->i_IEnumerator(); + co_yield WaitForSecondsRealtime::New_ctor(p_Self->RetryInterval)->i___System__Collections__IEnumerator(); continue; } else diff --git a/src/CP_SDK/Network/WebContent.cpp b/src/CP_SDK/Network/WebContent.cpp index bdadb36..c9ef6b2 100644 --- a/src/CP_SDK/Network/WebContent.cpp +++ b/src/CP_SDK/Network/WebContent.cpp @@ -1,8 +1,7 @@ #include "CP_SDK/Network/WebContent.hpp" #include -#include -#include +#include using namespace System::Text; diff --git a/src/CP_SDK/Network/WebResponse.cpp b/src/CP_SDK/Network/WebResponse.cpp index fdeb0bc..5ce5aa5 100644 --- a/src/CP_SDK/Network/WebResponse.cpp +++ b/src/CP_SDK/Network/WebResponse.cpp @@ -2,10 +2,9 @@ #include "CP_SDK/ChatPlexSDK.hpp" #include -#include -#include +#include #include -#include +#include bool StartWith(::Array* p_Array, ArrayW& p_Pattern, int p_PatternSize); @@ -46,12 +45,12 @@ namespace CP_SDK::Network { if (m_BodyString.has_value()) return m_BodyString.value(); - if (m_BodyBytes && m_BodyBytes->Length() > 0) + if (m_BodyBytes && m_BodyBytes->get_Length() > 0) { auto l_UTF8Encoding = Encoding::get_UTF8(); auto l_Preamble = l_UTF8Encoding->GetPreamble(); - if (l_Preamble.Length() > 0 && m_BodyBytes->Length() >= l_Preamble.Length() && StartWith(m_BodyBytes.Ptr(), l_Preamble, l_Preamble.Length())) - m_BodyString = l_UTF8Encoding->GetString(m_BodyBytes.Ptr(), l_Preamble.Length(), m_BodyBytes->Length() - l_Preamble.Length()); + if (l_Preamble.size() > 0 && m_BodyBytes->get_Length() >= l_Preamble.size() && StartWith(m_BodyBytes.Ptr(), l_Preamble, l_Preamble.size())) + m_BodyString = l_UTF8Encoding->GetString(m_BodyBytes.Ptr(), l_Preamble.size(), m_BodyBytes->get_Length() - l_Preamble.size()); else m_BodyString = l_UTF8Encoding->GetString(m_BodyBytes.Ptr()); } @@ -69,14 +68,14 @@ namespace CP_SDK::Network { WebResponse::WebResponse(UnityWebRequest * p_Request) { m_StatusCode = (HttpStatusCode)p_Request->get_responseCode(); - m_IsSuccessStatusCode = !(p_Request->get_isHttpError() || p_Request->get_isNetworkError()); + m_IsSuccessStatusCode = !(p_Request->get_result() == UnityWebRequest::Result::ProtocolError && p_Request->get_result() == UnityWebRequest::Result::ConnectionError); m_ShouldRetry = IsSuccessStatusCode() ? false : (p_Request->get_responseCode() < 400 || p_Request->get_responseCode() >= 500); m_BodyBytes = reinterpret_cast<::Array*>(p_Request->get_downloadHandler()->GetData().convert()); - if (p_Request->get_isNetworkError() || p_Request->get_isHttpError()) + if (p_Request->get_result() == UnityWebRequest::Result::ConnectionError || p_Request->get_result() == UnityWebRequest::Result::ProtocolError) { - if (p_Request->get_isHttpError()) - m_ReasonPhrase = u"HTTP/1.1 " + std::to_string(m_StatusCode) + u" " + p_Request->GetHTTPStatusString(m_StatusCode); + if (p_Request->get_result() == UnityWebRequest::Result::ProtocolError) + m_ReasonPhrase = u"HTTP/1.1 " + std::to_string(m_StatusCode.value__) + u" " + p_Request->GetHTTPStatusString(m_StatusCode.value__); else m_ReasonPhrase = p_Request->GetWebErrorString(p_Request->GetError()); } @@ -92,7 +91,7 @@ bool StartWith(::Array* p_Array, ArrayW& p_Pattern, int p_Patt auto l_PatternPosition = 0; for (int l_I = 0; l_I < p_PatternSize; ++l_I) { - if (p_Array->values[l_I] == p_Pattern[l_I]) + if (p_Array->_values[l_I] == p_Pattern[l_I]) continue; return false; diff --git a/src/CP_SDK/UI/Components/CFloatingPanel.cpp b/src/CP_SDK/UI/Components/CFloatingPanel.cpp index 57bcd3b..9dc1c62 100644 --- a/src/CP_SDK/UI/Components/CFloatingPanel.cpp +++ b/src/CP_SDK/UI/Components/CFloatingPanel.cpp @@ -3,6 +3,8 @@ #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" +#include + using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; using namespace UnityEngine::UI; @@ -152,7 +154,7 @@ namespace CP_SDK::UI::Components { { if (!m_Background) { - m_Background = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_Background = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_Background->get_gameObject()->set_layer(UISystem::UILayer); m_Background->get_rectTransform()->SetParent (get_transform(), false); m_Background->get_rectTransform()->set_localPosition (Vector3::get_zero()); diff --git a/src/CP_SDK/UI/Components/CIconButton.cpp b/src/CP_SDK/UI/Components/CIconButton.cpp index b60dc33..98e45f5 100644 --- a/src/CP_SDK/UI/Components/CIconButton.cpp +++ b/src/CP_SDK/UI/Components/CIconButton.cpp @@ -1,6 +1,7 @@ #include "CP_SDK/UI/Components/CIconButton.hpp" #include +#include using namespace UnityEngine; using namespace UnityEngine::UI; diff --git a/src/CP_SDK/UI/Components/CImage.cpp b/src/CP_SDK/UI/Components/CImage.cpp index 1c97123..aa1ad57 100644 --- a/src/CP_SDK/UI/Components/CImage.cpp +++ b/src/CP_SDK/UI/Components/CImage.cpp @@ -2,6 +2,7 @@ #include "CP_SDK/Animation/AnimationStateUpdater.hpp" #include +#include using namespace UnityEngine; using namespace UnityEngine::UI; @@ -31,7 +32,7 @@ namespace CP_SDK::UI::Components { /// @param p_Width Width CImage* CImage::SetWidth(float p_Width) { - RTransform()->set_sizeDelta(Vector2(p_Width, RTransform()->get_sizeDelta().y)); + RTransform()->set_sizeDelta({p_Width, RTransform()->get_sizeDelta().y}); LElement()->set_preferredWidth(p_Width); return this; } diff --git a/src/CP_SDK/UI/Components/Generics/CHOrVLayout.cpp b/src/CP_SDK/UI/Components/Generics/CHOrVLayout.cpp index c8e9b92..4a85aa0 100644 --- a/src/CP_SDK/UI/Components/Generics/CHOrVLayout.cpp +++ b/src/CP_SDK/UI/Components/Generics/CHOrVLayout.cpp @@ -48,7 +48,7 @@ namespace CP_SDK::UI::Components { { if (!m_Background) { - m_Background = reinterpret_cast(get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_Background = get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_Background->set_material(UISystem::Override_GetUIMaterial()); m_Background->set_raycastTarget(p_RaycastTarget); } diff --git a/src/CP_SDK/UI/Data/IListCell.cpp b/src/CP_SDK/UI/Data/IListCell.cpp index c195213..5395d10 100644 --- a/src/CP_SDK/UI/Data/IListCell.cpp +++ b/src/CP_SDK/UI/Data/IListCell.cpp @@ -4,7 +4,7 @@ #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -51,8 +51,8 @@ namespace CP_SDK::UI::Data { { auto l_NewCell = m_AddSelfComponent(GameObject::New_ctor("ListCell", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() , - reinterpret_cast(csTypeOf(RectTransform*)), - reinterpret_cast(csTypeOf(Button*)) + reinterpret_cast(csTypeOf(RectTransform*).convert()), + reinterpret_cast(csTypeOf(Button*).convert()) }))); l_NewCell->get_transform()->SetParent(p_Parent, false); l_NewCell->get_gameObject()->SetActive(false); @@ -86,7 +86,7 @@ namespace CP_SDK::UI::Data { if (!m_RTransform) m_RTransform = get_gameObject()->AddComponent(); - m_Image = reinterpret_cast(GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_Image = GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_Image->set_material (UISystem::Override_GetUIMaterial()); m_Image->set_type (Image::Type::Sliced); m_Image->set_pixelsPerUnitMultiplier(1); @@ -116,11 +116,11 @@ namespace CP_SDK::UI::Data { auto l_IsOdd = ((Index() & 1) != 0) ? true : false; auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(255, 255, 255, p_State ? (uint8_t)100 : (l_IsOdd ? (uint8_t)15 : (uint8_t)0)))); - l_Colors.set_highlightedColor(ColorU::Convert(Color32(255, 255, 255, p_State ? (uint8_t)100 : (uint8_t)75))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(255, 255, 255, p_State ? (uint8_t)100 : (uint8_t)75))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 255, 255, 255, p_State ? (uint8_t)100 : (l_IsOdd ? (uint8_t)15 : (uint8_t)0)))); + l_Colors.set_highlightedColor(ColorU::Convert(Color32(0, 255, 255, 255, p_State ? (uint8_t)100 : (uint8_t)75))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 255, 255, 255, p_State ? (uint8_t)100 : (uint8_t)75))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(127, 127, 127, p_State ? (uint8_t)100 : (uint8_t)75))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 127, 127, 127, p_State ? (uint8_t)100 : (uint8_t)75))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); } diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCColorInput.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCColorInput.cpp index c60a11d..b57d31a 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCColorInput.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCColorInput.cpp @@ -2,9 +2,10 @@ #include "CP_SDK/UI/IViewController.hpp" #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -53,7 +54,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_sizeDelta(Vector2(15.0f, 5.0f)); m_LElement = get_gameObject()->AddComponent(); @@ -62,14 +63,14 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement->set_minWidth (15.0f); m_LElement->set_minHeight ( 5.0f); - auto l_View = GameObject::New_ctor("View", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->GetComponent(); + auto l_View = GameObject::New_ctor("View", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->GetComponent(); l_View->get_gameObject()->set_layer(UISystem::UILayer); l_View->SetParent(get_transform(), false); - l_View->set_anchorMin(0.5f * Vector2::get_one()); - l_View->set_anchorMax(0.5f * Vector2::get_one()); + l_View->set_anchorMin(Vector2::get_one() * 0.5f); + l_View->set_anchorMax(Vector2::get_one() * 0.5f); l_View->set_sizeDelta(Vector2(15.0f, 5.0f)); - m_BG = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BG = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BG->get_gameObject()->set_layer(UISystem::UILayer); m_BG->get_rectTransform()->SetParent(l_View, false); m_BG->get_rectTransform()->set_pivot (Vector2( 0.50f, 0.50f)); @@ -104,11 +105,11 @@ namespace CP_SDK::UI::DefaultComponents { m_Button->get_onClick()->AddListener(MakeUnityAction(std::bind(&DefaultCColorInput::Button_OnClick, this))); auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(255, 255, 255, 255))); - l_Colors.set_highlightedColor(ColorU::Convert(Color32(255, 255, 255, 127))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(255, 255, 255, 255))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); + l_Colors.set_highlightedColor(ColorU::Convert(Color32(0, 255, 255, 255, 127))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(255, 255, 255, 48))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 255, 255, 255, 48))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); } diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCDropdown.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCDropdown.cpp index d5786f3..8855826 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCDropdown.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCDropdown.cpp @@ -4,7 +4,7 @@ #include "CP_SDK/Unity/Extensions/ColorU.hpp" #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -52,7 +52,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_sizeDelta(Vector2(60.0f, 5.5f)); m_LElement = get_gameObject()->AddComponent(); @@ -61,7 +61,7 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement->set_preferredHeight( 5.0f); m_LElement->set_flexibleWidth (150.0f); - m_BG = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BG = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BG->get_gameObject()->set_layer(UISystem::UILayer); m_BG->get_rectTransform()->SetParent(get_transform(), false); m_BG->get_rectTransform()->set_pivot (Vector2(0.50f, 0.50f)); @@ -100,11 +100,11 @@ namespace CP_SDK::UI::DefaultComponents { m_Button->get_onClick()->AddListener(MakeUnityAction(std::bind(&DefaultCDropdown::Button_OnClick, this))); auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(230, 230, 230, 127))); - l_Colors.set_highlightedColor (ColorU::Convert(Color32(255, 255, 255, 255))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(200, 200, 200, 255))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 230, 230, 230, 127))); + l_Colors.set_highlightedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 200, 200, 200, 255))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(255, 255, 255, 48))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 255, 255, 255, 48))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCFLayout.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCFLayout.cpp index 6531737..4a47ded 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCFLayout.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCFLayout.cpp @@ -89,7 +89,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_anchorMin(Vector2(0.0f, 0.0f)); m_RTransform->set_anchorMax(Vector2(1.0f, 1.0f)); m_RTransform->set_sizeDelta(Vector2(0.0f, 0.0f)); @@ -290,7 +290,7 @@ namespace CP_SDK::UI::DefaultComponents { } l_CurrentBarSize += l_ChildSize; - m_ItemList.push_back(l_Child); + m_ItemList.push_back(l_Child.ptr()); /// We need the largest element height to determine the starting position of the next line if (l_ChildOtherSize > l_CurrentBarSpace) l_CurrentBarSpace = l_ChildOtherSize; diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCFloatingPanel.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCFloatingPanel.cpp index b3b0f81..832339b 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCFloatingPanel.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCFloatingPanel.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace UnityEngine; using namespace UnityEngine::UI; @@ -43,13 +44,13 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_localPosition(Vector3::get_zero()); m_RTransform->set_localRotation(Quaternion::get_identity()); m_RTransform->set_localScale (Vector3(0.02f, 0.02f, 0.02f)); auto l_Canvas = get_gameObject()->AddComponent(); - l_Canvas->set_additionalShaderChannels(AdditionalCanvasShaderChannels::TexCoord1 | AdditionalCanvasShaderChannels::TexCoord2); + l_Canvas->set_additionalShaderChannels(AdditionalCanvasShaderChannels::TexCoord1.value__ | AdditionalCanvasShaderChannels::TexCoord2.value__); l_Canvas->set_sortingOrder (3); auto l_CanvasScaler = get_gameObject()->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCGLayout.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCGLayout.cpp index 9b62e6e..5c47af6 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCGLayout.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCGLayout.cpp @@ -40,7 +40,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_anchorMin(Vector2(0.0f, 0.0f)); m_RTransform->set_anchorMax(Vector2(1.0f, 1.0f)); m_RTransform->set_sizeDelta(Vector2(5.0f, 5.0f)); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCHLayout.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCHLayout.cpp index 787046f..eea700d 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCHLayout.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCHLayout.cpp @@ -38,7 +38,7 @@ namespace CP_SDK::UI::DefaultComponents { if (m_RTransform) return; - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_anchorMin(Vector2(0.0f, 0.0f)); m_RTransform->set_anchorMax(Vector2(1.0f, 1.0f)); m_RTransform->set_sizeDelta(Vector2(0.0f, 0.0f)); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCIconButton.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCIconButton.cpp index 8c13ab6..7c51e70 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCIconButton.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCIconButton.cpp @@ -2,11 +2,12 @@ #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" #include "CP_SDK/ChatPlexSDK.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include #include #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -49,11 +50,11 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_LElement = get_gameObject()->AddComponent(); - m_IconImage = reinterpret_cast(GameObject::New_ctor(u"Icon", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_IconImage = GameObject::New_ctor(u"Icon", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_IconImage->get_gameObject()->set_layer(UISystem::UILayer); m_IconImage->get_rectTransform()->SetParent (get_transform(), false); m_IconImage->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -73,7 +74,7 @@ namespace CP_SDK::UI::DefaultComponents { //m_Button->get_onClick()->RemoveAllListeners(); m_Button->get_onClick()->AddListener(MakeUnityAction(std::bind(&DefaultCIconButton::Button_OnClick, this))); - auto l_FakeBg = reinterpret_cast(get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr())); + auto l_FakeBg = get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_FakeBg->set_material (UISystem::Override_GetUIMaterial()); l_FakeBg->set_type (Image::Type::Simple); l_FakeBg->set_pixelsPerUnitMultiplier(1); @@ -81,11 +82,11 @@ namespace CP_SDK::UI::DefaultComponents { l_FakeBg->set_color (ColorU::WithAlpha(Color::get_black(), 0.01f)); auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(255, 255, 255, 150))); - l_Colors.set_highlightedColor (ColorU::Convert(Color32(255, 255, 255, 255))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(255, 255, 255, 255))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 255, 255, 255, 150))); + l_Colors.set_highlightedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(127, 127, 127, 150))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 127, 127, 127, 150))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); @@ -133,7 +134,7 @@ namespace CP_SDK::UI::DefaultComponents { return; StopAllCoroutines(); - StartCoroutine(custom_types::Helpers::CoroutineHelper::New(Coroutine_AnimateScale(this, 1.25f * Vector3::get_one(), 0.075f))); + StartCoroutine(custom_types::Helpers::CoroutineHelper::New(Coroutine_AnimateScale(this, Vector3::get_one() * 1.25f, 0.075f))); } /// @brief On pointer exit /// @param p_EventData Event data diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCImage.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCImage.cpp index bc5cffb..f9f329d 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCImage.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCImage.cpp @@ -39,12 +39,12 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_sizeDelta(Vector2(5.0f, 5.0f)); m_LElement = get_gameObject()->AddComponent(); - m_ImageC = reinterpret_cast(get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_ImageC = get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_ImageC->set_material (UISystem::Override_GetUIMaterial()); m_ImageC->set_type (Image::Type::Simple); m_ImageC->set_pixelsPerUnitMultiplier (1); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCPrimaryButton.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCPrimaryButton.cpp index 4be8d84..4693dcd 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCPrimaryButton.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCPrimaryButton.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace TMPro; @@ -55,7 +55,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_CSizeFitter = get_gameObject()->AddComponent(); m_CSizeFitter->set_horizontalFit(ContentSizeFitter::FitMode::PreferredSize); @@ -64,7 +64,7 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement = get_gameObject()->AddComponent(); m_LElement->set_minHeight(5.0f); - m_BackgroundImage = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BackgroundImage = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BackgroundImage->get_gameObject()->set_layer(UISystem::UILayer); m_BackgroundImage->get_rectTransform()->SetParent (get_transform(), false); m_BackgroundImage->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -82,7 +82,7 @@ namespace CP_SDK::UI::DefaultComponents { m_Label->SetAlign(TMPro::TextAlignmentOptions::Capline); m_Label->SetStyle(FontStyles::Bold); - m_IconImage = reinterpret_cast(GameObject::New_ctor("Icon", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_IconImage = GameObject::New_ctor("Icon", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_IconImage->get_gameObject()->set_layer(UISystem::UILayer); m_IconImage->get_rectTransform()->SetParent (get_transform(), false); m_IconImage->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -102,11 +102,11 @@ namespace CP_SDK::UI::DefaultComponents { m_Button->get_onClick()->AddListener(MakeUnityAction(std::bind(&DefaultCPrimaryButton::Button_OnClick, this))); auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(230, 230, 230, 180))); - l_Colors.set_highlightedColor (ColorU::Convert(Color32(255, 255, 255, 255))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(200, 200, 200, 255))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 230, 230, 230, 180))); + l_Colors.set_highlightedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 200, 200, 200, 255))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(255, 255, 255, 68))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 255, 255, 255, 68))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCSecondaryButton.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCSecondaryButton.cpp index 0c3254e..de1029b 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCSecondaryButton.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCSecondaryButton.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace TMPro; @@ -55,7 +55,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_CSizeFitter = get_gameObject()->AddComponent(); m_CSizeFitter->set_horizontalFit(ContentSizeFitter::FitMode::PreferredSize); @@ -64,7 +64,7 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement = get_gameObject()->AddComponent(); m_LElement->set_minHeight(5.0f); - m_BackgroundImage = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BackgroundImage = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BackgroundImage->get_gameObject()->set_layer(UISystem::UILayer); m_BackgroundImage->get_rectTransform()->SetParent (get_transform(), false); m_BackgroundImage->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -82,7 +82,7 @@ namespace CP_SDK::UI::DefaultComponents { m_Label->SetAlign(TMPro::TextAlignmentOptions::Capline); m_Label->SetStyle(FontStyles::Bold); - m_IconImage = reinterpret_cast(GameObject::New_ctor("Icon", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_IconImage = GameObject::New_ctor("Icon", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_IconImage->get_gameObject()->set_layer(UISystem::UILayer); m_IconImage->get_rectTransform()->SetParent (get_transform(), false); m_IconImage->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -102,11 +102,11 @@ namespace CP_SDK::UI::DefaultComponents { m_Button->get_onClick()->AddListener(MakeUnityAction(std::bind(&DefaultCSecondaryButton::Button_OnClick, this))); auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(230, 230, 230, 180))); - l_Colors.set_highlightedColor (ColorU::Convert(Color32(255, 255, 255, 255))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(200, 200, 200, 255))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 230, 230, 230, 180))); + l_Colors.set_highlightedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 200, 200, 200, 255))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(255, 255, 255, 68))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 255, 255, 255, 68))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCSlider.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCSlider.cpp index 606840e..82d2eab 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCSlider.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCSlider.cpp @@ -1,6 +1,7 @@ #include "CP_SDK/UI/DefaultComponents/DefaultCSlider.hpp" #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include #include @@ -86,7 +87,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_sizeDelta(Vector2(60.0f, 5.5f)); m_LElement = get_gameObject()->AddComponent(); @@ -95,7 +96,7 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement->set_preferredHeight(5.0f); m_LElement->set_flexibleWidth (150.0f); - m_BG = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BG = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BG->get_gameObject()->get_gameObject()->set_layer(UISystem::UILayer); m_BG->get_rectTransform()->SetParent(get_transform(), false); m_BG->get_rectTransform()->set_pivot (Vector2( 0.50f, 0.50f)); @@ -143,7 +144,7 @@ namespace CP_SDK::UI::DefaultComponents { SetNormalizedValue(GetSteppedNormalizedValue() + ((m_NumberOfSteps > 0) ? (1.0f / (float)m_NumberOfSteps) : 0.1f)); }); - m_SlidingArea = GameObject::New_ctor("SlidingArea", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->GetComponent(); + m_SlidingArea = GameObject::New_ctor("SlidingArea", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->GetComponent(); m_SlidingArea->get_gameObject()->set_layer(UISystem::UILayer); m_SlidingArea->SetParent(get_transform(), false); m_SlidingArea->set_pivot (Vector2( 0.5f, 0.5f)); @@ -152,7 +153,7 @@ namespace CP_SDK::UI::DefaultComponents { m_SlidingArea->set_anchoredPosition(Vector2( 0.0f, 0.0f)); m_SlidingArea->set_sizeDelta (Vector2(-11.5f, -1.0f)); - m_Handle = reinterpret_cast(GameObject::New_ctor("Handle", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_Handle = GameObject::New_ctor("Handle", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_Handle->get_gameObject()->set_layer(UISystem::UILayer); m_Handle->get_rectTransform()->SetParent(m_SlidingArea.Ptr(), false); m_Handle->get_rectTransform()->set_pivot (Vector2(0.5f, 0.5f)); @@ -161,7 +162,7 @@ namespace CP_SDK::UI::DefaultComponents { m_Handle->get_rectTransform()->set_anchoredPosition(Vector2(0.0f, 0.0f)); m_Handle->get_rectTransform()->set_sizeDelta (Vector2(1.5f, -1.0f)); m_Handle->set_material (UISystem::Override_GetUIMaterial()); - m_Handle->set_color (ColorU::Convert(Color32(255, 255, 255, 210))); + m_Handle->set_color (ColorU::Convert(Color32(0, 255, 255, 255, 210))); m_Handle->set_type (Image::Type::Simple); m_Handle->set_pixelsPerUnitMultiplier(15); m_Handle->set_sprite (UISystem::GetUISliderHandleSprite().Ptr()); @@ -296,7 +297,7 @@ namespace CP_SDK::UI::DefaultComponents { if (!p_O) { - m_BGSub2 = reinterpret_cast(GameObject::New_ctor("BGSub2", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BGSub2 = GameObject::New_ctor("BGSub2", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BGSub2->get_rectTransform()->SetParent(m_BG->get_transform(), false); m_BGSub2->get_rectTransform()->set_pivot (Vector2(0.50f, 0.50f)); m_BGSub2->get_rectTransform()->set_anchorMin (Vector2(0.00f, 0.00f)); @@ -320,7 +321,7 @@ namespace CP_SDK::UI::DefaultComponents { } else if (p_S) { - m_BGSub1 = reinterpret_cast(GameObject::New_ctor("BGSub1", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BGSub1 = GameObject::New_ctor("BGSub1", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BGSub1->get_rectTransform()->SetParent(m_BG->get_transform(), false); m_BGSub1->get_rectTransform()->set_pivot (Vector2(0.50f, 0.50f)); m_BGSub1->get_rectTransform()->set_anchorMin (Vector2(0.00f, 0.00f)); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCTabControl.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCTabControl.cpp index 6c3bd8f..5b19307 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCTabControl.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCTabControl.cpp @@ -86,7 +86,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_LElement = get_gameObject()->AddComponent(); m_LElement->set_minHeight (15.0f); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCText.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCText.cpp index 3e99151..9c03dd0 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCText.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCText.cpp @@ -43,9 +43,9 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement = get_gameObject()->AddComponent(); m_LElement->set_minHeight(5.0f); - m_TMProUGUI = reinterpret_cast(get_gameObject()->AddComponent(UISystem::Override_UnityComponent_TextMeshProUGUI.ptr())); - m_TMProUGUI->set_font (UISystem::Override_GetUIFont() ? UISystem::Override_GetUIFont() : m_TMProUGUI->get_font()); - m_TMProUGUI->set_fontSharedMaterial (UISystem::Override_GetUIFontSharedMaterial() ? UISystem::Override_GetUIFontSharedMaterial() : m_TMProUGUI->get_fontSharedMaterial()); + m_TMProUGUI = get_gameObject()->AddComponent(UISystem::Override_UnityComponent_TextMeshProUGUI.ptr()).try_cast().value_or(nullptr); + m_TMProUGUI->set_font (UISystem::Override_GetUIFont() ? UISystem::Override_GetUIFont() : m_TMProUGUI->get_font().ptr()); + m_TMProUGUI->set_fontSharedMaterial (UISystem::Override_GetUIFontSharedMaterial() ? UISystem::Override_GetUIFontSharedMaterial() : m_TMProUGUI->get_fontSharedMaterial().ptr()); m_TMProUGUI->set_margin (Vector4(0.0f, 0.0f, 0.0f, 0.0f)); m_TMProUGUI->set_fontSize (3.4f * UISystem::FontScale); m_TMProUGUI->set_color (UISystem::TextColor); @@ -54,7 +54,7 @@ namespace CP_SDK::UI::DefaultComponents { m_TMProUGUI->get_rectTransform()->set_anchorMin(Vector2(0.5f, 0.5f)); m_TMProUGUI->get_rectTransform()->set_anchorMax(Vector2(0.5f, 0.5f)); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); SetAlign(TextAlignmentOptions::Left); SetText(u"Default Text"); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCTextInput.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCTextInput.cpp index 7e341a6..bb08752 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCTextInput.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCTextInput.cpp @@ -4,7 +4,7 @@ #include "CP_SDK/Unity/Extensions/ColorU.hpp" #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -51,7 +51,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_sizeDelta(Vector2(60.0f, 5.50f)); m_LElement = get_gameObject()->AddComponent(); @@ -60,7 +60,7 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement->set_preferredHeight(5.0f); m_LElement->set_flexibleWidth (150.0f); - m_BG = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BG = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BG->get_gameObject()->set_layer(UISystem::UILayer); m_BG->get_rectTransform()->SetParent (get_transform(), false); m_BG->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -99,11 +99,11 @@ namespace CP_SDK::UI::DefaultComponents { m_Button->get_onClick()->AddListener(MakeUnityAction(std::bind(&DefaultCTextInput::Button_OnClick, this))); auto l_Colors = m_Button->get_colors(); - l_Colors.set_normalColor (ColorU::Convert(Color32(255, 255, 255, 127))); - l_Colors.set_highlightedColor (ColorU::Convert(Color32(255, 255, 255, 255))); - l_Colors.set_pressedColor (ColorU::Convert(Color32(200, 200, 200, 255))); + l_Colors.set_normalColor (ColorU::Convert(Color32(0, 255, 255, 255, 127))); + l_Colors.set_highlightedColor (ColorU::Convert(Color32(0, 255, 255, 255, 255))); + l_Colors.set_pressedColor (ColorU::Convert(Color32(0, 200, 200, 200, 255))); l_Colors.set_selectedColor (l_Colors.get_normalColor()); - l_Colors.set_disabledColor (ColorU::Convert(Color32(255, 255, 255, 48))); + l_Colors.set_disabledColor (ColorU::Convert(Color32(0, 255, 255, 255, 48))); l_Colors.set_fadeDuration (0.05f); m_Button->set_colors(l_Colors); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCTextSegmentedControl.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCTextSegmentedControl.cpp index 76267b7..4637450 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCTextSegmentedControl.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCTextSegmentedControl.cpp @@ -3,7 +3,7 @@ #include "CP_SDK/Unity/Extensions/ColorU.hpp" #include -#include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -52,7 +52,7 @@ namespace CP_SDK::UI::DefaultComponents { get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_CSizeFitter = get_gameObject()->AddComponent(); m_CSizeFitter->set_horizontalFit(ContentSizeFitter::FitMode::Unconstrained); @@ -126,12 +126,12 @@ namespace CP_SDK::UI::DefaultComponents { for (auto l_I = 0; l_I < p_Texts.size(); ++l_I) { - auto l_Control = GameObject::New_ctor(u"Tab" + std::to_string(l_I), ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->GetComponent(); + auto l_Control = GameObject::New_ctor(u"Tab" + std::to_string(l_I), ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->GetComponent(); l_Control->get_gameObject()->set_layer(UISystem::UILayer); l_Control->SetParent(get_transform(), false); l_Control->set_sizeDelta(Vector2(0.0f, 5.0f)); - auto l_Background = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + auto l_Background = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_Background->get_gameObject()->set_layer(UISystem::UILayer); l_Background->get_rectTransform()->SetParent(l_Control->get_transform(), false); l_Background->get_rectTransform()->set_anchorMin (Vector2::get_zero()); @@ -163,7 +163,7 @@ namespace CP_SDK::UI::DefaultComponents { auto l_Button = l_Control->get_gameObject()->AddComponent(); l_Button->set_targetGraphic(l_Background); - l_Button->get_onClick()->AddListener(MakeUnityAction([=]() -> void { + l_Button->get_onClick()->AddListener(MakeUnityAction([this, l_Button]() -> void { OnControlClicked(l_Button, true); })); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCToggle.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCToggle.cpp index 0434ca2..e6df470 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCToggle.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCToggle.cpp @@ -1,11 +1,12 @@ #include "CP_SDK/UI/DefaultComponents/DefaultCToggle.hpp" #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include #include #include -#include +#include #include #include @@ -73,13 +74,13 @@ namespace CP_SDK::UI::DefaultComponents { ColorU::WithAlpha(UISystem::SecondaryColor, 150.0f / 255.0f) ); m_DisabledColors = ColorBlock( - ColorU::Convert(Color32( 0, 0, 0, 64)), - ColorU::Convert(Color32( 0, 0, 0, 68)) + ColorU::Convert(Color32(0, 0, 0, 0, 64)), + ColorU::Convert(Color32(0, 0, 0, 0, 68)) ); get_gameObject()->set_layer(UISystem::UILayer); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_sizeDelta(Vector2(15.0f, 5.0f)); m_LElement = get_gameObject()->AddComponent(); @@ -88,11 +89,11 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement->set_minWidth (15.0f); m_LElement->set_minHeight ( 5.0f); - auto l_View = reinterpret_cast(GameObject::New_ctor("View", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->get_transform()); + auto l_View = GameObject::New_ctor("View", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->get_transform().try_cast().value_or(nullptr); l_View->get_gameObject()->set_layer(UISystem::UILayer); l_View->SetParent(get_transform(), false); - l_View->set_anchorMin (0.5f * Vector2::get_one()); - l_View->set_anchorMax (0.5f * Vector2::get_one()); + l_View->set_anchorMin (Vector2::get_one() * 0.5f); + l_View->set_anchorMax (Vector2::get_one() * 0.5f); l_View->set_sizeDelta (Vector2(15.0f, 5.0f)); m_Toggle = l_View->get_gameObject()->AddComponent(); @@ -100,11 +101,11 @@ namespace CP_SDK::UI::DefaultComponents { m_Toggle->onValueChanged->AddListener(MakeUnityAction(this, il2cpp_functions::class_get_method_from_name(this->klass, "Toggle_onValueChanged", 1))); m_Toggle->StateDidChangeEvent += {this, &DefaultCToggle::Toggle_StateDidChange}; - m_BackgroundImage = reinterpret_cast(GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_BackgroundImage = GameObject::New_ctor("BG", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_BackgroundImage->get_gameObject()->set_layer(UISystem::UILayer); m_BackgroundImage->get_rectTransform()->SetParent(l_View, false); - m_BackgroundImage->get_rectTransform()->set_anchorMin(0.5f * Vector2::get_one()); - m_BackgroundImage->get_rectTransform()->set_anchorMax(0.5f * Vector2::get_one()); + m_BackgroundImage->get_rectTransform()->set_anchorMin(Vector2::get_one() * 0.5f); + m_BackgroundImage->get_rectTransform()->set_anchorMax(Vector2::get_one() * 0.5f); m_BackgroundImage->get_rectTransform()->set_sizeDelta(Vector2(15.0f, 5.0f)); m_BackgroundImage->set_sprite (UISystem::GetUIRoundBGSprite().Ptr()); m_BackgroundImage->set_color (Color(0.0f, 0.0f, 0.0f, 0.5f)); @@ -126,7 +127,7 @@ namespace CP_SDK::UI::DefaultComponents { m_OnText->RTransform()->set_sizeDelta (Vector2( 6.00f, 0.00f)); m_OnText->RTransform()->set_localPosition(Vector3(-3.25f, 0.00f, 0.00f)); - auto l_Knob = reinterpret_cast(GameObject::New_ctor("Knob", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->get_transform()); + auto l_Knob = GameObject::New_ctor("Knob", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->get_transform().try_cast().value_or(nullptr); l_Knob->get_gameObject()->set_layer(UISystem::UILayer); l_Knob->SetParent(m_BackgroundImage->get_rectTransform(), false); l_Knob->set_anchorMin (Vector2( 0.50f, 0.0f)); @@ -134,7 +135,7 @@ namespace CP_SDK::UI::DefaultComponents { l_Knob->set_sizeDelta (Vector2( 7.50f, 0.0f)); l_Knob->set_localPosition(Vector3( 0.00f, 0.0f, 0.00f)); - m_KnobImage = reinterpret_cast(GameObject::New_ctor("Image", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_KnobImage = GameObject::New_ctor("Image", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_KnobImage->get_gameObject()->set_layer(UISystem::UILayer); m_KnobImage->get_rectTransform()->SetParent(l_Knob, false); m_KnobImage->get_rectTransform()->set_anchorMin (Vector2( 0.00f, 0.5f)); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCVLayout.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCVLayout.cpp index 90df60f..3f73049 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCVLayout.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCVLayout.cpp @@ -38,7 +38,7 @@ namespace CP_SDK::UI::DefaultComponents { if (m_RTransform) return; - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_anchorMin(Vector2(0.0f, 0.0f)); m_RTransform->set_anchorMax(Vector2(1.0f, 1.0f)); m_RTransform->set_sizeDelta(Vector2(0.0f, 0.0f)); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCVScrollView.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCVScrollView.cpp index 9ba2549..0db76de 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCVScrollView.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCVScrollView.cpp @@ -68,7 +68,7 @@ namespace CP_SDK::UI::DefaultComponents { m_LElement = get_gameObject()->AddComponent(); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_RTransform->set_anchorMin (Vector2(0.0f, 1.0f)); m_RTransform->set_anchorMax (Vector2(1.0f, 1.0f)); m_RTransform->set_sizeDelta (Vector2::get_zero()); @@ -76,7 +76,7 @@ namespace CP_SDK::UI::DefaultComponents { //////////////////////////////////////////////////////////////////////////// - auto l_ScrollBar = reinterpret_cast(GameObject::New_ctor("ScrollBar", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->get_transform()); + auto l_ScrollBar = GameObject::New_ctor("ScrollBar", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->get_transform().try_cast().value_or(nullptr); l_ScrollBar->get_gameObject()->set_layer(UISystem::UILayer); l_ScrollBar->SetParent(get_transform(), false); l_ScrollBar->set_anchorMin (Vector2( 1.0f, 0.0f)); @@ -84,7 +84,7 @@ namespace CP_SDK::UI::DefaultComponents { l_ScrollBar->set_sizeDelta (Vector2( m_ScrollBarWidth, 0.0f)); l_ScrollBar->set_anchoredPosition(Vector2(-(m_ScrollBarWidth / 2.0f), 0.0f)); - auto l_ScrollBarBG = reinterpret_cast(l_ScrollBar->get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr())); + auto l_ScrollBarBG = l_ScrollBar->get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_ScrollBarBG->set_material (UISystem::Override_GetUIMaterial()); l_ScrollBarBG->set_color (ColorU::WithAlpha("#202020", 0.7f)); l_ScrollBarBG->set_pixelsPerUnitMultiplier(1); @@ -121,21 +121,21 @@ namespace CP_SDK::UI::DefaultComponents { m_DownButton->IconImageC()->get_rectTransform()->set_sizeDelta (Vector2( 4.0f, 2.0f)); m_DownButton->SetSprite(UISystem::GetUIDownArrowSprite().Ptr())->OnClick({this, &DefaultCVScrollView::OnDownButton}); - auto l_ScrollIndicator = reinterpret_cast(GameObject::New_ctor("ScrollIndicator", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) }))->get_transform()); + auto l_ScrollIndicator = GameObject::New_ctor("ScrollIndicator", ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) }))->get_transform().try_cast().value_or(nullptr); l_ScrollIndicator->get_gameObject()->set_layer(UISystem::UILayer); l_ScrollIndicator->SetParent(l_ScrollBar->get_transform(), false); l_ScrollIndicator->set_anchorMin(Vector2(0.5f, 0.0f)); l_ScrollIndicator->set_anchorMax(Vector2(0.5f, 1.0f)); l_ScrollIndicator->set_sizeDelta(Vector2(1.6f, -12.0f)); - auto l_ScrollIndicatorImage = reinterpret_cast(l_ScrollIndicator->get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr())); + auto l_ScrollIndicatorImage = l_ScrollIndicator->get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_ScrollIndicatorImage->set_sprite (UISystem::GetUIRoundBGSprite().Ptr()); l_ScrollIndicatorImage->set_color (Color(0.0f, 0.0f, 0.0f, 0.5f)); l_ScrollIndicatorImage->set_type (Image::Type::Sliced); l_ScrollIndicatorImage->set_material (UISystem::Override_GetUIMaterial()); l_ScrollIndicatorImage->set_raycastTarget(false); - m_Handle = reinterpret_cast(GameObject::New_ctor("Handle", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + m_Handle = GameObject::New_ctor("Handle", ArrayW({ UISystem::Override_UnityComponent_Image.ptr() }))->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); m_Handle->get_gameObject()->set_layer(UISystem::UILayer); m_Handle->get_rectTransform()->SetParent(l_ScrollIndicator->get_transform(), false); m_Handle->get_rectTransform()->set_pivot (Vector2(0.5f, 1.0f)); @@ -150,10 +150,10 @@ namespace CP_SDK::UI::DefaultComponents { //////////////////////////////////////////////////////////////////////////// - m_ViewPort = reinterpret_cast(GameObject::New_ctor("ViewPort", ArrayW({ - reinterpret_cast(csTypeOf(RectTransform*)), - reinterpret_cast(csTypeOf(RectMask2D*)) - }))->get_transform()); + m_ViewPort = GameObject::New_ctor("ViewPort", ArrayW({ + reinterpret_cast(csTypeOf(RectTransform*).convert()), + reinterpret_cast(csTypeOf(RectMask2D*).convert()) + }))->get_transform().try_cast().value_or(nullptr); m_ViewPort->get_gameObject()->set_layer(UISystem::UILayer); m_ViewPort->SetParent(get_transform(), false); m_ViewPort->set_anchorMin (Vector2( 0.0f, 0.0f)); @@ -162,11 +162,11 @@ namespace CP_SDK::UI::DefaultComponents { m_ViewPort->set_localPosition(Vector3(-(m_ScrollBarWidth / 2.0f), 0.0f, 0.0f)); m_ViewPort->GetComponent()->set_padding(Vector4(0.25f, 0.25f, 0.25f, 0.25f)); - m_VScrollViewContent = reinterpret_cast(GameObject::New_ctor("ScrollViewContent", ArrayW({ - reinterpret_cast(csTypeOf(RectTransform*)), - reinterpret_cast(csTypeOf(ContentSizeFitter*)), - reinterpret_cast(csTypeOf(VerticalLayoutGroup*)) - }))->get_transform()); + m_VScrollViewContent = GameObject::New_ctor("ScrollViewContent", ArrayW({ + reinterpret_cast(csTypeOf(RectTransform*).convert()), + reinterpret_cast(csTypeOf(ContentSizeFitter*).convert()), + reinterpret_cast(csTypeOf(VerticalLayoutGroup*).convert()) + }))->get_transform().try_cast().value_or(nullptr); m_VScrollViewContent->get_gameObject()->set_layer(UISystem::UILayer); m_VScrollViewContent->SetParent(m_ViewPort.Ptr(), false); m_VScrollViewContent->set_anchorMin(Vector2(0.0f, 1.0f)); @@ -189,11 +189,11 @@ namespace CP_SDK::UI::DefaultComponents { //////////////////////////////////////////////////////////////////////////// - m_Container = reinterpret_cast(GameObject::New_ctor("Container", ArrayW({ - reinterpret_cast(csTypeOf(RectTransform*)), - reinterpret_cast(csTypeOf(VerticalLayoutGroup*)), - reinterpret_cast(csTypeOf(LayoutElement*)) - }))->get_transform()); + m_Container = GameObject::New_ctor("Container", ArrayW({ + reinterpret_cast(csTypeOf(RectTransform*).convert()), + reinterpret_cast(csTypeOf(VerticalLayoutGroup*).convert()), + reinterpret_cast(csTypeOf(LayoutElement*).convert()) + }))->get_transform().try_cast().value_or(nullptr); m_Container->get_gameObject()->set_layer(UISystem::UILayer); m_Container->SetParent(m_VScrollViewContent.Ptr(), false); m_Container->set_anchorMin(Vector2(0.0f, 1.0f)); diff --git a/src/CP_SDK/UI/DefaultComponents/DefaultCVVList.cpp b/src/CP_SDK/UI/DefaultComponents/DefaultCVVList.cpp index 3c76274..d9c3b39 100644 --- a/src/CP_SDK/UI/DefaultComponents/DefaultCVVList.cpp +++ b/src/CP_SDK/UI/DefaultComponents/DefaultCVVList.cpp @@ -54,7 +54,7 @@ namespace CP_SDK::UI::DefaultComponents { if (m_RTransform) return; - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); m_ScrollView = get_gameObject()->AddComponent(); m_ScrollView->Init(); diff --git a/src/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.cpp b/src/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.cpp index 2b263d6..1b7c128 100644 --- a/src/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.cpp +++ b/src/CP_SDK/UI/DefaultComponents/Subs/SubToggleWithCallbacks.cpp @@ -29,7 +29,7 @@ namespace CP_SDK::UI::DefaultComponents::Subs { void SubToggleWithCallbacks::Selectable__DoStateTransition(Selectable::SelectionState p_State, bool p_Instant) { CP_SDK_IL2CPP_CALL_BASE_METHOD(Selectable, "DoStateTransition", p_State, p_Instant); - StateDidChangeEvent(static_cast(p_State.value)); + StateDidChangeEvent(static_cast(p_State.value__)); } } ///< namespace CP_SDK::UI::DefaultComponents::Subs \ No newline at end of file diff --git a/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollIndicator.cpp b/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollIndicator.cpp index 9ca3e47..007defc 100644 --- a/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollIndicator.cpp +++ b/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollIndicator.cpp @@ -5,6 +5,7 @@ #include #include +#include using namespace UnityEngine; @@ -87,7 +88,7 @@ namespace CP_SDK::UI::DefaultComponents::Subs { /// @brief Refresh handle void SubVScrollIndicator::RefreshHandle() { - auto l_Progress = reinterpret_cast(get_transform())->get_rect().get_size().y - 2.0f * m_Padding; + auto l_Progress = get_transform().try_cast().value_or(nullptr)->get_rect().get_size().y - 2.0f * m_Padding; auto l_PosY = (0.0f - m_Progress) * (1.0f - m_NormalizedPageHeight) * l_Progress - m_Padding; if (std::isnan(l_PosY)) diff --git a/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollViewContent.cpp b/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollViewContent.cpp index 98f1243..e554c81 100644 --- a/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollViewContent.cpp +++ b/src/CP_SDK/UI/DefaultComponents/Subs/SubVScrollViewContent.cpp @@ -33,7 +33,7 @@ namespace CP_SDK::UI::DefaultComponents::Subs { /// @brief Component first frame void SubVScrollViewContent::Start() { - LayoutRebuilder::ForceRebuildLayoutImmediate(reinterpret_cast(get_transform())); + LayoutRebuilder::ForceRebuildLayoutImmediate(get_transform().try_cast().value_or(nullptr)); StopAllCoroutines(); StartCoroutine(custom_types::Helpers::CoroutineHelper::New(Coroutine_DisableCanvas(this))); @@ -70,7 +70,7 @@ namespace CP_SDK::UI::DefaultComponents::Subs { { co_yield nullptr; - auto l_RTransform = reinterpret_cast(p_Self->get_transform()->GetChild(0)); + auto l_RTransform = p_Self->get_transform()->GetChild(0).try_cast().value_or(nullptr); while (l_RTransform->get_sizeDelta().y == -1.0f) co_yield nullptr; @@ -80,7 +80,7 @@ namespace CP_SDK::UI::DefaultComponents::Subs { /// @brief Update scroll view content size & buttons void SubVScrollViewContent::UpdateScrollView() { - VScrollView->SetContentSize(reinterpret_cast(get_transform()->GetChild(0))->get_rect().m_Height); + VScrollView->SetContentSize(get_transform()->GetChild(0).try_cast().value_or(nullptr)->get_rect().m_Height); VScrollView->RefreshScrollButtons(); } diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultColorInputFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultColorInputFactory.cpp index e6742e1..8d2b165 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultColorInputFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultColorInputFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CColorInput* DefaultColorInputFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultDropdownFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultDropdownFactory.cpp index ff132c5..b12a464 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultDropdownFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultDropdownFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CDropdown* DefaultDropdownFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultFLayoutFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultFLayoutFactory.cpp index 9c8eec3..d15c209 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultFLayoutFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultFLayoutFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CFLayout* DefaultFLayoutFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultFloatingPanelFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultFloatingPanelFactory.cpp index 0d51fd5..9eee89e 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultFloatingPanelFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultFloatingPanelFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CFloatingPanel* DefaultFloatingPanelFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultGLayoutFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultGLayoutFactory.cpp index a45917d..4fb31ac 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultGLayoutFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultGLayoutFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CGLayout* DefaultGLayoutFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultHLayoutFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultHLayoutFactory.cpp index 2efcf27..f21c854 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultHLayoutFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultHLayoutFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CHLayout* DefaultHLayoutFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultIconButtonFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultIconButtonFactory.cpp index b8ac679..7f6e262 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultIconButtonFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultIconButtonFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CIconButton* DefaultIconButtonFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultImageFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultImageFactory.cpp index 02f6740..6420657 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultImageFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultImageFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CImage* DefaultImageFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultPrimaryButtonFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultPrimaryButtonFactory.cpp index 310ad7c..c5d1fc1 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultPrimaryButtonFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultPrimaryButtonFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CPrimaryButton* DefaultPrimaryButtonFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultSecondaryButtonFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultSecondaryButtonFactory.cpp index 0333b2a..4093451 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultSecondaryButtonFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultSecondaryButtonFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CSecondaryButton* DefaultSecondaryButtonFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultSliderFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultSliderFactory.cpp index 5f886bc..a4b4595 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultSliderFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultSliderFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CSlider* DefaultSliderFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultTabControlFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultTabControlFactory.cpp index 425147f..c75cba3 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultTabControlFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultTabControlFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CTabControl* DefaultTabControlFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultTextFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultTextFactory.cpp index 630e5c0..c2da0ba 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultTextFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultTextFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CText* DefaultTextFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultTextInputFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultTextInputFactory.cpp index 1b1fa03..1b15c1d 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultTextInputFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultTextInputFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CTextInput* DefaultTextInputFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultTextSegmentedControlFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultTextSegmentedControlFactory.cpp index 4944adb..4053e31 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultTextSegmentedControlFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultTextSegmentedControlFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CTextSegmentedControl* DefaultTextSegmentedControlFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultToggleFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultToggleFactory.cpp index 35cf0a6..8475c8f 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultToggleFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultToggleFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CToggle* DefaultToggleFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultVLayoutFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultVLayoutFactory.cpp index fcc729d..dbf8fcd 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultVLayoutFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultVLayoutFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CVLayout* DefaultVLayoutFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultVScrollViewFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultVScrollViewFactory.cpp index 1361758..3399ff8 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultVScrollViewFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultVScrollViewFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CVScrollView* DefaultVScrollViewFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/DefaultFactories/DefaultVVListFactory.cpp b/src/CP_SDK/UI/DefaultFactories/DefaultVVListFactory.cpp index ec4ec56..05da8e1 100644 --- a/src/CP_SDK/UI/DefaultFactories/DefaultVVListFactory.cpp +++ b/src/CP_SDK/UI/DefaultFactories/DefaultVVListFactory.cpp @@ -14,7 +14,7 @@ namespace CP_SDK::UI::DefaultFactories { /// @param p_Parent Parent transform Components::CVVList* DefaultVVListFactory::Create(std::u16string_view p_Name, Transform* p_Parent) { - auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*)) })); + auto l_GameObject = GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK/UI/FlowCoordinator.cpp b/src/CP_SDK/UI/FlowCoordinator.cpp index 6411325..12fc943 100644 --- a/src/CP_SDK/UI/FlowCoordinator.cpp +++ b/src/CP_SDK/UI/FlowCoordinator.cpp @@ -23,4 +23,34 @@ namespace CP_SDK::UI { } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + _v::MonoPtr& FlowCoordinator::_InstanceEx(_u::Type* p_Type) + { + if (p_Type && m_Instances.contains(p_Type)) + return m_Instances[p_Type]; + + auto l_Ptr = _u::GameObject::New_ctor("[CP_SDK.UI.FlowCoordinator<" + p_Type->get_FullName() + ">]", ArrayW<_u::Type*>({ + p_Type + }))->GetComponent(p_Type).try_cast().value_or(nullptr); + _u::GameObject::DontDestroyOnLoad(l_Ptr->get_gameObject()); + + m_Instances[p_Type] = l_Ptr; + + return m_Instances[p_Type]; + } + + void FlowCoordinator::_DestroyEx(_u::Type* p_Type) + { + auto l_It = m_Instances.find(p_Type); + if (!p_Type || l_It == m_Instances.end()) + return; + + if (m_Instances[p_Type]) + _u::GameObject::Destroy(m_Instances[p_Type]->get_gameObject()); + + m_Instances.erase(l_It); + } + } ///< namespace CP_SDK::UI \ No newline at end of file diff --git a/src/CP_SDK/UI/IModal.cpp b/src/CP_SDK/UI/IModal.cpp index 3b74e61..13709f2 100644 --- a/src/CP_SDK/UI/IModal.cpp +++ b/src/CP_SDK/UI/IModal.cpp @@ -27,7 +27,7 @@ namespace CP_SDK::UI { { CP_SDK_UI_IL2CPP_BIND_FIELD(RTransform, m_RTransform); - m_RTransform = reinterpret_cast(get_transform()); + m_RTransform = get_transform().try_cast().value_or(nullptr); } } ///< namespace CP_SDK::UI \ No newline at end of file diff --git a/src/CP_SDK/UI/LoadingProgressBar.cpp b/src/CP_SDK/UI/LoadingProgressBar.cpp index 13cc6fd..f02d172 100644 --- a/src/CP_SDK/UI/LoadingProgressBar.cpp +++ b/src/CP_SDK/UI/LoadingProgressBar.cpp @@ -1,5 +1,6 @@ #include "CP_SDK/UI/LoadingProgressBar.hpp" #include "CP_SDK/UI/UISystem.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include "UnityEngine/GameObject.hpp" #include "UnityEngine/Transform.hpp" @@ -49,7 +50,7 @@ namespace CP_SDK::UI { m_Canvas->set_renderMode(RenderMode::WorldSpace); m_Canvas->set_enabled(false); - auto l_RectTransform = reinterpret_cast(m_Canvas->get_transform()); + auto l_RectTransform = m_Canvas->get_transform().try_cast().value_or(nullptr); l_RectTransform->set_sizeDelta(Vector2(100, 50)); m_HeaderText = UISystem::TextFactory->Create(u"", m_Canvas->get_transform()); @@ -63,13 +64,13 @@ namespace CP_SDK::UI { } m_LoadingBackground = GameObject::New_ctor("Background")->AddComponent(); - l_RectTransform = reinterpret_cast(m_LoadingBackground->get_transform()); + l_RectTransform = m_LoadingBackground->get_transform().try_cast().value_or(nullptr); l_RectTransform->SetParent(m_Canvas->get_transform(), false); l_RectTransform->set_sizeDelta(Vector2(100, 10)); m_LoadingBackground->set_color(Color(0, 0, 0, 0.2f)); m_LoadingBar = GameObject::New_ctor("Loading Bar")->AddComponent(); - l_RectTransform = reinterpret_cast(m_LoadingBar->get_transform()); + l_RectTransform = m_LoadingBar->get_transform().try_cast().value_or(nullptr); l_RectTransform->SetParent(m_Canvas->get_transform(), false); l_RectTransform->set_sizeDelta(Vector2(100, 10)); m_LoadingBar->set_sprite( @@ -162,7 +163,7 @@ namespace CP_SDK::UI { /// @param p_Time Time in seconds custom_types::Helpers::Coroutine LoadingProgressBar::Coroutine_DisableCanvas(LoadingProgressBar* p_Self, float p_Time) { - co_yield WaitForSecondsRealtime::New_ctor(p_Time)->i_IEnumerator(); + co_yield WaitForSecondsRealtime::New_ctor(p_Time)->i___System__Collections__IEnumerator(); p_Self->m_Canvas->set_enabled(false); } diff --git a/src/CP_SDK/UI/ModMenu.cpp b/src/CP_SDK/UI/ModMenu.cpp index 6a7895f..f78e2d3 100644 --- a/src/CP_SDK/UI/ModMenu.cpp +++ b/src/CP_SDK/UI/ModMenu.cpp @@ -56,7 +56,7 @@ namespace CP_SDK::UI { return; m_Instance = GameObject::New_ctor("[CP_SDK.UI.ModMenu]", ArrayW({ - reinterpret_cast(csTypeOf(ModMenu*)), + reinterpret_cast(csTypeOf(ModMenu*).convert()), }))->GetComponent(); GameObject::DontDestroyOnLoad(m_Instance->get_gameObject()); diff --git a/src/CP_SDK/UI/ScreenSystem.cpp b/src/CP_SDK/UI/ScreenSystem.cpp index 06c2d1e..5e8cf9d 100644 --- a/src/CP_SDK/UI/ScreenSystem.cpp +++ b/src/CP_SDK/UI/ScreenSystem.cpp @@ -55,7 +55,7 @@ namespace CP_SDK::UI { return; m_Instance = GameObject::New_ctor("[CP_SDK.UI.ScreenSystem]", ArrayW({ - reinterpret_cast(csTypeOf(ScreenSystem*)), + reinterpret_cast(csTypeOf(ScreenSystem*).convert()), }))->GetComponent(); GameObject::DontDestroyOnLoad(m_Instance->get_gameObject()); } diff --git a/src/CP_SDK/UI/Tooltip.cpp b/src/CP_SDK/UI/Tooltip.cpp index 91845b4..50adeea 100644 --- a/src/CP_SDK/UI/Tooltip.cpp +++ b/src/CP_SDK/UI/Tooltip.cpp @@ -3,6 +3,7 @@ #include "CP_SDK/Unity/Extensions/ColorU.hpp" #include +#include using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; @@ -49,7 +50,7 @@ namespace CP_SDK::UI { l_Tooltip->m_ContentSizeFitter->set_horizontalFit(ContentSizeFitter::FitMode::PreferredSize); l_Tooltip->m_ContentSizeFitter->set_verticalFit (ContentSizeFitter::FitMode::PreferredSize); - l_Tooltip->m_Image = reinterpret_cast(l_Tooltip->get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr())); + l_Tooltip->m_Image = l_Tooltip->get_gameObject()->AddComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_Tooltip->m_Image->set_material (UISystem::Override_GetUIMaterial()); l_Tooltip->m_Image->set_type (Image::Type::Sliced); l_Tooltip->m_Image->set_pixelsPerUnitMultiplier(1); diff --git a/src/CP_SDK/UI/UISystem.cpp b/src/CP_SDK/UI/UISystem.cpp index 1b4feb7..19c8e03 100644 --- a/src/CP_SDK/UI/UISystem.cpp +++ b/src/CP_SDK/UI/UISystem.cpp @@ -34,6 +34,7 @@ #include #include #include +#include using namespace CP_SDK::Unity::Extensions; using namespace TMPro; @@ -108,8 +109,8 @@ namespace CP_SDK::UI { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - SafePtr UISystem::Override_UnityComponent_Image = csTypeOf(Image*); - SafePtr UISystem::Override_UnityComponent_TextMeshProUGUI = csTypeOf(TextMeshProUGUI*); + SafePtr UISystem::Override_UnityComponent_Image = reinterpret_cast(csTypeOf(Image*).convert()); + SafePtr UISystem::Override_UnityComponent_TextMeshProUGUI = reinterpret_cast(csTypeOf(TextMeshProUGUI*).convert()); //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -132,7 +133,7 @@ namespace CP_SDK::UI { Unity::EnhancedImage::FromRawAnimated( u"CP_SDK._Resources.ChatPlexLogoLoading.webp", Animation::EAnimationType::WEBP, - reinterpret_cast<::Array*>(IncludedAssets::ChatPlexLogoLoading_webp.operator ArrayW *>().convert()), + reinterpret_cast<::Array*>(Assets::ChatPlexLogoLoading_webp.operator ArrayW *>().convert()), [](const Unity::EnhancedImage::Ptr& x) -> void { m_LoadingAnimation = x; } @@ -163,22 +164,22 @@ namespace CP_SDK::UI { #define AUTO_SPRITE_GETTER(__Field, __Variable, __Asset, __Borders) \ UIFieldRefDelExtractor::t_DelType __Field = []() -> UIFieldRefDelExtractor::t_PtrType { return GetXSprite(__Variable, __Asset, __Borders); }; - AUTO_SPRITE_GETTER(UISystem::GetUIButtonSprite, m_UIButtonSprite, IncludedAssets::UIButton_png.Raw(), Vector4(10, 10, 10, 10)); - AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerFBGSprite, m_UIColorPickerFBGSprite, IncludedAssets::UIColorPickerFBG_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerHBGSprite, m_UIColorPickerHBGSprite, IncludedAssets::UIColorPickerHBG_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerSBGSprite, m_UIColorPickerSBGSprite, IncludedAssets::UIColorPickerSBG_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerVBGSprite, m_UIColorPickerVBGSprite, IncludedAssets::UIColorPickerVBG_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIDownArrowSprite, m_UIDownArrowSprite, IncludedAssets::UIDownArrow_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIIconGearSprite, m_UIIconGear, IncludedAssets::UIIconGear_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIIconLockedSprite, m_UIIconLocked, IncludedAssets::UIIconLocked_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIIconUnlockedSprite, m_UIIconUnlocked, IncludedAssets::UIIconUnlocked_png.Raw(), Vector4::get_zero()); - AUTO_SPRITE_GETTER(UISystem::GetUIRectBGSprite, m_UIRectBGSprite, IncludedAssets::UIRectBG_png.Raw(), Vector4(15, 15, 15, 15)); - AUTO_SPRITE_GETTER(UISystem::GetUIRoundBGSprite, m_UIRoundBGSprite, IncludedAssets::UIRoundBG_png.Raw(), Vector4(15, 15, 15, 15)); - AUTO_SPRITE_GETTER(UISystem::GetUIRoundRectLeftBGSprite, m_UIRoundRectLeftBGSprite, IncludedAssets::UIRoundRectLeftBG_png.Raw(), Vector4(15, 15, 15, 15)); - AUTO_SPRITE_GETTER(UISystem::GetUIRoundRectRightBGSprite, m_UIRoundRectRightBGSprite, IncludedAssets::UIRoundRectRightBG_png.Raw(), Vector4(15, 15, 15, 15)); - AUTO_SPRITE_GETTER(UISystem::GetUIRoundSmoothFrameSprite, m_UIRoundSmoothFrameSprite, IncludedAssets::UIRoundSmoothFrame_png.Raw(), Vector4(15, 15, 15, 15)); - AUTO_SPRITE_GETTER(UISystem::GetUISliderBGSprite, m_UISliderBGSprite, IncludedAssets::UISliderBG_png.Raw(), Vector4(15, 15, 15, 15)); - AUTO_SPRITE_GETTER(UISystem::GetUISliderHandleSprite, m_UISliderHandleSprite, IncludedAssets::UISliderHandle_png.Raw(), Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIButtonSprite, m_UIButtonSprite, Assets::UIButton_png, Vector4(10, 10, 10, 10)); + AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerFBGSprite, m_UIColorPickerFBGSprite, Assets::UIColorPickerFBG_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerHBGSprite, m_UIColorPickerHBGSprite, Assets::UIColorPickerHBG_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerSBGSprite, m_UIColorPickerSBGSprite, Assets::UIColorPickerSBG_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIColorPickerVBGSprite, m_UIColorPickerVBGSprite, Assets::UIColorPickerVBG_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIDownArrowSprite, m_UIDownArrowSprite, Assets::UIDownArrow_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIIconGearSprite, m_UIIconGear, Assets::UIIconGear_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIIconLockedSprite, m_UIIconLocked, Assets::UIIconLocked_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIIconUnlockedSprite, m_UIIconUnlocked, Assets::UIIconUnlocked_png, Vector4::get_zero()); + AUTO_SPRITE_GETTER(UISystem::GetUIRectBGSprite, m_UIRectBGSprite, Assets::UIRectBG_png, Vector4(15, 15, 15, 15)); + AUTO_SPRITE_GETTER(UISystem::GetUIRoundBGSprite, m_UIRoundBGSprite, Assets::UIRoundBG_png, Vector4(15, 15, 15, 15)); + AUTO_SPRITE_GETTER(UISystem::GetUIRoundRectLeftBGSprite, m_UIRoundRectLeftBGSprite, Assets::UIRoundRectLeftBG_png, Vector4(15, 15, 15, 15)); + AUTO_SPRITE_GETTER(UISystem::GetUIRoundRectRightBGSprite, m_UIRoundRectRightBGSprite, Assets::UIRoundRectRightBG_png, Vector4(15, 15, 15, 15)); + AUTO_SPRITE_GETTER(UISystem::GetUIRoundSmoothFrameSprite, m_UIRoundSmoothFrameSprite, Assets::UIRoundSmoothFrame_png, Vector4(15, 15, 15, 15)); + AUTO_SPRITE_GETTER(UISystem::GetUISliderBGSprite, m_UISliderBGSprite, Assets::UISliderBG_png, Vector4(15, 15, 15, 15)); + AUTO_SPRITE_GETTER(UISystem::GetUISliderHandleSprite, m_UISliderHandleSprite, Assets::UISliderHandle_png, Vector4::get_zero()); #undef AUTO_SPRITE_GETTER @@ -191,12 +192,12 @@ namespace CP_SDK::UI { return ViewController::_Instance(p_Type); auto l_GameObject = GameObject::New_ctor(p_Type->get_Name(), ArrayW({ - reinterpret_cast(csTypeOf(RectTransform*)), - reinterpret_cast(csTypeOf(CanvasGroup*)) + reinterpret_cast(csTypeOf(RectTransform*).convert()), + reinterpret_cast(csTypeOf(CanvasGroup*).convert()) })); GameObject::DontDestroyOnLoad(l_GameObject); - auto l_ViewController = reinterpret_cast(l_GameObject->AddComponent(p_Type)); + auto l_ViewController = l_GameObject->AddComponent(p_Type).try_cast().value_or(nullptr); l_ViewController->RTransform()->set_anchorMin (Vector2::get_zero()); l_ViewController->RTransform()->set_anchorMax (Vector2::get_one()); l_ViewController->RTransform()->set_sizeDelta (Vector2::get_zero()); diff --git a/src/CP_SDK/UI/ViewController.cpp b/src/CP_SDK/UI/ViewController.cpp index d988ae2..882509f 100644 --- a/src/CP_SDK/UI/ViewController.cpp +++ b/src/CP_SDK/UI/ViewController.cpp @@ -3,6 +3,9 @@ #include "CP_SDK/UI/IModal.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" +#include +#include + using namespace CP_SDK::Unity::Extensions; using namespace UnityEngine; using namespace UnityEngine::UI; @@ -86,6 +89,26 @@ namespace CP_SDK::UI { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// + ViewController* ViewController::_Instance(_u::Type* p_Type) + { + if (p_Type && m_Instances.contains(p_Type)) + return m_Instances[p_Type].Ptr(false); + + return nullptr; + } + _v::MonoPtr& ViewController::_InstanceEx(_u::Type* p_Type) + { + static auto s_Default = _v::MonoPtr(nullptr); + + if (p_Type && m_Instances.contains(p_Type)) + return m_Instances[p_Type]; + + return s_Default; + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + /// @brief Can UI be updated bool ViewController::CanBeUpdated() { @@ -184,7 +207,7 @@ namespace CP_SDK::UI { IModal* ViewController::CreateModal_Impl(System::Type* p_Type) { auto l_GameObject = GameObject::New_ctor(p_Type->get_Name(), ArrayW({ - reinterpret_cast(csTypeOf(RectTransform*)), + reinterpret_cast(csTypeOf(RectTransform*).convert()), p_Type, UISystem::Override_UnityComponent_Image.ptr() })); @@ -197,7 +220,7 @@ namespace CP_SDK::UI { l_Modal->RTransform()->set_anchoredPosition(Vector2(0.0f, 0.0f)); l_Modal->RTransform()->set_sizeDelta (Vector2(0.0f, 0.0f)); - auto l_Background = reinterpret_cast(l_GameObject->GetComponent(UISystem::Override_UnityComponent_Image.ptr())); + auto l_Background = l_GameObject->GetComponent(UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_Background->set_material (UISystem::Override_GetUIMaterial()); l_Background->set_raycastTarget (true); l_Background->set_pixelsPerUnitMultiplier (1); diff --git a/src/CP_SDK/UI/Views/MainRightView.cpp b/src/CP_SDK/UI/Views/MainRightView.cpp index 3a47362..4e6e914 100644 --- a/src/CP_SDK/UI/Views/MainRightView.cpp +++ b/src/CP_SDK/UI/Views/MainRightView.cpp @@ -30,7 +30,7 @@ namespace CP_SDK::UI::Views { /// @brief On view creation void MainRightView::OnViewCreation_Impl() { - auto l_Sprite = Unity::SpriteU::CreateFromRaw(IncludedAssets::ChatPlexLogoTransparent_png.Raw()); + auto l_Sprite = Unity::SpriteU::CreateFromRaw(Assets::ChatPlexLogoTransparent_png); Templates::FullRectLayout({ Templates::TitleBar(u"Powered By"), diff --git a/src/CP_SDK/UI/Views/TopNavigationView.cpp b/src/CP_SDK/UI/Views/TopNavigationView.cpp index a008391..11f8dd3 100644 --- a/src/CP_SDK/UI/Views/TopNavigationView.cpp +++ b/src/CP_SDK/UI/Views/TopNavigationView.cpp @@ -40,7 +40,7 @@ namespace CP_SDK::UI::Views { XUIHLayout::Make({ XUIText::Make(u"super test title!") - ->SetStyle(TMPro::FontStyles::UpperCase | TMPro::FontStyles::Bold) + ->SetStyle(TMPro::FontStyles::UpperCase.value__ | TMPro::FontStyles::Bold.value__) ->SetFontSize(4.5f) ->Bind(&m_Title) ->AsShared() diff --git a/src/CP_SDK/Unity/EnhancedImage.cpp b/src/CP_SDK/Unity/EnhancedImage.cpp index c4e5111..4da414f 100644 --- a/src/CP_SDK/Unity/EnhancedImage.cpp +++ b/src/CP_SDK/Unity/EnhancedImage.cpp @@ -111,11 +111,11 @@ namespace CP_SDK::Unity { /// @param p_ForcedHeight Forced height void EnhancedImage::FromRawAnimated(std::u16string p_ID, Animation::EAnimationType p_Type, _v::CMonoPtrRef<::Array> p_Bytes, _v::CActionRef p_Callback, int p_ForcedHeight) { - if (p_Type == Animation::EAnimationType::AUTODETECT && p_Bytes->Length() > 0) + if (p_Type == Animation::EAnimationType::AUTODETECT && p_Bytes->get_Length() > 0) { - if (p_Bytes->Length() > 3 && p_Bytes->values[0] == 0x47 && ContainBytePattern(p_Bytes, ANIMATED_GIF_PATTERN, sizeof(ANIMATED_GIF_PATTERN))) + if (p_Bytes->get_Length() > 3 && p_Bytes->_values[0] == 0x47 && ContainBytePattern(p_Bytes, ANIMATED_GIF_PATTERN, sizeof(ANIMATED_GIF_PATTERN))) p_Type = Animation::EAnimationType::GIF; - else if (p_Bytes->Length() > 16 && ContainBytePattern(p_Bytes, WEBPVP8_PATTERN, sizeof(WEBPVP8_PATTERN))) + else if (p_Bytes->get_Length() > 16 && ContainBytePattern(p_Bytes, WEBPVP8_PATTERN, sizeof(WEBPVP8_PATTERN))) p_Type = Animation::EAnimationType::WEBP; else p_Type = Animation::EAnimationType::NONE; @@ -313,9 +313,9 @@ namespace CP_SDK::Unity { bool EnhancedImage::ContainBytePattern(_v::CMonoPtrRef<::Array> p_Array, const uint8_t* p_Pattern, int p_PatternSize) { auto l_PatternPosition = 0; - for (int l_I = 0; l_I < p_Array->Length(); ++l_I) + for (int l_I = 0; l_I < p_Array->get_Length(); ++l_I) { - if (p_Array->values[l_I] != p_Pattern[l_PatternPosition]) + if (p_Array->_values[l_I] != p_Pattern[l_PatternPosition]) { l_PatternPosition = 0; continue; diff --git a/src/CP_SDK/Unity/FontManager.cpp b/src/CP_SDK/Unity/FontManager.cpp index 037b1db..0b06c0a 100644 --- a/src/CP_SDK/Unity/FontManager.cpp +++ b/src/CP_SDK/Unity/FontManager.cpp @@ -13,7 +13,8 @@ namespace CP_SDK::Unity { bool FontManager::m_IsInitialized = false; _v::MonoPtr FontManager::m_AssetBundle = nullptr; - _v::MonoPtr FontManager::m_BundleFont = nullptr; + _v::MonoPtr FontManager::m_BundleMainFont = nullptr; + _v::MonoPtr FontManager::m_BundleChatFont = nullptr; _v::MonoPtr FontManager::m_MainFont = nullptr; _v::MonoPtr FontManager::m_ChatFont = nullptr; _v::Func<_u::TMP_FontAsset*, _u::TMP_FontAsset*> FontManager::m_TMPFontAssetSetup = nullptr; @@ -30,9 +31,11 @@ namespace CP_SDK::Unity { /// @brief Init the font manager void FontManager::Init() { + ChatPlexSDK::Logger()->Error(u"[CP_SDK.Unity][FontManager.Init] Loading font asset bundle..."); + static auto s_LoadFromMemory = reinterpret_cast(il2cpp_functions::resolve_icall("UnityEngine.AssetBundle::LoadFromMemory_Internal")); - m_AssetBundle = s_LoadFromMemory(IncludedAssets::QuestFonts_bundle.Raw(), 0); + m_AssetBundle = s_LoadFromMemory(Assets::QuestFonts_bundle, 0); if (!m_AssetBundle) { ChatPlexSDK::Logger()->Error(u"[CP_SDK.Unity][FontManager.Init] Failed to load the font asset bundle"); @@ -56,24 +59,19 @@ namespace CP_SDK::Unity { if (!m_MainFont) { - if (!m_BundleFont) - m_BundleFont = m_AssetBundle->LoadAsset("[CP_SDK]segoeui SDF"); + if (!m_BundleMainFont) + m_BundleMainFont = m_AssetBundle->LoadAsset("[CP_SDK]segoeui SDF Main"); - m_MainFont = TMP_FontAsset::CreateFontAsset(m_BundleFont.Ptr()->get_sourceFontFile()); - m_MainFont->set_name(m_BundleFont->get_name() + " CloneMain"); - m_MainFont->hashCode = TMP_TextUtilities::GetSimpleHashCode(m_MainFont->get_name()); - m_MainFont->set_fallbackFontAssetTable(m_BundleFont->get_fallbackFontAssetTable()); + m_MainFont = m_BundleMainFont; if (m_TMPFontAssetSetup.IsValid()) m_MainFont = m_TMPFontAssetSetup(m_MainFont.Ptr()); - m_MainFont->normalStyle = 0.5f; - m_MainFont->normalSpacingOffset = -1.0f; - m_MainFont->boldStyle = 2.0f; - m_MainFont->boldSpacing = 2.0f; - m_MainFont->italicStyle = 15; - - m_ChatFont = m_BundleFont.Ptr(); + m_MainFont->___normalStyle = 0.5f; + m_MainFont->___normalSpacingOffset = -1.0f; + m_MainFont->___boldStyle = 2.0f; + m_MainFont->___boldSpacing = 2.0f; + m_MainFont->___italicStyle = 15; } return m_MainFont.Ptr(); @@ -86,10 +84,10 @@ namespace CP_SDK::Unity { if (!m_ChatFont) { - if (!m_BundleFont) - m_BundleFont = m_AssetBundle->LoadAsset("[CP_SDK]segoeui SDF"); + if (!m_BundleChatFont) + m_BundleChatFont = m_AssetBundle->LoadAsset("[CP_SDK]segoeui SDF"); - m_ChatFont = m_BundleFont.Ptr(); + m_ChatFont = m_BundleChatFont.Ptr(); if (m_TMPFontAssetSetup.IsValid()) m_ChatFont = m_TMPFontAssetSetup(m_ChatFont.Ptr()); diff --git a/src/CP_SDK/Unity/MTThreadInvoker.cpp b/src/CP_SDK/Unity/MTThreadInvoker.cpp index de17525..6685e96 100644 --- a/src/CP_SDK/Unity/MTThreadInvoker.cpp +++ b/src/CP_SDK/Unity/MTThreadInvoker.cpp @@ -11,17 +11,12 @@ const int MAX_QUEUE_SIZE = 1000; namespace CP_SDK::Unity { - CP_SDK_IL2CPP_INHERIT_INIT(__MTThreadInvokerDummy); - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - bool MTThreadInvoker::m_RunCondition = false; - _v::MonoPtr<_u::Thread> MTThreadInvoker::m_UpdateThread; - MTThreadInvoker::Queue** MTThreadInvoker::m_Queues; - bool MTThreadInvoker::m_Queued = false; - int MTThreadInvoker::m_FrontQueue = 0; - std::mutex MTThreadInvoker::m_Mutex; + bool MTThreadInvoker::m_RunCondition = false; + il2cpp_utils::il2cpp_aware_thread* MTThreadInvoker::m_UpdateThread = nullptr; + MTThreadInvoker::Queue** MTThreadInvoker::m_Queues; + bool MTThreadInvoker::m_Queued = false; + int MTThreadInvoker::m_FrontQueue = 0; + std::mutex MTThreadInvoker::m_Mutex; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -29,7 +24,7 @@ namespace CP_SDK::Unity { /// @brief Initialize void MTThreadInvoker::Initialize() { - if (m_UpdateThread != 0) + if (m_UpdateThread) return; m_Queues = new MTThreadInvoker::Queue*[2]; @@ -43,25 +38,19 @@ namespace CP_SDK::Unity { m_RunCondition = true; - auto l_ThreadStartMethod = il2cpp_functions::class_get_method_from_name(classof(__MTThreadInvokerDummy*), "Dummy", 0); - m_UpdateThread = _u::Thread::New_ctor( - _u::ThreadStart::New_ctor( - nullptr, - _u::IntPtr(reinterpret_cast(l_ThreadStartMethod)) - ) - ); - m_UpdateThread->Start(); + m_UpdateThread = new il2cpp_utils::il2cpp_aware_thread(&MTThreadInvoker::__INTERNAL_Update); } /// @brief Stop void MTThreadInvoker::Destroy() { - if (m_UpdateThread == 0) + if (!m_UpdateThread) return; m_RunCondition = false; - if (m_UpdateThread && m_UpdateThread->get_IsAlive()) - m_UpdateThread->Join(); - m_UpdateThread = 0; + if (m_UpdateThread->joinable()) + m_UpdateThread->join(); + delete m_UpdateThread; + m_UpdateThread = nullptr; for (int l_I = 0; l_I < 2; ++l_I) { @@ -162,13 +151,4 @@ namespace CP_SDK::Unity { } } - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - /// @brief Dummy method for thread start - void __MTThreadInvokerDummy::Dummy() - { - MTThreadInvoker::__INTERNAL_Update(); - } - } ///< namespace CP_SDK::Unity \ No newline at end of file diff --git a/src/CP_SDK/Unity/Texture2DU.cpp b/src/CP_SDK/Unity/Texture2DU.cpp index c41cc76..a386b2c 100644 --- a/src/CP_SDK/Unity/Texture2DU.cpp +++ b/src/CP_SDK/Unity/Texture2DU.cpp @@ -17,7 +17,7 @@ namespace CP_SDK::Unity { /// @param p_Bytes Raw Texture 2D data Texture2D* Texture2DU::CreateFromRaw(::Array* p_Bytes) { - if (p_Bytes->Length() > 0) + if (p_Bytes->get_Length() > 0) { try { @@ -39,7 +39,7 @@ namespace CP_SDK::Unity { /// @param p_Callback Callback void Texture2DU::CreateFromRawThreaded(_v::MonoPtr<::Array> p_Bytes, _v::Action p_Callback) { - if (p_Bytes && p_Bytes->Length() > 0) + if (p_Bytes && p_Bytes->get_Length() > 0) { stbi_uc* l_STBIBuffer = nullptr; try @@ -48,12 +48,12 @@ namespace CP_SDK::Unity { int l_Width; int l_Height; - if (!stbi_info_from_memory(p_Bytes->values, p_Bytes->Length(), &l_Width, &l_Height, &l_InputChannels)) + if (!stbi_info_from_memory(p_Bytes->_values, p_Bytes->get_Length(), &l_Width, &l_Height, &l_InputChannels)) throw std::runtime_error("Failed to load picture"); stbi_set_flip_vertically_on_load(1); - l_STBIBuffer = stbi_load_from_memory(p_Bytes->values, p_Bytes->Length(), &l_Width, &l_Height, &l_InputChannels, 4); + l_STBIBuffer = stbi_load_from_memory(p_Bytes->_values, p_Bytes->get_Length(), &l_Width, &l_Height, &l_InputChannels, 4); if (!l_STBIBuffer) throw std::runtime_error("Failed to load picture"); @@ -62,7 +62,7 @@ namespace CP_SDK::Unity { for (auto l_I = 0; l_I < (l_Width * l_Height); ++l_I) { auto l_SrcPixel = &l_STBIBuffer[l_I * 4]; - l_Pixels->values[l_I] = Extensions::ColorU::Convert(Color32(l_SrcPixel[0], l_SrcPixel[1], l_SrcPixel[2], l_SrcPixel[3])); + l_Pixels->_values[l_I] = Extensions::ColorU::Convert(Color32(0, l_SrcPixel[0], l_SrcPixel[1], l_SrcPixel[2], l_SrcPixel[3])); } stbi_image_free(l_STBIBuffer); diff --git a/src/CP_SDK/Unity/TextureRaw.cpp b/src/CP_SDK/Unity/TextureRaw.cpp index e60f192..9e5bdb7 100644 --- a/src/CP_SDK/Unity/TextureRaw.cpp +++ b/src/CP_SDK/Unity/TextureRaw.cpp @@ -1,5 +1,6 @@ #include "CP_SDK/Unity/TextureRaw.hpp" #include "CP_SDK/Unity/Extensions/ColorU.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include "CP_SDK/ChatPlexSDK.hpp" #define STB_IMAGE_IMPLEMENTATION @@ -29,17 +30,17 @@ namespace CP_SDK::Unity { p_Width = 0; p_Height = 0; - if (p_Bytes == nullptr && p_Bytes->Length() == 0) + if (p_Bytes == nullptr && p_Bytes->get_Length() == 0) return false; int l_InputChannels; - if (!stbi_info_from_memory(p_Bytes->values, p_Bytes->Length(), &p_Width, &p_Height, &l_InputChannels)) + if (!stbi_info_from_memory(p_Bytes->_values, p_Bytes->get_Length(), &p_Width, &p_Height, &l_InputChannels)) return false; stbi_set_flip_vertically_on_load(1); - auto l_STBIBuffer = stbi_load_from_memory(p_Bytes->values, p_Bytes->Length(), &p_Width, &p_Height, &l_InputChannels, 4); + auto l_STBIBuffer = stbi_load_from_memory(p_Bytes->_values, p_Bytes->get_Length(), &p_Width, &p_Height, &l_InputChannels, 4); if (!l_STBIBuffer) return false; @@ -51,7 +52,7 @@ namespace CP_SDK::Unity { for (auto l_I = 0; l_I < (p_Width * p_Height); ++l_I) { auto l_SrcPixel = &l_STBIBuffer[l_I * 4]; - l_Pixels[l_I] = Extensions::ColorU::Convert(Color32(l_SrcPixel[0], l_SrcPixel[1], l_SrcPixel[2], l_SrcPixel[3])); + l_Pixels[l_I] = Extensions::ColorU::Convert(Color32(0, l_SrcPixel[0], l_SrcPixel[1], l_SrcPixel[2], l_SrcPixel[3])); } stbi_image_free(l_STBIBuffer); @@ -192,26 +193,26 @@ namespace CP_SDK::Unity { auto l_RI = l_TI + p_Radius; auto l_FV = l_InPixels[l_TI]; auto l_LV = l_InPixels[l_TI + p_Width - 1]; - auto l_Val = (p_Radius + 1) * l_FV; + auto l_Val = (p_Radius + 1.0f) * l_FV; for (auto l_J = 0; l_J < p_Radius; ++l_J) - l_Val = l_Val + (l_InPixels[l_TI + l_J]); + l_Val += l_InPixels[l_TI + l_J]; for (auto l_J = 0; l_J <= p_Radius; ++l_J) { - l_Val = l_Val + (l_InPixels[l_RI++] - l_FV); + l_Val += l_InPixels[l_RI++] - l_FV; l_InPixels[l_TI++] = l_Val * l_Mult; } for (auto l_J = p_Radius + 1; l_J < p_Width - p_Radius; ++l_J) { - l_Val = l_Val + (l_InPixels[l_RI++] - l_InPixels[l_LI++]); + l_Val += l_InPixels[l_RI++] - l_InPixels[l_LI++]; l_InPixels[l_TI++] = l_Val * l_Mult; } for (auto l_J = p_Width - p_Radius; l_J < p_Width; ++l_J) { - l_Val = l_Val + (l_LV - l_InPixels[l_LI++]); + l_Val += l_LV - l_InPixels[l_LI++]; l_InPixels[l_TI++] = l_Val * l_Mult; } }; @@ -230,11 +231,11 @@ namespace CP_SDK::Unity { auto l_Val = (p_Radius + 1) * l_FV; for (auto l_J = 0; l_J < p_Radius; ++l_J) - l_Val = l_Val + (l_InPixels[l_TI + l_J * p_Width]); + l_Val += l_InPixels[l_TI + l_J * p_Width]; for (auto l_J = 0; l_J <= p_Radius; ++l_J) { - l_Val = l_Val + (l_InPixels[l_RI] - l_FV); + l_Val += l_InPixels[l_RI] - l_FV; l_InPixels[l_TI] = l_Val * l_Mult; l_RI += p_Width; l_TI += p_Width; @@ -242,7 +243,7 @@ namespace CP_SDK::Unity { for (auto l_J = p_Radius + 1; l_J < p_Height - p_Radius; ++l_J) { - l_Val = l_Val + (l_InPixels[l_RI] - l_InPixels[l_LI]); + l_Val += l_InPixels[l_RI] - l_InPixels[l_LI]; l_InPixels[l_TI] = l_Val * l_Mult; l_LI += p_Width; l_RI += p_Width; @@ -251,7 +252,7 @@ namespace CP_SDK::Unity { for (auto l_J = p_Height - p_Radius; l_J < p_Height; ++l_J) { - l_Val = l_Val + (l_LV - l_InPixels[l_LI]); + l_Val += l_LV - l_InPixels[l_LI]; l_InPixels[l_TI] = l_Val * l_Mult; l_LI += p_Width; l_TI += p_Width; diff --git a/src/CP_SDK/Utils/Il2cpp.cpp b/src/CP_SDK/Utils/Il2cpp.cpp index 0a750c4..7af7769 100644 --- a/src/CP_SDK/Utils/Il2cpp.cpp +++ b/src/CP_SDK/Utils/Il2cpp.cpp @@ -3,21 +3,21 @@ namespace CP_SDK::Utils { - std::vector Hooks::m_InstalledFuncs; + std::vector Hooks::m_InstalledFuncs; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// Register a hook /// @param p_Function Function to register - void Hooks::Register(void (*p_Function)(Logger&)) + void Hooks::Register(void (*p_Function)(Paper::LoggerContext&)) { m_InstalledFuncs.push_back(p_Function); } /// Install all hooks void Hooks::InstallHooks() { - auto l_Logger = reinterpret_cast(ChatPlexSDK::Logger())->GetBMBFLogger(); + auto l_Logger = reinterpret_cast(ChatPlexSDK::Logger())->GetPaperLogger(); for (auto& l_Current : m_InstalledFuncs) l_Current(*l_Logger); } diff --git a/src/CP_SDK_BS/Game/BeatMapsClient.cpp b/src/CP_SDK_BS/Game/BeatMapsClient.cpp index 6ed9922..375de1c 100644 --- a/src/CP_SDK_BS/Game/BeatMapsClient.cpp +++ b/src/CP_SDK_BS/Game/BeatMapsClient.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include #include #include @@ -225,7 +225,7 @@ namespace CP_SDK_BS::Game { p_Token, [=](_v::CMonoPtrRef<::Array> p_Result) -> void { - if (!p_Result || (p_Token.m_source && p_Token.m_source->get_IsCancellationRequested())) + if (!p_Result || (p_Token._source && p_Token._source->get_IsCancellationRequested())) { p_Callback(false, _default); return; @@ -233,11 +233,11 @@ namespace CP_SDK_BS::Game { try { - std::u16string l_CustomSongsPath = _v::StrToU16Str(RuntimeSongLoader::API::GetCustomLevelsPath()); + std::u16string l_CustomSongsPath = _v::StrToU16Str(SongCore::API::Loading::GetPreferredCustomLevelPath().string()); CP_SDK::ChatPlexSDK::Logger()->Info(u"[CP_SDK_BS.Game][BeatMapsClient] Downloaded zip!"); - if (p_Token.m_source && p_Token.m_source->get_IsCancellationRequested()) + if (p_Token._source && p_Token._source->get_IsCancellationRequested()) { p_Callback(false, _default); return; @@ -276,11 +276,11 @@ namespace CP_SDK_BS::Game { /// Prepare base path auto l_BasePath = p_Song->id + u" (" + p_Song->metadata.value().songName + u" - " + p_Song->metadata.value().levelAuthorName + u")"; - auto l_InvalidChars = Path::GetInvalidFileNameChars(); + auto l_InvalidChars = Path::GetInvalidPathChars(); for (auto l_I = 0; l_I < l_BasePath.length(); ++l_I) { - if (!l_InvalidChars.Contains(l_BasePath[l_I])) + if (!l_InvalidChars.contains(l_BasePath[l_I])) continue; l_BasePath = l_BasePath.substr(0, l_I) + l_BasePath.substr(l_I + 1); @@ -305,7 +305,7 @@ namespace CP_SDK_BS::Game { /// zip_stream_extract create directory if needed int l_Args = 2; - auto l_ExtractResult = zip_stream_extract((const char*)p_ZIPBytes->values, p_ZIPBytes->Length(), l_OutPath.c_str(), +[](const char*, void*) -> int { + auto l_ExtractResult = zip_stream_extract((const char*)p_ZIPBytes->_values, p_ZIPBytes->get_Length(), l_OutPath.c_str(), +[](const char*, void*) -> int { return 0; }, &l_Args); diff --git a/src/CP_SDK_BS/Game/LevelCompletionData.cpp b/src/CP_SDK_BS/Game/LevelCompletionData.cpp index 1099424..ac22363 100644 --- a/src/CP_SDK_BS/Game/LevelCompletionData.cpp +++ b/src/CP_SDK_BS/Game/LevelCompletionData.cpp @@ -1,11 +1,10 @@ #include "CP_SDK_BS/Game/LevelCompletionData.hpp" #include "CP_SDK_BS/Game/Levels.hpp" -#include +#include #include -#include -#include +#include namespace CP_SDK_BS::Game { @@ -15,7 +14,7 @@ namespace CP_SDK_BS::Game { return false; std::vector l_Requirements; - if (Levels::TryGetCustomRequirementsFor(Data->previewBeatmapLevel, Data->difficultyBeatmap->get_parentDifficultyBeatmapSet()->get_beatmapCharacteristic(), Data->difficultyBeatmap->get_difficulty(), &l_Requirements)) + if (Levels::TryGetCustomRequirementsFor(Data->beatmapLevel, Data->beatmapKey.beatmapCharacteristic, Data->beatmapKey.difficulty, &l_Requirements)) { for (auto& l_Current : l_Requirements) { @@ -34,7 +33,7 @@ namespace CP_SDK_BS::Game { return false; std::vector l_Requirements; - if (Levels::TryGetCustomRequirementsFor(Data->previewBeatmapLevel, Data->difficultyBeatmap->get_parentDifficultyBeatmapSet()->get_beatmapCharacteristic(), Data->difficultyBeatmap->get_difficulty(), &l_Requirements)) + if (Levels::TryGetCustomRequirementsFor(Data->beatmapLevel, Data->beatmapKey.beatmapCharacteristic, Data->beatmapKey.difficulty, &l_Requirements)) { for (auto& l_Current : l_Requirements) { diff --git a/src/CP_SDK_BS/Game/LevelData.cpp b/src/CP_SDK_BS/Game/LevelData.cpp index 5b0e414..489172f 100644 --- a/src/CP_SDK_BS/Game/LevelData.cpp +++ b/src/CP_SDK_BS/Game/LevelData.cpp @@ -1,11 +1,10 @@ #include "CP_SDK_BS/Game/LevelData.hpp" #include "CP_SDK_BS/Game/Levels.hpp" -#include +#include #include -#include -#include +#include namespace CP_SDK_BS::Game { @@ -18,11 +17,11 @@ namespace CP_SDK_BS::Game { } bool LevelData::IsNoodle() { - if (!Data || !Data->previewBeatmapLevel) + if (!Data || !Data->beatmapLevel) return false; std::vector l_Requirements; - if (Levels::TryGetCustomRequirementsFor(Data->previewBeatmapLevel, Data->difficultyBeatmap->get_parentDifficultyBeatmapSet()->get_beatmapCharacteristic(), Data->difficultyBeatmap->get_difficulty(), &l_Requirements)) + if (Levels::TryGetCustomRequirementsFor(Data->beatmapLevel, Data->beatmapKey.beatmapCharacteristic, Data->beatmapKey.difficulty, &l_Requirements)) { for (auto& l_Current : l_Requirements) { @@ -41,7 +40,7 @@ namespace CP_SDK_BS::Game { return false; std::vector l_Requirements; - if (Levels::TryGetCustomRequirementsFor(Data->previewBeatmapLevel, Data->difficultyBeatmap->get_parentDifficultyBeatmapSet()->get_beatmapCharacteristic(), Data->difficultyBeatmap->get_difficulty(), &l_Requirements)) + if (Levels::TryGetCustomRequirementsFor(Data->beatmapLevel, Data->beatmapKey.beatmapCharacteristic, Data->beatmapKey.difficulty, &l_Requirements)) { for (auto& l_Current : l_Requirements) { diff --git a/src/CP_SDK_BS/Game/LevelSelection.cpp b/src/CP_SDK_BS/Game/LevelSelection.cpp index 1fa8e27..02b8c39 100644 --- a/src/CP_SDK_BS/Game/LevelSelection.cpp +++ b/src/CP_SDK_BS/Game/LevelSelection.cpp @@ -2,21 +2,21 @@ #include "CP_SDK_BS/Game/Logic.hpp" #include "CP_SDK/Unity/MTCoroutineStarter.hpp" #include +#include -#include +#include #include #include #include -#include +#include #include -#include #include #include namespace CP_SDK_BS::Game { - _v::MonoPtr<_u::CustomPreviewBeatmapLevel> LevelSelection::m_PendingFilterSong; - bool LevelSelection::m_PreventLevelSearchViewController_didStartLoadingEvent; + _v::MonoPtr<_u::BeatmapLevel> LevelSelection::m_PendingFilterSong; + bool LevelSelection::m_PreventLevelSearchViewController_didStartLoadingEvent; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -28,13 +28,13 @@ namespace CP_SDK_BS::Game { /// @brief Filter to specific song /// @param p_SongToFilter Song to filter - bool LevelSelection::FilterToSpecificSong(_u::CustomPreviewBeatmapLevel* p_SongToFilter) + bool LevelSelection::FilterToSpecificSong(_u::BeatmapLevel* p_SongToFilter) { m_PendingFilterSong = p_SongToFilter; try { - auto l_LevelFilteringNavigationController = _u::Resources::FindObjectsOfTypeAll<_u::LevelSelectionNavigationController*>().FirstOrDefault(); + auto l_LevelFilteringNavigationController = _u::Resources::FindObjectsOfTypeAll<_u::LevelSelectionNavigationController*>()->FirstOrDefault(); if (l_LevelFilteringNavigationController) { if (l_LevelFilteringNavigationController->get_gameObject()->get_activeInHierarchy()) @@ -101,7 +101,7 @@ namespace CP_SDK_BS::Game { /// @param p_LevelSelectionNavigationController LevelSelectionNavigationController instance custom_types::Helpers::Coroutine LevelSelection::LevelSelection_SelectLevelCategory(_u::LevelSelectionNavigationController* p_LevelSelectionNavigationController) { - while (!_v::IsUnityPtrValid(p_LevelSelectionNavigationController) || p_LevelSelectionNavigationController->isInTransition) + while (!_v::IsUnityPtrValid(p_LevelSelectionNavigationController) || p_LevelSelectionNavigationController->____isInTransition) { if (!_v::IsUnityPtrValid(p_LevelSelectionNavigationController)) co_return; @@ -115,23 +115,23 @@ namespace CP_SDK_BS::Game { if (!p_LevelSelectionNavigationController || !p_LevelSelectionNavigationController->get_isInViewControllerHierarchy() || !p_LevelSelectionNavigationController->get_isActiveAndEnabled()) co_return; - auto l_LevelFilteringNavigationController = p_LevelSelectionNavigationController->levelFilteringNavigationController; - if (!_v::IsUnityPtrValid(l_LevelFilteringNavigationController)) + auto l_LevelFilteringNavigationController = p_LevelSelectionNavigationController->____levelFilteringNavigationController; + if (!l_LevelFilteringNavigationController.isAlive()) co_return; if (l_LevelFilteringNavigationController->get_selectedLevelCategory() != _u::SelectLevelCategoryViewController::LevelCategory::All) { - auto l_Selector = l_LevelFilteringNavigationController->selectLevelCategoryViewController; - if (_v::IsUnityPtrValid(l_Selector)) + auto l_Selector = l_LevelFilteringNavigationController->____selectLevelCategoryViewController; + if (l_Selector.isAlive()) { - auto l_SegmentControl = l_Selector->levelFilterCategoryIconSegmentedControl; - auto l_Tags = l_Selector->levelCategoryInfos; + auto l_SegmentControl = l_Selector->____levelFilterCategoryIconSegmentedControl; + auto l_Tags = l_Selector->____levelCategoryInfos; auto l_IndexToSelect = -1; - for (auto l_I = 0; l_I < l_Tags.Length(); ++l_I) + for (auto l_I = 0; l_I < l_Tags->get_Length(); ++l_I) { - if (l_Tags[l_I]->levelCategory != _u::SelectLevelCategoryViewController::LevelCategory::All) + if (l_Tags[l_I]->___levelCategory != _u::SelectLevelCategoryViewController::LevelCategory::All) continue; l_IndexToSelect = l_I; @@ -147,7 +147,7 @@ namespace CP_SDK_BS::Game { CP_SDK::Unity::MTCoroutineStarter::Start(custom_types::Helpers::CoroutineHelper::New( LevelSelection_FilterLevel( - l_LevelFilteringNavigationController->levelSearchViewController, + l_LevelFilteringNavigationController->____levelSearchViewController, true ) )); @@ -157,7 +157,7 @@ namespace CP_SDK_BS::Game { { CP_SDK::Unity::MTCoroutineStarter::Start(custom_types::Helpers::CoroutineHelper::New( LevelSelection_FilterLevel( - l_LevelFilteringNavigationController->levelSearchViewController, + l_LevelFilteringNavigationController->____levelSearchViewController, false ) )); @@ -176,7 +176,7 @@ namespace CP_SDK_BS::Game { if (p_Wait) { - while (!_v::IsUnityPtrValid(p_LevelSearchViewController) || p_LevelSearchViewController->isInTransition) + while (!_v::IsUnityPtrValid(p_LevelSearchViewController) || p_LevelSearchViewController->____isInTransition) { if (!_v::IsUnityPtrValid(p_LevelSearchViewController)) co_return; @@ -194,13 +194,14 @@ namespace CP_SDK_BS::Game { try { m_PreventLevelSearchViewController_didStartLoadingEvent = true; - p_LevelSearchViewController->ResetCurrentFilterParams(); + p_LevelSearchViewController->ResetAllFilterSettings(false); - auto l_Set = System::Collections::Generic::HashSet_1<::StringW>::New_ctor(); - l_Set->Add(m_PendingFilterSong->levelID); + auto l_Filter = GlobalNamespace::LevelFilter(); + l_Filter.limitIds = ArrayW({ m_PendingFilterSong->___levelID }); + l_Filter.searchText = u""; - p_LevelSearchViewController->UpdateSearchLevelFilterParams( - _u::LevelFilterParams::ByBeatmapLevelIds(l_Set) + p_LevelSearchViewController->Refresh( + byref(l_Filter) ); m_PreventLevelSearchViewController_didStartLoadingEvent = false; } @@ -222,13 +223,13 @@ namespace CP_SDK_BS::Game { try { - auto l_Filter = p_LevelSearchViewController->currentFilterParams; - if (l_Filter && l_Filter->filterByLevelIds) + auto l_Filter = p_LevelSearchViewController->____currentSearchFilter; + if (l_Filter.limitIds && l_Filter.limitIds->get_Length() == 1) { - p_LevelSearchViewController->ResetCurrentFilterParams(); + p_LevelSearchViewController->ResetAllFilterSettings(false); - auto l_InputFieldView = p_LevelSearchViewController->searchTextInputFieldView; - if (_v::IsUnityPtrValid(l_InputFieldView)) + auto l_InputFieldView = p_LevelSearchViewController->____searchTextInputFieldView; + if (l_InputFieldView) { l_InputFieldView->UpdateClearButton(); l_InputFieldView->UpdatePlaceholder(); @@ -237,7 +238,7 @@ namespace CP_SDK_BS::Game { } catch (const std::exception& l_Exception) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][LevelSearchViewController_LevelSearchViewController_UpdateBeatmapLevelPackCollectionAsync] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][LevelSearchViewController_didStartLoadingEvent] Error:"); CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); } } @@ -246,12 +247,12 @@ namespace CP_SDK_BS::Game { //////////////////////////////////////////////////////////////////////////// CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( - LevelSearchViewController_UpdateBeatmapLevelPackCollectionAsync, &_u::LevelSearchViewController::UpdateBeatmapLevelPackCollectionAsync, + LevelSearchViewController_RefreshAsync, &_u::LevelSearchViewController::RefreshAsync, void, _u::LevelSearchViewController* __Instance) { - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter LevelSearchViewController_UpdateBeatmapLevelPackCollectionAsync"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter LevelSearchViewController_RefreshAsync"); - LevelSearchViewController_UpdateBeatmapLevelPackCollectionAsync(__Instance); + LevelSearchViewController_RefreshAsync(__Instance); try { @@ -259,11 +260,11 @@ namespace CP_SDK_BS::Game { } catch (const std::exception& l_Exception) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][LevelSelection.LevelSearchViewController_UpdateBeatmapLevelPackCollectionAsync] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][LevelSelection.LevelSearchViewController_RefreshAsync] Error:"); CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); } - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit LevelSearchViewController_UpdateBeatmapLevelPackCollectionAsync"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit LevelSearchViewController_RefreshAsync"); } } ///< namespace CP_SDK_BS::Game diff --git a/src/CP_SDK_BS/Game/Levels.cpp b/src/CP_SDK_BS/Game/Levels.cpp index f4331ee..4f7882a 100644 --- a/src/CP_SDK_BS/Game/Levels.cpp +++ b/src/CP_SDK_BS/Game/Levels.cpp @@ -8,22 +8,24 @@ #include "assets.hpp" #include -#include -#include +#include +#include +#include #include -#include +#include +#include #include -#include -#include -#include #include +#include +#include #include #include +#include #include #include -#include -#include +#include +#include #include #include #include @@ -32,6 +34,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include using namespace GlobalNamespace; @@ -42,15 +50,16 @@ namespace CP_SDK_BS::Game { _v::MonoPtr Levels::m_DefaultPackCover; - std::vector<_v::Action<>> Levels::m_ReloadSongsCallbacks; - std::mutex Levels::m_ReloadSongsCallbacksMutex; - - _v::MonoPtr Levels::m_AdditionalContentModel; - _v::MonoPtr Levels::m_BeatmapCharacteristicCollectionSO; + _v::MonoPtr Levels::m_BeatmapCharacteristicCollection; _v::MonoPtr Levels::m_BeatmapLevelsModel; _v::MonoPtr Levels::m_GetLevelCancellationTokenSource; _v::MonoPtr Levels::m_GetLevelEntitlementStatusTokenSource; _v::MonoPtr Levels::m_MenuTransitionsHelper; + _v::MonoPtr Levels::m_SimpleLevelStarter; + + bool Levels::m_ReloadSongsInitialized = false; + std::vector<_v::Action<>> Levels::m_ReloadSongsCallbacks; + std::mutex Levels::m_ReloadSongsCallbacksMutex; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -59,7 +68,7 @@ namespace CP_SDK_BS::Game { Sprite* Levels::GetDefaultPackCover() { if (!m_DefaultPackCover) - m_DefaultPackCover = CP_SDK::Unity::SpriteU::CreateFromRaw(IncludedAssets::DefaultPackCover_png.Raw()); + m_DefaultPackCover = CP_SDK::Unity::SpriteU::CreateFromRaw(Assets::DefaultPackCover_png); return m_DefaultPackCover.Ptr(false); } @@ -83,22 +92,28 @@ namespace CP_SDK_BS::Game { CP_SDK::Unity::MTMainThreadInvoker::Enqueue([p_Full]() -> void { - RuntimeSongLoader::API::RefreshSongs(p_Full, [](const auto&) -> void + if (!m_ReloadSongsInitialized) { - CP_SDK::Unity::MTMainThreadInvoker::Enqueue([]() -> void - { - std::vector<_v::Action<>> l_Callbacks; - //lock (m_ReloadSongsCallbacks) + m_ReloadSongsInitialized = true; + + SongCore::API::Loading::GetSongsLoadedEvent().addCallback([](std::span<::SongCore::SongLoader::CustomBeatmapLevel* const> p_Loaded) -> void { + CP_SDK::Unity::MTMainThreadInvoker::Enqueue([]() -> void { - std::lock_guard l_Lock(m_ReloadSongsCallbacksMutex); - l_Callbacks.insert(l_Callbacks.begin(), m_ReloadSongsCallbacks.begin(), m_ReloadSongsCallbacks.end()); - m_ReloadSongsCallbacks.clear(); - } + std::vector<_v::Action<>> l_Callbacks; + //lock (m_ReloadSongsCallbacks) + { + std::lock_guard l_Lock(m_ReloadSongsCallbacksMutex); + l_Callbacks.insert(l_Callbacks.begin(), m_ReloadSongsCallbacks.begin(), m_ReloadSongsCallbacks.end()); + m_ReloadSongsCallbacks.clear(); + } - for (auto& l_Current : l_Callbacks) - l_Current(); + for (auto& l_Current : l_Callbacks) + l_Current(); + }); }); - }); + } + + SongCore::API::Loading::RefreshSongs(p_Full); }); } /// @brief Check for mapping capability @@ -106,26 +121,83 @@ namespace CP_SDK_BS::Game { /// @return True or false bool Levels::HasMappingCapability(std::u16string_view p_Capability) { - if (p_Capability.size() >= 18 && CP_SDK::Utils::U16EqualsToCaseInsensitive(p_Capability.substr(0, 18), u"Mapping Extensions")) - return Modloader::getMods().contains("MappingExtensions"); + auto l_Capabilities = SongCore::API::Capabilities::GetRegisteredCapabilities(); + for (auto& l_Capability : l_Capabilities) + { + if (!CP_SDK::Utils::U16EqualsToCaseInsensitive(p_Capability, CP_SDK::Utils::StrToU16Str(l_Capability))) + continue; - if (CP_SDK::Utils::U16EqualsToCaseInsensitive(p_Capability, u"Chroma Lighting Events")) - return Modloader::getMods().contains("Chroma"); + return true; + } + + return false; + } - if (CP_SDK::Utils::U16EqualsToCaseInsensitive(p_Capability, u"Chroma")) + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Sanitize a level ID for case matching + /// @param p_LevelID Input level ID + /// @return Sanitized level ID + std::u16string Levels::SanitizeLevelID(std::u16string_view p_LevelID) + { + std::u16string l_LevelHash; + if (TryGetHashFromLevelID(p_LevelID, &l_LevelHash)) { - if (!Modloader::getMods().contains("Chroma")) - return false; + /// Level hash is sanitized by TryGetHashFromLevelID + return u"custom_level_" + l_LevelHash; + } - auto l_Env = getenv("DisableChromaReq"); - return l_Env != nullptr && strcmp(l_Env, "0") == 0; + return std::u16string(p_LevelID); + } + /// @brief Try get hash from level ID + /// @param p_LevelID Input level ID + /// @param p_Hash OUT hash + /// @return true or false + bool Levels::TryGetHashFromLevelID(std::u16string_view p_LevelID, std::u16string* p_Hash) + { + if (p_Hash) p_Hash->clear(); + if (!LevelID_IsCustom(p_LevelID)) + return false; + + if (p_Hash) + { + *p_Hash = p_LevelID.substr(13); + + if (p_Hash->length() == 40) // TODO check for only hex + std::transform(p_Hash->begin(), p_Hash->end(), p_Hash->begin(), std::towupper); } - if (CP_SDK::Utils::U16EqualsToCaseInsensitive(p_Capability, u"Noodle Extensions")) - return Modloader::getMods().contains("NoodleExtensions"); + return true; + } + /// @brief Try get level ID from hash + /// @param p_Hash Input hash + /// @param p_LevelID OUT level ID + /// @return true or false + bool Levels::TryGetLevelIDFromHash(std::u16string_view p_Hash, std::u16string* p_LevelID) + { + if (p_LevelID) p_LevelID->clear(); + if (p_Hash.empty() || p_Hash.length() != 40) + return false; - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.HasMappingCapability] NOT YET IMPLEMENTED RETURNING FALSE"); - return false; + if (p_LevelID) + { + *p_LevelID = u"custom_level_" + p_Hash; + std::transform(std::next(p_LevelID->begin(), 13), p_LevelID->end(), std::next(p_LevelID->begin(), 13), std::towupper); + } + + return true; + } + /// @brief Is level ID a custom level ID + /// @param p_LevelID Input level ID + /// @return true or false + bool Levels::LevelID_IsCustom(std::u16string_view p_LevelID) + { + if (p_LevelID.length() < 13) + return false; + + auto l_View = std::u16string_view(p_LevelID.data(), 13); + return _v::U16EqualsToCaseInsensitive(l_View, u"custom_level_"); } //////////////////////////////////////////////////////////////////////////// @@ -139,24 +211,35 @@ namespace CP_SDK_BS::Game { { if (p_BeatmapCharacteristicSO) *p_BeatmapCharacteristicSO = nullptr; - if (!m_BeatmapCharacteristicCollectionSO) + if (p_SerializedName.length() == 0) + return false; + + if (!m_BeatmapCharacteristicCollection) { - auto l_CustomLevelLoader = Resources::FindObjectsOfTypeAll().FirstOrDefault(); - if (l_CustomLevelLoader) - m_BeatmapCharacteristicCollectionSO = l_CustomLevelLoader->beatmapCharacteristicCollection; + auto l_PlayerDataModel = Resources::FindObjectsOfTypeAll()->FirstOrDefault(); + if (l_PlayerDataModel) + m_BeatmapCharacteristicCollection = l_PlayerDataModel->get_playerDataFileModel()->____beatmapCharacteristicCollection; } - if (!m_BeatmapCharacteristicCollectionSO) + if (!m_BeatmapCharacteristicCollection) { CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetBeatmapCharacteristicSOBySerializedName] Invalid BeatmapCharacteristicCollectionSO"); return false; } - auto l_Result = m_BeatmapCharacteristicCollectionSO->GetBeatmapCharacteristicBySerializedName(SanitizeBeatmapCharacteristicSOSerializedName(p_SerializedName)); - if (l_Result && p_BeatmapCharacteristicSO) - *p_BeatmapCharacteristicSO = l_Result; + StringW l_SerializedName = SanitizeBeatmapCharacteristicSOSerializedName(p_SerializedName); + UnityW l_BeatmapCharacteristicSO; + bool l_Result = false; - return l_Result != nullptr; + if (m_BeatmapCharacteristicCollection->____beatmapCharacteristicsBySerializedName->TryGetValue(l_SerializedName, byref(l_BeatmapCharacteristicSO))) + { + l_Result = true; + + if (p_BeatmapCharacteristicSO) + *p_BeatmapCharacteristicSO = l_BeatmapCharacteristicSO.unsafePtr(); + } + + return l_Result; } /// @brief Sanitize BeatmapCharacteristicSO serialized name /// @param p_SerializedName Input serialized name @@ -198,7 +281,7 @@ namespace CP_SDK_BS::Game { auto l_CharacteristicSO = (BeatmapCharacteristicSO*)nullptr; if (TryGetBeatmapCharacteristicSOBySerializedName(p_SerializedName, &l_CharacteristicSO)) - return l_CharacteristicSO->sortingOrder; + return l_CharacteristicSO->____sortingOrder; return 1000; } @@ -206,55 +289,6 @@ namespace CP_SDK_BS::Game { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - /// @brief Is level ID a custom level ID - /// @param p_LevelID Input level ID - /// @return true or false - bool Levels::LevelID_IsCustom(std::u16string_view p_LevelID) - { - if (p_LevelID.length() < 13) - return false; - - auto l_View = std::u16string_view(p_LevelID.data(), 13); - return _v::U16EqualsToCaseInsensitive(l_View, u"custom_level_"); - } - /// @brief Try get hash from level ID - /// @param p_LevelID Input level ID - /// @param p_Hash OUT hash - /// @return true or false - bool Levels::TryGetHashFromLevelID(std::u16string_view p_LevelID, std::u16string* p_Hash) - { - if (p_Hash) p_Hash->clear(); - if (!LevelID_IsCustom(p_LevelID)) - return false; - - if (p_Hash) - { - *p_Hash = p_LevelID.substr(13); - - if (p_Hash->length() == 40/* TODO check for only hex*/) - std::transform(p_Hash->begin(), p_Hash->end(), p_Hash->begin(), std::towupper); - } - - return true; - } - /// @brief Sanitize a level ID for case matching - /// @param p_LevelID Input level ID - /// @return Sanitized level ID - std::u16string Levels::SanitizeLevelID(std::u16string_view p_LevelID) - { - std::u16string l_LevelHash; - if (TryGetHashFromLevelID(p_LevelID, &l_LevelHash)) - { - /// Level hash is sanitized by TryGetHashFromLevelID - return u"custom_level_" + l_LevelHash; - } - - return std::u16string(p_LevelID); - } - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - /// @brief BeatmapDifficulty to BeatmapDifficulty enum name /// @param p_BeatmapDifficulty BeatmapDifficulty /// @return BeatmapDifficulty enum name or "? ExpertPlus ?" @@ -339,101 +373,10 @@ namespace CP_SDK_BS::Game { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - /// @brief For each of PreviewDifficultyBeatmapSets for a PreviewBeatmapLevel - /// @param p_PreviewBeatmapLevel Input preview beatmap level - /// @param p_Functor Functor for each element, return true mean we continue iterating - void Levels::PreviewDifficultyBeatmapSets_ForEach(IPreviewBeatmapLevel* p_PreviewBeatmapLevel, _v::CFuncRef p_Functor) - { - if (!p_PreviewBeatmapLevel) - return; - - auto l_List = p_PreviewBeatmapLevel->get_previewDifficultyBeatmapSets(); - try - { - CP_SDK::ChatPlexSDK::Logger()->Info(u"[CP_SDK_BS.Game][Level.PreviewDifficultyBeatmapSets_ForEach] Trying method 1"); - auto l_Count = l_List->i_IReadOnlyCollection_1_T()->get_Count(); - for (auto l_I = 0; l_I < l_Count; ++l_I) - { - if (!p_Functor(l_List->get_Item(l_I))) - break; - } - } - catch(const std::exception&) - { - CP_SDK::ChatPlexSDK::Logger()->Info(u"[CP_SDK_BS.Game][Level.PreviewDifficultyBeatmapSets_ForEach] Trying method 2"); - try - { - auto l_Enumerator = l_List->i_IReadOnlyCollection_1_T()->i_IEnumerable_1_T()->GetEnumerator()->i_IEnumerator(); - while (l_Enumerator->MoveNext()) - { - if (!p_Functor((PreviewDifficultyBeatmapSet*)l_Enumerator->get_Current())) - break; - } - } - catch(const std::exception&) - { - CP_SDK::ChatPlexSDK::Logger()->Info(u"[CP_SDK_BS.Game][Level.PreviewDifficultyBeatmapSets_ForEach] Resolution failed"); - } - } - } - /// @brief Try get preview difficulty beatmap set by CharacteristicSO - /// @param p_PreviewBeatmapLevel Input preview beatmap level - /// @param p_BeatmapCharacteristicSO Input characteristic SO - /// @param p_PreviewDifficultyBeatmapSet OUT result preview beatmap set - /// @return True or false - bool Levels::TryGetPreviewDifficultyBeatmapSet(IPreviewBeatmapLevel* p_PreviewBeatmapLevel, BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, PreviewDifficultyBeatmapSet** p_PreviewDifficultyBeatmapSet) - { - if (p_PreviewDifficultyBeatmapSet) *p_PreviewDifficultyBeatmapSet = nullptr; - if (!p_PreviewBeatmapLevel || !p_BeatmapCharacteristicSO) - return false; - - auto l_Result = (PreviewDifficultyBeatmapSet*)nullptr; - - PreviewDifficultyBeatmapSets_ForEach(p_PreviewBeatmapLevel, [&](PreviewDifficultyBeatmapSet* l_Current) -> bool - { - if (l_Current->beatmapCharacteristic->serializedName != p_BeatmapCharacteristicSO->serializedName) - return true; ///< Continue - - l_Result = l_Current; - return false; ///< Break - }); - - if (l_Result != nullptr) - { - if (p_PreviewDifficultyBeatmapSet) *p_PreviewDifficultyBeatmapSet = l_Result; - return true; - } - - return false; - } - /// @brief Check if a difficulty is present in a PreviewDifficultyBeatmapSet - /// @param p_PreviewDifficultyBeatmapSet Input PreviewDifficultyBeatmapSet - /// @param p_Difficulty Requested difficulty - /// @return True or false - bool Levels::PreviewDifficultyBeatmapSet_HasDifficulty(PreviewDifficultyBeatmapSet* p_PreviewDifficultyBeatmapSet, BeatmapDifficulty p_Difficulty) - { - if ( p_PreviewDifficultyBeatmapSet == nullptr - || p_PreviewDifficultyBeatmapSet->beatmapDifficulties.Length() == 0) - return false; - - for (const auto& l_Current : p_PreviewDifficultyBeatmapSet->beatmapDifficulties) - { - if (l_Current != p_Difficulty) - continue; - - return true; - } - - return false; - } - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - /// @brief Own a DLC level by level ID /// @param p_LevelID Level ID /// @param p_Callback Callback for success/failure - void Levels::OwnDLCLevelByLevelID(std::u16string_view p_LevelID, _v::Action p_Callback) + void Levels::OwnDLCLevelByLevelID(std::u16string p_LevelID, _v::Action p_Callback) { if (LevelID_IsCustom(p_LevelID)) { @@ -441,10 +384,16 @@ namespace CP_SDK_BS::Game { return; } - if (!m_AdditionalContentModel) - m_AdditionalContentModel = Resources::FindObjectsOfTypeAll().FirstOrDefault(); + if (!m_BeatmapLevelsModel) + { + auto l_MainFlowCoordinator = Resources::FindObjectsOfTypeAll<_u::MainFlowCoordinator*>()->FirstOrDefault([](_u::MainFlowCoordinator* x) -> bool { + return x->____beatmapLevelsModel; + }); + if (l_MainFlowCoordinator) + m_BeatmapLevelsModel = l_MainFlowCoordinator->____beatmapLevelsModel; + } - if (m_AdditionalContentModel) + if (m_BeatmapLevelsModel && m_BeatmapLevelsModel->____entitlements) { if (m_GetLevelEntitlementStatusTokenSource) m_GetLevelEntitlementStatusTokenSource->Cancel(); @@ -453,13 +402,13 @@ namespace CP_SDK_BS::Game { try { - auto l_Task = m_AdditionalContentModel->GetLevelEntitlementStatusAsync(p_LevelID, m_GetLevelEntitlementStatusTokenSource->get_Token()); + auto l_Task = m_BeatmapLevelsModel->____entitlements->GetLevelEntitlementStatusAsync(p_LevelID, m_GetLevelEntitlementStatusTokenSource->get_Token()); l_Task->ConfigureAwait(false); - _v::AwaitTaskAsync( + _v::AwaitTaskAsync( l_Task, - [=](_v::MonoPtrRef> p_Task, bool p_Success) { - p_Callback(p_Success && p_Task->get_Result() == AdditionalContentModel::EntitlementStatus::Owned); + [=](_v::MonoPtrRef> p_Task, bool p_Success) { + p_Callback(p_Success && p_Task->get_Result() == EntitlementStatus::Owned); } ); @@ -476,129 +425,192 @@ namespace CP_SDK_BS::Game { p_Callback(false); } - /// @brief Try to get PreviewBeatmapLevel by level ID - /// @param p_LevelID ID of the level - /// @param p_PreviewBeatmapLevel OUT Found PreviewBeatmapLevel or nullptr + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Try to get BeatmapLevel by level ID + /// @param p_LevelID ID of the level + /// @param p_BeatmapLevel OUT Found BeatmapLevel or nullptr /// @return true or false - bool Levels::TryGetPreviewBeatmapLevelForLevelID(std::u16string_view p_LevelID, IPreviewBeatmapLevel** p_PreviewBeatmapLevel) + bool Levels::TryGetBeatmapLevelForLevelID(std::u16string_view p_LevelID, BeatmapLevel** p_BeatmapLevel) { - if (p_PreviewBeatmapLevel) *p_PreviewBeatmapLevel = nullptr; + if (p_BeatmapLevel) *p_BeatmapLevel = nullptr; auto l_LevelID = SanitizeLevelID(p_LevelID); if (LevelID_IsCustom(p_LevelID)) { - auto l_Custom = RuntimeSongLoader::API::GetLevelById(_v::U16StrToStr(l_LevelID)); - if (l_Custom.has_value()) + auto l_Custom = SongCore::API::Loading::GetLevelByLevelID(_v::U16StrToStr(l_LevelID)); + if (l_Custom) { - if (p_PreviewBeatmapLevel) *p_PreviewBeatmapLevel = l_Custom.value()->i_IPreviewBeatmapLevel(); + if (p_BeatmapLevel) *p_BeatmapLevel = l_Custom; return true; } } if (!m_BeatmapLevelsModel) - m_BeatmapLevelsModel = Resources::FindObjectsOfTypeAll().FirstOrDefault(); + { + auto l_MainFlowCoordinator = Resources::FindObjectsOfTypeAll<_u::MainFlowCoordinator*>()->FirstOrDefault([](_u::MainFlowCoordinator* x) -> bool { + return x->____beatmapLevelsModel; + }); + if (l_MainFlowCoordinator) + m_BeatmapLevelsModel = l_MainFlowCoordinator->____beatmapLevelsModel; + } if (m_BeatmapLevelsModel) { - auto l_Result = m_BeatmapLevelsModel->GetLevelPreviewForLevelId(l_LevelID); + auto l_Result = m_BeatmapLevelsModel->GetBeatmapLevel(l_LevelID); if (l_Result) { - if (p_PreviewBeatmapLevel) *p_PreviewBeatmapLevel = l_Result; + if (p_BeatmapLevel) *p_BeatmapLevel = l_Result; return true; } } else - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetPreviewBeatmapLevelForLevelID] Invalid BeatmapLevelsModel"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetBeatmapLevelForLevelID] Invalid BeatmapLevelsModel"); return false; } - /// @brief Try get custom requirements for a IPreviewBeatmapLevel->BeatmapCharacteristicSO->BeatmapDifficulty - /// @param p_PreviewBeatmapLevel Input preview beatmap level + /// @brief Try to get BeatmapLevel by hash + /// @param p_Hash Hash of the level + /// @param p_BeatmapLevel OUT Found BeatmapLevel or nullptr + /// @return true or false + bool Levels::TryGetBeatmapLevelForHash(std::u16string_view p_Hash, _u::BeatmapLevel** p_BeatmapLevel) + { + std::u16string l_LevelID; + if (!TryGetLevelIDFromHash(p_Hash, &l_LevelID)) + return false; + + return TryGetBeatmapLevelForLevelID(l_LevelID, p_BeatmapLevel); + } + /// @brief For each of BeatmapKey for a BeatmapLevel + /// @param p_BeatmapLevel Input beatmap level + /// @param p_Functor Functor for each element, return true mean we continue iterating + void Levels::BeatmapLevel_ForEachBeatmapKey(BeatmapLevel* p_BeatmapLevel, _v::CFuncRef p_Functor) + { + if (!p_BeatmapLevel) + return; + + try + { + /// Force cache generation + p_BeatmapLevel->GetBeatmapKeys(); + + for (const auto& l_Current : p_BeatmapLevel->____beatmapKeysCache) + { + if (!p_Functor(l_Current)) + break; + } + } + catch(const std::exception&) + { + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Level.BeatmapLevel_ForEachBeatmapKey] Resolution failed"); + } + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Check if a difficulty is present in a BeatmapLevel + /// @param p_BeatmapLevel Input beatmap level + /// @param p_BeatmapCharacteristicSO Desired BeatmapCharacteristicSO + /// @param p_BeatmapDifficulty Desired BeatmapDifficulty + /// @return True or false + bool Levels::BeatmapLevel_HasDifficulty(_u::BeatmapLevel* p_BeatmapLevel, + _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, + _u::BeatmapDifficulty p_BeatmapDifficulty) + { + if (!p_BeatmapLevel || !p_BeatmapCharacteristicSO) + return false; + + if (p_BeatmapLevel->GetDifficultyBeatmapData(p_BeatmapCharacteristicSO, p_BeatmapDifficulty) == nullptr) + return false; + + return true; + } + /// @brief Try get a beatmap key from a BeatmapLevel + /// @param p_BeatmapLevel Input beatmap level + /// @param p_BeatmapCharacteristicSO Desired BeatmapCharacteristicSO + /// @param p_BeatmapDifficulty Desired BeatmapDifficulty + /// @param p_BeatmapKey Out beatmap key + /// @return True or false + bool Levels::BeatmapLevel_TryGetBeatmapKey( _u::BeatmapLevel* p_BeatmapLevel, + _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, + _u::BeatmapDifficulty p_BeatmapDifficulty, + _u::BeatmapKey* p_BeatmapKey) + { + if (!p_BeatmapLevel || !p_BeatmapCharacteristicSO) + return false; + + auto l_Found = false; + BeatmapLevel_ForEachBeatmapKey(p_BeatmapLevel, [&](const BeatmapKey& l_Current) -> bool + { + auto l_BeatmapCharacteristicSO = l_Current.beatmapCharacteristic.unsafePtr(); + if (l_BeatmapCharacteristicSO->____serializedName != p_BeatmapCharacteristicSO->____serializedName) + return true; ///< Continue + + if (l_Current.difficulty != p_BeatmapDifficulty) + return true; ///< Continue + + if (p_BeatmapKey) *p_BeatmapKey = l_Current; + l_Found = true; + + return false; ///< Continue + }); + + return l_Found; + } + /// @brief Try get custom requirements for a BeatmapLevel->BeatmapCharacteristicSO->BeatmapDifficulty + /// @param p_BeatmapLevel Input beatmap level /// @param p_BeatmapCharacteristicSO Desired BeatmapCharacteristicSO /// @param p_BeatmapDifficulty Desired BeatmapDifficulty /// @param p_CustomRequirements OUT custom requirements /// @return true or false - bool Levels::TryGetCustomRequirementsFor(IPreviewBeatmapLevel* p_PreviewBeatmapLevel, - BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, - BeatmapDifficulty p_BeatmapDifficulty, - std::vector* p_CustomRequirements) + bool Levels::TryGetCustomRequirementsFor(_u::BeatmapLevel* p_BeatmapLevel, + _u::BeatmapCharacteristicSO* p_BeatmapCharacteristicSO, + _u::BeatmapDifficulty p_BeatmapDifficulty, + std::vector* p_CustomRequirements) { if (p_CustomRequirements) p_CustomRequirements->clear(); - if (!p_PreviewBeatmapLevel || !p_BeatmapCharacteristicSO) + if (!p_BeatmapLevel || !p_BeatmapCharacteristicSO) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Invalid IPreviewBeatmapLevel or BeatmapCharacteristicSO"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Invalid BeatmapLevel or BeatmapCharacteristicSO"); return false; } - if (!LevelID_IsCustom(p_PreviewBeatmapLevel->get_levelID())) + if (!LevelID_IsCustom(p_BeatmapLevel->___levelID)) return false; - auto l_CustomLevel = (CustomPreviewBeatmapLevel*)nullptr; - if (auto l_Filter = il2cpp_utils::try_cast(p_PreviewBeatmapLevel)) - l_CustomLevel = il2cpp_utils::try_cast(l_Filter.value()->beatmapLevel).value_or(nullptr); - else - l_CustomLevel = il2cpp_utils::try_cast(p_PreviewBeatmapLevel).value_or(nullptr); + auto l_CustomLevel = (SongCore::SongLoader::CustomBeatmapLevel*)nullptr; + if (auto l_Custom = il2cpp_utils::try_cast(p_BeatmapLevel)) + l_CustomLevel = l_Custom.value_or(nullptr); if (!l_CustomLevel) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Failed to convert to custom level for id: " + p_PreviewBeatmapLevel->get_levelID()); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Failed to convert to custom level for id: " + p_BeatmapLevel->___levelID); return false; } - auto l_StandardLevelInfoSaveData = il2cpp_utils::try_cast(l_CustomLevel->get_standardLevelInfoSaveData()).value_or(nullptr); + auto l_StandardLevelInfoSaveData = il2cpp_utils::try_cast(l_CustomLevel->get_standardLevelInfoSaveData()).value_or(nullptr); if (!l_StandardLevelInfoSaveData) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Failed to retrieve custom data level for id: " + p_PreviewBeatmapLevel->get_levelID()); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Failed to retrieve custom data level for id: " + p_BeatmapLevel->___levelID); return false; } - auto& l_Document = l_StandardLevelInfoSaveData->doc; - auto l_DifficultyToFind = BeatmapDifficultyToBeatmapDifficultyEnumName(p_BeatmapDifficulty); - auto l_HasCustomData = false; - CustomJSONData::ValueUTF16 l_CustomData; - - auto l_DifficultyBeatmapSetsIT = l_Document->FindMember(u"_difficultyBeatmapSets"); - if (l_DifficultyBeatmapSetsIT != l_Document->MemberEnd()) + auto l_CharacteristicAndDifficultyWrapper = l_StandardLevelInfoSaveData->TryGetCharacteristicAndDifficulty(p_BeatmapCharacteristicSO->____serializedName, p_BeatmapDifficulty); + if (!l_CharacteristicAndDifficultyWrapper) { - auto l_SetArray = l_DifficultyBeatmapSetsIT->value.GetArray(); - for (auto& l_BeatmapCharacteristicIt : l_SetArray) - { - if (p_BeatmapCharacteristicSO->serializedName == l_BeatmapCharacteristicIt.FindMember(u"_beatmapCharacteristicName")->value.GetString()) - { - auto l_DifficultyBeatmaps = l_BeatmapCharacteristicIt.FindMember(u"_difficultyBeatmaps")->value.GetArray(); - for (auto& l_DifficultyBeatmapIt : l_DifficultyBeatmaps) - { - if (l_DifficultyToFind != l_DifficultyBeatmapIt.FindMember(u"_difficulty")->value.GetString()) - continue; - - if (!l_DifficultyBeatmapIt.HasMember(u"_customData") || !l_DifficultyBeatmapIt[u"_customData"].IsObject()) - return false; - - l_HasCustomData = true; - l_CustomData.CopyFrom(l_DifficultyBeatmapIt[u"_customData"], l_Document->GetAllocator()); - break; - } - } - - if (l_HasCustomData) - break; - } - } - - if (!l_HasCustomData || !l_CustomData.HasMember(u"_requirements") || !l_CustomData[u"_requirements"].IsArray()) - { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] no custom data"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryGetCustomRequirementsFor] Failed to retrieve custom data level for id: " + p_BeatmapLevel->___levelID); return false; } - if (!p_CustomRequirements) - return true; + auto l_CharacteristicAndDifficulty = l_CharacteristicAndDifficultyWrapper.value().get(); - auto l_Requirements = l_CustomData[u"_requirements"].GetArray(); - p_CustomRequirements->reserve(l_Requirements.Size()); - for (auto& l_Requirement : l_Requirements) + p_CustomRequirements->reserve(l_CharacteristicAndDifficulty.requirements.size()); + for (auto& l_Requirement : l_CharacteristicAndDifficulty.requirements) { - auto l_CustomRequirement = l_Requirement.GetString(); + auto l_CustomRequirement = CP_SDK::Utils::StrToU16Str(l_Requirement); auto l_It = std::find(p_CustomRequirements->begin(), p_CustomRequirements->end(), l_CustomRequirement); if (l_It == p_CustomRequirements->end()) @@ -609,182 +621,154 @@ namespace CP_SDK_BS::Game { return true; } - /// @brief Load a BeatmapLevel by level ID - /// @param p_LevelID ID of the level - /// @param p_LoadCallback Load callback - void Levels::LoadBeatmapLevelByLevelID( std::u16string_view p_LevelID, - _v::Action<_v::MonoPtr> p_LoadCallback) + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Try to load BeatmapLevel cover image async + /// @param p_BeatmapLevel Input BeatmapLevel + /// @param p_Callback Callback + void Levels::TryLoadBeatmapLevelCoverAsync(_u::BeatmapLevel* p_BeatmapLevel, _v::Action p_Callback) { - /// Custom levels - if (LevelID_IsCustom(p_LevelID)) + if (!p_BeatmapLevel || !p_BeatmapLevel->___previewMediaData) { - auto l_Level = RuntimeSongLoader::API::GetLevelById(_v::U16StrToStr(SanitizeLevelID(p_LevelID))); - if (!l_Level) - { - CP_SDK::Unity::MTMainThreadInvoker::Enqueue([=]() { p_LoadCallback(nullptr); }); - return; - } + CP_SDK::Unity::MTMainThreadInvoker::Enqueue([=]() { p_Callback(false, Levels::GetDefaultPackCover()); }); + return; + } - auto l_LevelType = l_Level.value()->GetType(); - if (csTypeOf(CustomPreviewBeatmapLevel*)->IsAssignableFrom(l_LevelType)) - { - GetBeatmapLevelFromLevelID(l_Level.value()->levelID, [=](_v::MonoPtr p_Result) { - if (p_Result) - p_LoadCallback(p_Result); + _v::MonoPtr l_PreviewBeatmapLevel(p_BeatmapLevel); + auto l_Task = p_BeatmapLevel->___previewMediaData->GetCoverSpriteAsync(CancellationToken::get_None()); + + _v::AwaitTaskAsync>( + l_Task, + [=](_v::MonoPtrRef>> p_Task, bool p_Success) { + try + { + if (p_Success && p_Task->get_Result()) + p_Callback(true, p_Task->get_Result().unsafePtr()); else - p_LoadCallback(nullptr); - }); + p_Callback(false, Levels::GetDefaultPackCover()); + } + catch (const std::exception& l_Exception) + { + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryLoadBeatmapLevelCoverAsync] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); + + p_Callback(false, Levels::GetDefaultPackCover()); + } } + ); + } + + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Load a BeatmapLevelData by level ID + /// @param p_LevelID ID of the level + /// @param p_LoadCallback Load callback + void Levels::LoadBeatmapLevelDataByLevelID( std::u16string p_LevelID, + _v::Action<_v::MonoPtr<_u::BeatmapLevel, true>, _v::MonoPtr<_u::IBeatmapLevelData, true>> p_LoadCallback) + { + auto l_LevelID = SanitizeLevelID(p_LevelID); + BeatmapLevel* l_BeatmapLevelUnsafe = nullptr; + if (!TryGetBeatmapLevelForLevelID(l_LevelID, &l_BeatmapLevelUnsafe)) + { + p_LoadCallback(nullptr, nullptr); + return; } - /// Base levels - else + + _v::MonoPtr l_BeatmapLevel = l_BeatmapLevelUnsafe; + if (!LevelID_IsCustom(p_LevelID)) { OwnDLCLevelByLevelID(p_LevelID, [=](bool p_OwnDLCLevelByLevelIDResult) { if (!p_OwnDLCLevelByLevelIDResult) { - p_LoadCallback(nullptr); + p_LoadCallback(nullptr, nullptr); return; } - GetBeatmapLevelFromLevelID(p_LevelID, [=](_v::MonoPtr p_Result) { + LoadIBeatmapLevelDataAsync(p_LevelID, [=](_v::MonoPtr p_Result) { if (p_Result) - p_LoadCallback(p_Result); + p_LoadCallback(l_BeatmapLevel.Ptr(false), p_Result); else - p_LoadCallback(nullptr); + p_LoadCallback(nullptr, nullptr); }); }); } - } - /// @brief Try to load PreviewBeatmapLevel cover image async - /// @param p_PreviewBeatmapLevel Input PreviewBeatmapLevel - /// @param p_Callback Callback - void Levels::TryLoadPreviewBeatmapLevelCoverAsync(IPreviewBeatmapLevel* p_PreviewBeatmapLevel, _v::Action p_Callback) - { - if (!p_PreviewBeatmapLevel) - { - CP_SDK::Unity::MTMainThreadInvoker::Enqueue([=]() { p_Callback(false, Levels::GetDefaultPackCover()); }); - return; - } - - auto l_CustomPreviewBeatmapLevel = il2cpp_utils::try_cast(p_PreviewBeatmapLevel).value_or(nullptr); - if (l_CustomPreviewBeatmapLevel) - { - if (!l_CustomPreviewBeatmapLevel->coverImage) - { - auto l_CoverImageFilename = l_CustomPreviewBeatmapLevel->standardLevelInfoSaveData->coverImageFilename; - if (!System::String::IsNullOrEmpty(l_CoverImageFilename)) - { - _v::MonoPtr l_CustomPreviewBeatmapLevelSafe(l_CustomPreviewBeatmapLevel); - auto l_Path = StringW(System::IO::Path::Combine(l_CustomPreviewBeatmapLevel->customLevelPath, l_CoverImageFilename)).operator std::__ndk1::u16string(); - - CP_SDK::Unity::MTThreadInvoker::EnqueueOnThread([=]() - { - try - { - auto l_Bytes = System::IO::File::ReadAllBytes(l_Path); - CP_SDK::Unity::SpriteU::CreateFromRawThreaded(l_Bytes.operator Array *(), [=](Sprite* p_Sprite) - { - if (l_CustomPreviewBeatmapLevelSafe) l_CustomPreviewBeatmapLevelSafe.Ptr(false)->coverImage = p_Sprite ? p_Sprite : Levels::GetDefaultPackCover(); - p_Callback(p_Sprite, p_Sprite ? p_Sprite : Levels::GetDefaultPackCover()); - }); - } - catch (const std::exception&) - { - if (l_CustomPreviewBeatmapLevelSafe) l_CustomPreviewBeatmapLevelSafe.Ptr(false)->coverImage = Levels::GetDefaultPackCover(); - CP_SDK::Unity::MTMainThreadInvoker::Enqueue([=]() { p_Callback(false, Levels::GetDefaultPackCover()); }); - } - }); - } - else - { - l_CustomPreviewBeatmapLevel->coverImage = Levels::GetDefaultPackCover(); - CP_SDK::Unity::MTMainThreadInvoker::Enqueue([=]() { p_Callback(false, Levels::GetDefaultPackCover()); }); - } - } - else - { - _v::MonoPtr l_Cover = l_CustomPreviewBeatmapLevel->coverImage; - CP_SDK::Unity::MTMainThreadInvoker::Enqueue([=]() { p_Callback(l_Cover, l_Cover ? l_Cover.Ptr(false) : Levels::GetDefaultPackCover()); }); - } - } else { - _v::MonoPtr l_PreviewBeatmapLevel(p_PreviewBeatmapLevel); - auto l_Task = p_PreviewBeatmapLevel->GetCoverImageAsync(CancellationToken::get_None()); - - _v::AwaitTaskAsync( - l_Task, - [=](_v::MonoPtrRef> p_Task, bool p_Success) { - try - { - if (p_Success && p_Task->get_Result()) - p_Callback(true, p_Task->get_Result()); - else - p_Callback(false, Levels::GetDefaultPackCover()); - } - catch (const std::exception& l_Exception) - { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][Levels.TryLoadPreviewBeatmapLevelCoverAsync] Error:"); - CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); - } - } - ); + LoadIBeatmapLevelDataAsync(p_LevelID, [=](_v::MonoPtr p_Result) { + if (p_Result) + p_LoadCallback(l_BeatmapLevel.Ptr(false), p_Result); + else + p_LoadCallback(nullptr, nullptr); + }); } } /// @brief Start a BeatmapLevel /// @param p_Level Loaded level /// @param p_Characteristic Beatmap game mode /// @param p_Difficulty Beatmap difficulty + /// @param p_BeatmapLevelData Beatmap level data /// @param p_OverrideEnvironmentSettings Environment settings /// @param p_ColorScheme Color scheme /// @param p_GameplayModifiers Modifiers /// @param p_PlayerSettings Player settings /// @param p_SongFinishedCallback Callback when the song is finished /// @param p_MenuButtonText Menu button text - void Levels::StartBeatmapLevel( IBeatmapLevel* p_Level, - BeatmapCharacteristicSO* p_Characteristic, - BeatmapDifficulty p_Difficulty, - OverrideEnvironmentSettings* p_OverrideEnvironmentSettings, - ColorScheme* p_ColorScheme, - GameplayModifiers* p_GameplayModifiers, - PlayerSpecificSettings* p_PlayerSettings, - _v::Action p_SongFinishedCallback, - std::u16string_view p_MenuButtonText) + void Levels::StartBeatmapLevel( _u::BeatmapLevel* p_Level, + _u::BeatmapCharacteristicSO* p_Characteristic, + _u::BeatmapDifficulty p_Difficulty, + _u::IBeatmapLevelData* p_BeatmapLevelData, + _u::OverrideEnvironmentSettings* p_OverrideEnvironmentSettings, + _u::ColorScheme* p_ColorScheme, + _u::GameplayModifiers* p_GameplayModifiers, + _u::PlayerSpecificSettings* p_PlayerSettings, + _v::Action<_u::StandardLevelScenesTransitionSetupDataSO*, _u::LevelCompletionResults*> p_SongFinishedCallback, + std::u16string_view p_MenuButtonText) { - if (p_Level == nullptr || p_Level->get_beatmapLevelData() == nullptr) + if (p_Level == nullptr) return; if (!m_MenuTransitionsHelper) - m_MenuTransitionsHelper = Resources::FindObjectsOfTypeAll().FirstOrDefault(); + m_MenuTransitionsHelper = Resources::FindObjectsOfTypeAll()->FirstOrDefault(); + + if (!m_SimpleLevelStarter) + m_SimpleLevelStarter = Resources::FindObjectsOfTypeAll()->FirstOrDefault(); - if (m_MenuTransitionsHelper) + if (m_MenuTransitionsHelper && m_SimpleLevelStarter) { try { Scoring::BeatLeader_ManualWarmUpSubmission(); - using t_Delegate = System::Action_2*; + using t_Delegate = System::Action_2, LevelCompletionResults*>*; - auto l_DifficultyBeatmap = BeatmapLevelDataExtensions::GetDifficultyBeatmap(p_Level->get_beatmapLevelData(), p_Characteristic, p_Difficulty); - auto l_Delegate = custom_types::MakeDelegate(std::function([=](StandardLevelScenesTransitionSetupDataSO* __a, LevelCompletionResults* __b) { - p_SongFinishedCallback(__a, __b, l_DifficultyBeatmap); + auto l_BeatmapKey = BeatmapKey(p_Characteristic, p_Difficulty, p_Level->___levelID); + auto l_Delegate = custom_types::MakeDelegate(std::function([=](UnityW __a, LevelCompletionResults* __b) { + p_SongFinishedCallback(__a, __b); })); m_MenuTransitionsHelper->StartStandardLevel( - "Solo", - l_DifficultyBeatmap, - reinterpret_cast(p_Level), - p_OverrideEnvironmentSettings, - p_ColorScheme, - p_GameplayModifiers ? p_GameplayModifiers : GameplayModifiers::New_ctor(), - p_PlayerSettings ? p_PlayerSettings : PlayerSpecificSettings::New_ctor(), - nullptr, - p_MenuButtonText, - false, - false, - nullptr, - l_Delegate, - nullptr + /* string gameMode: */ "Solo", + /* in BeatmapKey beatmapKey: */ byref(l_BeatmapKey), + /* BeatmapLevel beatmapLevel: */ p_Level, + /* IBeatmapLevelData beatmapLevelData: */ p_BeatmapLevelData, + /* OverrideEnvironmentSettings overrideEnvironmentSettings: */ p_OverrideEnvironmentSettings, + /* ColorScheme overrideColorScheme: */ p_ColorScheme, + /* ColorScheme beatmapOverrideColorScheme: */ nullptr, + /* GameplayModifiers gameplayModifiers: */ p_GameplayModifiers ? p_GameplayModifiers : GameplayModifiers::New_ctor(), + /* PlayerSpecificSettings playerSpecificSettings: */ p_PlayerSettings ? p_PlayerSettings : PlayerSpecificSettings::New_ctor(), + /* PracticeSettings practiceSettings: */ nullptr, + /* EnvironmentsListModel environmentsListModel: */ m_SimpleLevelStarter->____environmentsListModel, + /* string backButtonText: */ p_MenuButtonText, + /* bool useTestNoteCutSoundEffects: */ false, + /* bool startPaused: */ false, + /* Action beforeSceneSwitchCallback: */ nullptr, + /* Action afterSceneSwitchCallback: */ nullptr, + /* Action levelFinishedCallback: */ l_Delegate, + /* Action levelRestartedCallback: */ nullptr, + /* RecordingToolManager.SetupData? recordingToolData: */ System::Nullable_1<__RecordingToolManager__SetupData>() ); } catch (const std::exception& l_Exception) @@ -800,14 +784,20 @@ namespace CP_SDK_BS::Game { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - /// @brief Get a BeatmapLevel from a level ID + /// @brief Load IBeatmapLevelData from a level ID /// @param p_LevelID Level ID /// @param p_Callback Callback for success/failure - void Levels::GetBeatmapLevelFromLevelID(std::u16string_view p_LevelID, - _v::Action<_v::MonoPtr> p_Callback) + void Levels::LoadIBeatmapLevelDataAsync(std::u16string p_LevelID, + _v::Action<_v::MonoPtr<_u::IBeatmapLevelData, true>> p_Callback) { if (!m_BeatmapLevelsModel) - m_BeatmapLevelsModel = Resources::FindObjectsOfTypeAll().FirstOrDefault(); + { + auto l_MainFlowCoordinator = Resources::FindObjectsOfTypeAll<_u::MainFlowCoordinator*>()->FirstOrDefault([](_u::MainFlowCoordinator* x) -> bool { + return x->____beatmapLevelsModel; + }); + if (l_MainFlowCoordinator) + m_BeatmapLevelsModel = l_MainFlowCoordinator->____beatmapLevelsModel; + } if (m_BeatmapLevelsModel) { @@ -818,15 +808,15 @@ namespace CP_SDK_BS::Game { try { - auto l_Task = m_BeatmapLevelsModel->GetBeatmapLevelAsync(p_LevelID, m_GetLevelCancellationTokenSource->get_Token()); + auto l_Task = m_BeatmapLevelsModel->LoadBeatmapLevelDataAsync(p_LevelID, m_GetLevelCancellationTokenSource->get_Token()); - _v::AwaitTaskAsync( + _v::AwaitTaskAsync( l_Task, - [=](_v::MonoPtrRef> p_Task, bool p_Success) { + [=](_v::MonoPtrRef> p_Task, bool p_Success) { try { if (p_Success && !p_Task->get_Result().isError) - p_Callback(p_Task->get_Result().beatmapLevel); + p_Callback(p_Task->get_Result().beatmapLevelData); else p_Callback(nullptr); } @@ -881,34 +871,34 @@ namespace CP_SDK_BS::Game { if (p_HaveAnyScore) *p_HaveAnyScore = false; if (p_HaveAllScores) *p_HaveAllScores = true; - auto l_LevelID = SanitizeLevelID(p_LevelID); - auto l_PreviewBeatmapLevel = (IPreviewBeatmapLevel*)nullptr; - if (!TryGetPreviewBeatmapLevelForLevelID(l_LevelID, &l_PreviewBeatmapLevel)) + auto l_LevelID = SanitizeLevelID(p_LevelID); + auto l_BeatmapLevel = (BeatmapLevel*)nullptr; + if (!TryGetBeatmapLevelForLevelID(l_LevelID, &l_BeatmapLevel)) { if (p_HaveAllScores) *p_HaveAllScores = false; return l_Results; } - auto l_PlayerDataModel = Resources::FindObjectsOfTypeAll().FirstOrDefault(); - PreviewDifficultyBeatmapSets_ForEach(l_PreviewBeatmapLevel, [&](PreviewDifficultyBeatmapSet* l_Current) -> bool + auto l_PlayerDataModel = Resources::FindObjectsOfTypeAll()->FirstOrDefault(); + auto l_PlayerData = l_PlayerDataModel ? l_PlayerDataModel->____playerData : nullptr; + auto l_LevelStatsData = l_PlayerData ? l_PlayerData->get_levelsStatsData() : nullptr; + + BeatmapLevel_ForEachBeatmapKey(l_BeatmapLevel, [&](const BeatmapKey& l_Current) -> bool { - if (!l_Results.contains(l_Current->beatmapCharacteristic)) - l_Results[l_Current->beatmapCharacteristic] = t_CharacteristicScores(); + auto l_BeatmapCharacteristicSO = const_cast(l_Current.beatmapCharacteristic.unsafePtr()); + if (!l_Results.contains(l_BeatmapCharacteristicSO)) + l_Results[l_BeatmapCharacteristicSO] = t_CharacteristicScores(); - for (auto l_Difficulty : l_Current->beatmapDifficulties) + PlayerLevelStatsData* l_PlayerLevelStatsData = nullptr; + if (l_LevelStatsData->TryGetValue(l_Current, byref(l_PlayerLevelStatsData)) && l_PlayerLevelStatsData && l_PlayerLevelStatsData->____playCount) { - auto l_ScoreSO = l_PlayerDataModel->playerData->GetPlayerLevelStatsData(l_LevelID, l_Difficulty, l_Current->beatmapCharacteristic); - - if (l_ScoreSO->validScore) - { - if (p_HaveAnyScore) *p_HaveAnyScore = true; - l_Results[l_Current->beatmapCharacteristic].push_back(std::make_tuple(l_Difficulty, l_ScoreSO->highScore)); - } - else - { - if (p_HaveAllScores) *p_HaveAllScores = false; - l_Results[l_Current->beatmapCharacteristic].push_back(std::make_tuple(l_Difficulty, -1)); - } + if (p_HaveAnyScore) *p_HaveAnyScore = true; + l_Results[l_BeatmapCharacteristicSO].push_back(std::make_tuple(l_Current.difficulty, l_PlayerLevelStatsData->____highScore)); + } + else + { + if (p_HaveAllScores) *p_HaveAllScores = false; + l_Results[l_BeatmapCharacteristicSO].push_back(std::make_tuple(l_Current.difficulty, -1)); } return true; ///< Continue diff --git a/src/CP_SDK_BS/Game/Logic.cpp b/src/CP_SDK_BS/Game/Logic.cpp index d79bd20..2766e40 100644 --- a/src/CP_SDK_BS/Game/Logic.cpp +++ b/src/CP_SDK_BS/Game/Logic.cpp @@ -72,7 +72,7 @@ namespace CP_SDK_BS::Game { if (ActiveScene() != ESceneType::Menu) OnMenuSceneActive(); - auto l_GameScenesManager = _u::Resources::FindObjectsOfTypeAll<_u::GameScenesManager*>().FirstOrDefault(); + auto l_GameScenesManager = _u::Resources::FindObjectsOfTypeAll<_u::GameScenesManager*>()->FirstOrDefault(); if (l_GameScenesManager != nullptr) { if (p_Current.get_name() == "EmptyTransition" && !m_LastMainSceneWasNotMenu) @@ -113,6 +113,12 @@ namespace CP_SDK_BS::Game { m_ActiveScene = ESceneType::Menu; m_LevelData = nullptr; + if (!m_WasChatPlexUnityInitialized) + { + CP_SDK::ChatPlexSDK::OnUnityReady(); + m_WasChatPlexUnityInitialized = true; + } + CP_SDK::ChatPlexSDK::Fire_OnGenericMenuScene(); OnSceneChange.Invoke(m_ActiveScene); @@ -143,7 +149,7 @@ namespace CP_SDK_BS::Game { m_WasChatPlexUnityInitialized = true; } - auto l_GameScenesManager = _u::Resources::FindObjectsOfTypeAll<_u::GameScenesManager*>().FirstOrDefault(); + auto l_GameScenesManager = _u::Resources::FindObjectsOfTypeAll<_u::GameScenesManager*>()->FirstOrDefault(); if (l_GameScenesManager != nullptr) l_GameScenesManager->remove_transitionDidFinishEvent(m_Delegate1); @@ -212,8 +218,8 @@ namespace CP_SDK_BS::Game { { m_LevelData->IsReplay = m_WasInReplay; - if (m_LevelData->Data && m_LevelData->Data->transformedBeatmapData) - m_LevelData->MaxMultipliedScore = _u::ScoreModel::ComputeMaxMultipliedScoreForBeatmap(m_LevelData->Data->transformedBeatmapData); + if (m_LevelData->Data && m_LevelData->Data->get_transformedBeatmapData()) + m_LevelData->MaxMultipliedScore = _u::ScoreModel::ComputeMaxMultipliedScoreForBeatmap(m_LevelData->Data->get_transformedBeatmapData()); m_LevelCompletionData = nullptr; @@ -244,8 +250,8 @@ namespace CP_SDK_BS::Game { m_LevelCompletionData = nullptr; m_LevelData = p_LevelData; - if (m_LevelData != nullptr && m_LevelData->Data && m_LevelData->Data->transformedBeatmapData) - m_LevelData->MaxMultipliedScore = _u::ScoreModel::ComputeMaxMultipliedScoreForBeatmap(m_LevelData->Data->transformedBeatmapData); + if (m_LevelData != nullptr && m_LevelData->Data && m_LevelData->Data->get_transformedBeatmapData()) + m_LevelData->MaxMultipliedScore = _u::ScoreModel::ComputeMaxMultipliedScoreForBeatmap(m_LevelData->Data->get_transformedBeatmapData()); } /// @brief On level ended /// @param p_LevelCompletionData Level completion data @@ -258,8 +264,8 @@ namespace CP_SDK_BS::Game { m_LevelCompletionData = p_LevelCompletionData; m_LevelCompletionData->IsReplay = m_WasInReplay; - if (m_LevelCompletionData != nullptr && m_LevelCompletionData->Data && m_LevelCompletionData->Data->transformedBeatmapData) - m_LevelCompletionData->MaxMultipliedScore = _u::ScoreModel::ComputeMaxMultipliedScoreForBeatmap(m_LevelCompletionData->Data->transformedBeatmapData); + if (m_LevelCompletionData != nullptr && m_LevelCompletionData->Data && m_LevelCompletionData->Data->get_transformedBeatmapData()) + m_LevelCompletionData->MaxMultipliedScore = _u::ScoreModel::ComputeMaxMultipliedScoreForBeatmap(m_LevelCompletionData->Data->get_transformedBeatmapData()); } } ///< namespace CP_SDK_BS::Game diff --git a/src/CP_SDK_BS/Game/Patches/PMissionLevelScenesTransitionSetupDataSO.cpp b/src/CP_SDK_BS/Game/Patches/PMissionLevelScenesTransitionSetupDataSO.cpp index 779b2ad..489c05b 100644 --- a/src/CP_SDK_BS/Game/Patches/PMissionLevelScenesTransitionSetupDataSO.cpp +++ b/src/CP_SDK_BS/Game/Patches/PMissionLevelScenesTransitionSetupDataSO.cpp @@ -1,9 +1,9 @@ - #include "CP_SDK_BS/Game/Patches/PMissionLevelScenesTransitionSetupDataSO.hpp" #include "CP_SDK_BS/Game/Logic.hpp" #include "CP_SDK_BS/Game/Scoring.hpp" #include "CP_SDK/Utils/Il2cpp.hpp" +#include #include #include @@ -27,32 +27,41 @@ namespace CP_SDK_BS::Game::Patches { //////////////////////////////////////////////////////////////////////////// CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( - MissionLevelScenesTransitionSetupDataSO_Init, &MissionLevelScenesTransitionSetupDataSO::Init, - void, MissionLevelScenesTransitionSetupDataSO* __Instance, - - StringW __a, IDifficultyBeatmap* __b, IPreviewBeatmapLevel* __c, ArrayW __d, - ColorScheme* __e, GameplayModifiers* __f, PlayerSpecificSettings* __g, StringW __h) + MenuTransitionsHelper_StartMissionLevel, &MenuTransitionsHelper::StartMissionLevel, + void, MenuTransitionsHelper* __Instance, + + StringW __a, + ByRef __b, + BeatmapLevel* __c, + ColorScheme* __d, + GameplayModifiers* __e, + ::ArrayW*> __f, + PlayerSpecificSettings* __g, + EnvironmentsListModel* __h, + System::Action* __i, + System::Action_2, MissionCompletionResults*>* __j, + System::Action_2, MissionCompletionResults*>* __k) { - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter MissionLevelScenesTransitionSetupDataSO_Init"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter MenuTransitionsHelper_StartMissionLevel"); Scoring::__SetScoreSaberIsInReplay(false); - MissionLevelScenesTransitionSetupDataSO_Init(__Instance, __a, __b, __c, __d, __e, __f, __g, __h); + MenuTransitionsHelper_StartMissionLevel(__Instance, __a, __b, __c, __d, __e, __f, __g, __h, __i, __j, __k); try { s_PMissionLevelScenesTransitionSetupDataSO_LevelData = LevelData::Make(); auto& l_LevelData = s_PMissionLevelScenesTransitionSetupDataSO_LevelData; l_LevelData->Type = LevelType::Solo; - l_LevelData->Data = __Instance->gameplayCoreSceneSetupData; + l_LevelData->Data = __Instance->____missionLevelScenesTransitionSetupData->get_gameplayCoreSceneSetupData(); Logic::FireLevelStarted(l_LevelData); } catch(const std::exception& l_Exception) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][MissionLevelScenesTransitionSetupDataSO_Init] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][MenuTransitionsHelper_StartMissionLevel] Error:"); CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); } - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit MissionLevelScenesTransitionSetupDataSO_Init"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit MenuTransitionsHelper_StartMissionLevel"); } CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( MissionLevelScenesTransitionSetupDataSO_Finish, &MissionLevelScenesTransitionSetupDataSO::Finish, @@ -72,7 +81,7 @@ namespace CP_SDK_BS::Game::Patches { auto l_LevelCompletionData = LevelCompletionData::Make(); l_LevelCompletionData->Type = LevelType::Solo; l_LevelCompletionData->Data = l_LevelData->Data; - l_LevelCompletionData->Results = __a->levelCompletionResults; + l_LevelCompletionData->Results = __a->___levelCompletionResults; Scoring::__SetScoreSaberIsInReplay(false); @@ -89,4 +98,4 @@ namespace CP_SDK_BS::Game::Patches { //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit MissionLevelScenesTransitionSetupDataSO_Finish"); } -} ///< namespace CP_SDK_BS::Game::Patches +} ///< namespace CP_SDK_BS::Game::Patches \ No newline at end of file diff --git a/src/CP_SDK_BS/Game/Patches/PMultiplayerLevelScenesTransitionSetupDataSO.cpp b/src/CP_SDK_BS/Game/Patches/PMultiplayerLevelScenesTransitionSetupDataSO.cpp index b730403..2e25d75 100644 --- a/src/CP_SDK_BS/Game/Patches/PMultiplayerLevelScenesTransitionSetupDataSO.cpp +++ b/src/CP_SDK_BS/Game/Patches/PMultiplayerLevelScenesTransitionSetupDataSO.cpp @@ -1,4 +1,3 @@ - #include "CP_SDK_BS/Game/Patches/PMultiplayerLevelScenesTransitionSetupDataSO.hpp" #include "CP_SDK_BS/Game/Logic.hpp" #include "CP_SDK_BS/Game/Scoring.hpp" @@ -29,33 +28,29 @@ namespace CP_SDK_BS::Game::Patches { //////////////////////////////////////////////////////////////////////////// CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( - MultiplayerLevelScenesTransitionSetupDataSO_Init, &MultiplayerLevelScenesTransitionSetupDataSO::Init, - void, MultiplayerLevelScenesTransitionSetupDataSO* __Instance, - - StringW __a, IPreviewBeatmapLevel* __b, BeatmapDifficulty __c, BeatmapCharacteristicSO* __d, - IDifficultyBeatmap* __e, ColorScheme* __f, GameplayModifiers* __g, PlayerSpecificSettings* __h, - PracticeSettings* __i, bool __j) + MultiplayerLevelScenesTransitionSetupDataSO_InitAndSetupScenes, &MultiplayerLevelScenesTransitionSetupDataSO::InitAndSetupScenes, + void, MultiplayerLevelScenesTransitionSetupDataSO* __Instance) { - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter MultiplayerLevelScenesTransitionSetupDataSO_Init"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter MultiplayerLevelScenesTransitionSetupDataSO_InitAndSetupScenes"); Scoring::__SetScoreSaberIsInReplay(false); - MultiplayerLevelScenesTransitionSetupDataSO_Init(__Instance, __a, __b, __c, __d, __e, __f, __g, __h, __i, __j); + MultiplayerLevelScenesTransitionSetupDataSO_InitAndSetupScenes(__Instance); try { s_PMultiplayerLevelScenesTransitionSetupDataSO_LevelData = LevelData::Make(); auto& l_LevelData = s_PMultiplayerLevelScenesTransitionSetupDataSO_LevelData; l_LevelData->Type = LevelType::Multiplayer; - l_LevelData->Data = __Instance->gameplayCoreSceneSetupData; + l_LevelData->Data = __Instance->get_gameplayCoreSceneSetupData(); Logic::FireLevelStarted(l_LevelData); } catch (const std::exception& l_Exception) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][MultiplayerLevelScenesTransitionSetupDataSO_Init] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][MultiplayerLevelScenesTransitionSetupDataSO_InitAndSetupScenes] Error:"); CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); } - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit MultiplayerLevelScenesTransitionSetupDataSO_Init"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit MultiplayerLevelScenesTransitionSetupDataSO_InitAndSetupScenes"); } CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( MultiplayerLevelScenesTransitionSetupDataSO_Finish, &MultiplayerLevelScenesTransitionSetupDataSO::Finish, @@ -80,8 +75,8 @@ namespace CP_SDK_BS::Game::Patches { { auto l_LocalResultData = __a->get_localPlayerResultData(); - if (l_LocalResultData->multiplayerLevelCompletionResults) - l_LevelCompletionData->Results = l_LocalResultData->multiplayerLevelCompletionResults->levelCompletionResults; + if (l_LocalResultData->___multiplayerLevelCompletionResults) + l_LevelCompletionData->Results = l_LocalResultData->___multiplayerLevelCompletionResults->____levelCompletionResults; } Scoring::__SetScoreSaberIsInReplay(false); @@ -99,4 +94,4 @@ namespace CP_SDK_BS::Game::Patches { //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit MultiplayerLevelScenesTransitionSetupDataSO_Finish"); } -} ///< namespace CP_SDK_BS::Game::Patches +} ///< namespace CP_SDK_BS::Game::Patches \ No newline at end of file diff --git a/src/CP_SDK_BS/Game/Patches/PStandardLevelScenesTransitionSetupDataSO.cpp b/src/CP_SDK_BS/Game/Patches/PStandardLevelScenesTransitionSetupDataSO.cpp index ef7a5d5..57f7f97 100644 --- a/src/CP_SDK_BS/Game/Patches/PStandardLevelScenesTransitionSetupDataSO.cpp +++ b/src/CP_SDK_BS/Game/Patches/PStandardLevelScenesTransitionSetupDataSO.cpp @@ -1,4 +1,3 @@ - #include "CP_SDK_BS/Game/Patches/PStandardLevelScenesTransitionSetupDataSO.hpp" #include "CP_SDK_BS/Game/Logic.hpp" #include "CP_SDK_BS/Game/Scoring.hpp" @@ -27,33 +26,31 @@ namespace CP_SDK_BS::Game::Patches { //////////////////////////////////////////////////////////////////////////// CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( - StandardLevelScenesTransitionSetupDataSO_Init, &StandardLevelScenesTransitionSetupDataSO::Init, + StandardLevelScenesTransitionSetupDataSO_InitAndSetupScenes, &StandardLevelScenesTransitionSetupDataSO::InitAndSetupScenes, void, StandardLevelScenesTransitionSetupDataSO* __Instance, - StringW __a, IDifficultyBeatmap* __b, IPreviewBeatmapLevel* __c, OverrideEnvironmentSettings* __d, - ColorScheme* __e, GameplayModifiers* __f, PlayerSpecificSettings* __g, PracticeSettings* __h, - StringW __i, bool __j, bool __k, BeatmapDataCache* __l) + PlayerSpecificSettings* __a, StringW __b, bool __c) { - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter StandardLevelScenesTransitionSetupDataSO_Init"); - Scoring::__SetScoreSaberIsInReplay(__a == u"Replay"); - StandardLevelScenesTransitionSetupDataSO_Init(__Instance, __a, __b, __c, __d, __e, __f, __g, __h, __i, __j, __k, __l); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Enter StandardLevelScenesTransitionSetupDataSO_InitAndSetupScenes"); + Scoring::__SetScoreSaberIsInReplay(__Instance->get_gameMode() == u"Replay"); + StandardLevelScenesTransitionSetupDataSO_InitAndSetupScenes(__Instance, __a, __b, __c); try { s_PStandardLevelScenesTransitionSetupDataSO_LevelData = LevelData::Make(); auto& l_LevelData = s_PStandardLevelScenesTransitionSetupDataSO_LevelData; l_LevelData->Type = LevelType::Solo; - l_LevelData->Data = __Instance->gameplayCoreSceneSetupData; + l_LevelData->Data = __Instance->get_gameplayCoreSceneSetupData(); Logic::FireLevelStarted(l_LevelData); } catch (const std::exception& l_Exception) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][StandardLevelScenesTransitionSetupDataSO_Init] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game.Patches][StandardLevelScenesTransitionSetupDataSO_InitAndSetupScenes] Error:"); CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); } - //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit StandardLevelScenesTransitionSetupDataSO_Init"); + //CP_SDK::ChatPlexSDK::Logger()->Error(u"Exit StandardLevelScenesTransitionSetupDataSO_InitAndSetupScenes"); } CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( StandardLevelScenesTransitionSetupDataSO_Finish, &StandardLevelScenesTransitionSetupDataSO::Finish, diff --git a/src/CP_SDK_BS/Game/PlayerAvatarPicture.cpp b/src/CP_SDK_BS/Game/PlayerAvatarPicture.cpp index df91fc2..48fb867 100644 --- a/src/CP_SDK_BS/Game/PlayerAvatarPicture.cpp +++ b/src/CP_SDK_BS/Game/PlayerAvatarPicture.cpp @@ -40,7 +40,7 @@ namespace CP_SDK_BS::Game { try { if ( p_AvatarResult == nullptr || !p_AvatarResult->IsSuccessStatusCode() - || !p_AvatarResult->BodyBytes() || p_AvatarResult->BodyBytes()->Length() == 0) + || !p_AvatarResult->BodyBytes() || p_AvatarResult->BodyBytes()->get_Length() == 0) { p_OnFailCallback(); return; @@ -70,7 +70,7 @@ namespace CP_SDK_BS::Game { try { if ( p_PlayerResult == nullptr || !p_PlayerResult->IsSuccessStatusCode() - || !p_PlayerResult->BodyBytes() || p_PlayerResult->BodyBytes()->Length() == 0) + || !p_PlayerResult->BodyBytes() || p_PlayerResult->BodyBytes()->get_Length() == 0) { p_OnFailCallback(); return; @@ -90,7 +90,7 @@ namespace CP_SDK_BS::Game { try { if ( p_AvatarResult == nullptr || !p_AvatarResult->IsSuccessStatusCode() - || !p_AvatarResult->BodyBytes() || p_AvatarResult->BodyBytes()->Length() == 0) + || !p_AvatarResult->BodyBytes() || p_AvatarResult->BodyBytes()->get_Length() == 0) { p_OnFailCallback(); return; diff --git a/src/CP_SDK_BS/Game/Scoring.cpp b/src/CP_SDK_BS/Game/Scoring.cpp index d481792..00b23e9 100644 --- a/src/CP_SDK_BS/Game/Scoring.cpp +++ b/src/CP_SDK_BS/Game/Scoring.cpp @@ -2,7 +2,7 @@ #include "CP_SDK/ChatPlexSDK.hpp" #include -#include +#include #include namespace CP_SDK_BS::Game { @@ -69,18 +69,19 @@ namespace CP_SDK_BS::Game { /// Doesn't seem to be required on Quest } - //////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// @brief Init scoring utils void Scoring::Init() { + if (m_Init) return; - m_IsScoreSaberPresent = Modloader::getMods().contains("scoresaber"); + m_IsScoreSaberPresent = HasMod("scoresaber"); - m_IsBeatLeaderPresent = Modloader::getMods().contains("BeatLeader"); + m_IsBeatLeaderPresent = HasMod("BeatLeader"); if (m_IsBeatLeaderPresent) m_BeatLeaderIsInReplayFN = CondDeps::FindUnsafe("replay", "IsInReplay"); @@ -97,4 +98,30 @@ namespace CP_SDK_BS::Game { m_IsInScoreSaberReplay = p_Is; } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /// @brief Check for mod precense by ID + /// @param p_ModID ID of the mod + bool Scoring::HasMod(std::string_view p_ModID) + { + auto l_AllMods = modloader::get_all(); + return std::ranges::find_if(l_AllMods, [p_ModID](const modloader::ModResult& p_ModResult) { + if (!std::holds_alternative(p_ModResult)) + return false; + + auto& l_Right = std::get(p_ModResult).info.id; + if (p_ModID.length() != l_Right.length()) + return false; + + for (auto l_I = 0; l_I < p_ModID.length(); ++l_I) + { + if (std::towlower(p_ModID[l_I]) != std::towlower(l_Right[l_I])) + return false; + } + + return true; + }) != l_AllMods.end(); + } + } ///< namespace CP_SDK_BS::Game diff --git a/src/CP_SDK_BS/Game/UserPlatform.cpp b/src/CP_SDK_BS/Game/UserPlatform.cpp index ebe926d..f11bee3 100644 --- a/src/CP_SDK_BS/Game/UserPlatform.cpp +++ b/src/CP_SDK_BS/Game/UserPlatform.cpp @@ -2,6 +2,7 @@ #include "CP_SDK/ChatPlexSDK.hpp" #include +#include #include #include #include @@ -52,17 +53,17 @@ namespace CP_SDK_BS::Game { for (GlobalNamespace::PlatformLeaderboardsModel * l_Current : l_PlatformLeaderboardsModels) { - if (l_Current->platformUserModel == nullptr) + if (l_Current->____platformUserModel == nullptr) continue; - auto l_Task = l_Current->platformUserModel->GetUserInfo(); + auto l_Task = l_Current->____platformUserModel->GetUserInfo(System::Threading::CancellationToken::get_None()); l_Task->Wait(); - auto l_PlayerID = l_Task->get_Result()->platformUserId; + auto l_PlayerID = l_Task->get_Result()->___platformUserId; if (!System::String::IsNullOrEmpty(l_PlayerID)) { m_UserID = l_PlayerID; - m_UserName = l_Task->get_Result()->userName; + m_UserName = l_Task->get_Result()->___userName; return; } } diff --git a/src/CP_SDK_BS/UI/DefaultComponentsOverrides/BS_CFloatingPanel.cpp b/src/CP_SDK_BS/UI/DefaultComponentsOverrides/BS_CFloatingPanel.cpp index 760f086..310b402 100644 --- a/src/CP_SDK_BS/UI/DefaultComponentsOverrides/BS_CFloatingPanel.cpp +++ b/src/CP_SDK_BS/UI/DefaultComponentsOverrides/BS_CFloatingPanel.cpp @@ -71,7 +71,7 @@ namespace CP_SDK_BS::UI::DefaultComponentsOverrides { { /// Refresh VR pointer due to bug auto l_VRPointers = Resources::FindObjectsOfTypeAll(); - auto l_VRPointer = CP_SDK::ChatPlexSDK::ActiveGenericScene() == CP_SDK::EGenericScene::Playing ? l_VRPointers.LastOrDefault() : l_VRPointers.FirstOrDefault(); + auto l_VRPointer = CP_SDK::ChatPlexSDK::ActiveGenericScene() == CP_SDK::EGenericScene::Playing ? l_VRPointers->LastOrDefault() : l_VRPointers->FirstOrDefault(); if (l_VRPointer) { @@ -117,7 +117,7 @@ namespace CP_SDK_BS::UI::DefaultComponentsOverrides { void BS_CFloatingPanel::CreateMover(VRPointer* p_VRPointer) { if (!p_VRPointer) - p_VRPointer = Resources::FindObjectsOfTypeAll().FirstOrDefault(); + p_VRPointer = Resources::FindObjectsOfTypeAll()->FirstOrDefault(); if (p_VRPointer == nullptr) { @@ -131,7 +131,7 @@ namespace CP_SDK_BS::UI::DefaultComponentsOverrides { if (!m_MoverHandle) { m_MoverHandle = GameObject::New_ctor("MoverHandle", ArrayW({ - reinterpret_cast(csTypeOf(Subs::SubFloatingPanelMoverHandle*)) + reinterpret_cast(csTypeOf(Subs::SubFloatingPanelMoverHandle*).convert()) }))->GetComponent(); m_MoverHandle->get_transform()->SetParent(get_transform()); m_MoverHandle->get_transform()->set_localPosition(Vector3::get_zero()); diff --git a/src/CP_SDK_BS/UI/DefaultComponentsOverrides/Subs/SubFloatingPanelMover.cpp b/src/CP_SDK_BS/UI/DefaultComponentsOverrides/Subs/SubFloatingPanelMover.cpp index 2a8e3e8..e300c77 100644 --- a/src/CP_SDK_BS/UI/DefaultComponentsOverrides/Subs/SubFloatingPanelMover.cpp +++ b/src/CP_SDK_BS/UI/DefaultComponentsOverrides/Subs/SubFloatingPanelMover.cpp @@ -2,6 +2,7 @@ #include "CP_SDK_BS/UI/DefaultComponentsOverrides/Subs/SubFloatingPanelMoverHandle.hpp" #include "CP_SDK_BS/UI/DefaultComponentsOverrides/BS_CFloatingPanel.hpp" #include "CP_SDK/UI/UISystem.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include @@ -48,11 +49,7 @@ namespace CP_SDK_BS::UI::DefaultComponentsOverrides::Subs { /// @brief On frame void SubFloatingPanelMover::Update() { -#if BEATSABER_1_29_4_OR_NEWER auto l_VRController = m_VRPointer ? m_VRPointer->get_lastSelectedVrController() : nullptr; -#else - auto l_VRController = m_VRPointer ? m_VRPointer->get_vrController() : nullptr; -#endif auto l_VRControllerTransform = l_VRController != nullptr ? l_VRController->get_transform() : nullptr; auto l_ButtonDown = l_VRController != nullptr ? l_VRController->get_triggerValue() > 0.9f : false; @@ -69,7 +66,7 @@ namespace CP_SDK_BS::UI::DefaultComponentsOverrides::Subs { for (auto l_I = 0; l_I < l_HitCount; ++l_I) { - auto& l_Hit = m_RaycastBuffer->get(l_I); + auto& l_Hit = m_RaycastBuffer->_values[l_I]; auto l_Collider = l_Hit.get_collider(); auto l_TargetTransform = (Transform*)nullptr; @@ -109,13 +106,9 @@ namespace CP_SDK_BS::UI::DefaultComponentsOverrides::Subs { if (!m_GrabbingController) return; -#if BEATSABER_1_29_4_OR_NEWER auto l_Delta = m_GrabbingController->get_thumbstick().y * Time::get_unscaledDeltaTime(); -#else - auto l_Delta = m_GrabbingController->get_verticalAxisValue() * Time::get_unscaledDeltaTime(); -#endif - if (m_GrabPosition.get_magnitude() > MinScrollDistance) m_GrabPosition = m_GrabPosition - (Vector3::get_forward() * l_Delta); - else m_GrabPosition = m_GrabPosition - (Vector3::get_forward() * std::clamp(l_Delta, std::numeric_limits::min(), 0.0f)); + if (m_GrabPosition.get_magnitude() > MinScrollDistance) m_GrabPosition -= Vector3::get_forward() * l_Delta; + else m_GrabPosition -= Vector3::get_forward() * std::clamp(l_Delta, std::numeric_limits::min(), 0.0f); auto l_RTransform = m_FloatingPanel->RTransform(); auto l_ControllerTransform = m_GrabbingController->get_transform(); diff --git a/src/CP_SDK_BS/UI/DefaultFactoriesOverrides/BS_FloatingPanelFactory.cpp b/src/CP_SDK_BS/UI/DefaultFactoriesOverrides/BS_FloatingPanelFactory.cpp index be9a306..a2a7131 100644 --- a/src/CP_SDK_BS/UI/DefaultFactoriesOverrides/BS_FloatingPanelFactory.cpp +++ b/src/CP_SDK_BS/UI/DefaultFactoriesOverrides/BS_FloatingPanelFactory.cpp @@ -12,7 +12,7 @@ namespace CP_SDK_BS::UI::DefaultFactoriesOverrides { /// @param p_Parent Parent transform CP_SDK::UI::Components::CFloatingPanel* BS_FloatingPanelFactory::Create(std::u16string_view p_Name, _u::Transform* p_Parent) { - auto l_GameObject = _u::GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(_u::RectTransform*)) })); + auto l_GameObject = _u::GameObject::New_ctor(p_Name, ArrayW({ reinterpret_cast(csTypeOf(_u::RectTransform*).convert()) })); l_GameObject->get_transform()->SetParent(p_Parent, false); auto l_Element = l_GameObject->AddComponent(); diff --git a/src/CP_SDK_BS/UI/GameFont.cpp b/src/CP_SDK_BS/UI/GameFont.cpp index bc2cc56..95e0b92 100644 --- a/src/CP_SDK_BS/UI/GameFont.cpp +++ b/src/CP_SDK_BS/UI/GameFont.cpp @@ -19,7 +19,7 @@ namespace CP_SDK_BS::UI { if (m_BaseGameFont || CP_SDK::ChatPlexSDK::ActiveGenericScene() != CP_SDK::EGenericScene::Menu) return m_BaseGameFont.Ptr(false); - m_BaseGameFont = Resources::FindObjectsOfTypeAll().FirstOrDefault([](TMP_FontAsset* t) { return t->get_name() == "Teko-Medium SDF"; }); + m_BaseGameFont = Resources::FindObjectsOfTypeAll()->FirstOrDefault([](TMP_FontAsset* t) { return t->get_name() == "Teko-Medium SDF"; }); return m_BaseGameFont.Ptr(false); } /// @brief Get main game font curved material @@ -28,7 +28,7 @@ namespace CP_SDK_BS::UI { if (m_BaseGameFontSharedMaterial || CP_SDK::ChatPlexSDK::ActiveGenericScene() != CP_SDK::EGenericScene::Menu) return m_BaseGameFontSharedMaterial.Ptr(false); - m_BaseGameFontSharedMaterial = Material::Instantiate(Resources::FindObjectsOfTypeAll().Last([](Material* t) { return t->get_name() == "Teko-Medium SDF Curved Softer"; })); + m_BaseGameFontSharedMaterial = Material::Instantiate(Resources::FindObjectsOfTypeAll()->Last([](Material* t) { return t->get_name() == "Teko-Medium SDF Curved Softer"; })); return m_BaseGameFontSharedMaterial.Ptr(false); } diff --git a/src/CP_SDK_BS/UI/HMUIIconSegmentedControl.cpp b/src/CP_SDK_BS/UI/HMUIIconSegmentedControl.cpp index 47062f8..4507dfc 100644 --- a/src/CP_SDK_BS/UI/HMUIIconSegmentedControl.cpp +++ b/src/CP_SDK_BS/UI/HMUIIconSegmentedControl.cpp @@ -1,4 +1,5 @@ #include "CP_SDK_BS/UI/HMUIIconSegmentedControl.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include #include @@ -25,17 +26,17 @@ namespace CP_SDK_BS::UI { { if (!m_Template) { - m_Template = Resources::FindObjectsOfTypeAll().First([](auto x) -> bool { - return x->get_name() == u"BeatmapCharacteristicSegmentedControl" && x->container != nullptr; + m_Template = Resources::FindObjectsOfTypeAll()->First([](auto x) -> bool { + return x->get_name() == u"BeatmapCharacteristicSegmentedControl" && x->____container != nullptr; }); } auto l_Control = GameObject::Instantiate(m_Template.Ptr(), p_Parent, false); l_Control->set_name(u"BSPIconSegmentedControl"); - l_Control->container = m_Template->container; - l_Control->hideCellBackground = p_HideCellBackground; + l_Control->____container = m_Template->____container; + l_Control->____hideCellBackground = p_HideCellBackground; - auto l_RectTransform = reinterpret_cast(l_Control->get_transform()); + auto l_RectTransform = l_Control->get_transform().try_cast().value_or(nullptr); l_RectTransform->set_anchorMin (Vector2::get_one() * 0.5f); l_RectTransform->set_anchorMax (Vector2::get_one() * 0.5f); l_RectTransform->set_anchoredPosition(Vector2::get_zero() ); diff --git a/src/CP_SDK_BS/UI/HMUITextSegmentedControl.cpp b/src/CP_SDK_BS/UI/HMUITextSegmentedControl.cpp index 34c34b6..7305c1b 100644 --- a/src/CP_SDK_BS/UI/HMUITextSegmentedControl.cpp +++ b/src/CP_SDK_BS/UI/HMUITextSegmentedControl.cpp @@ -1,4 +1,5 @@ #include "CP_SDK_BS/UI/HMUITextSegmentedControl.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include #include @@ -27,17 +28,17 @@ namespace CP_SDK_BS::UI { { if (!m_Template) { - m_Template = Resources::FindObjectsOfTypeAll().First([](auto x) -> bool { - return x->get_name() == u"BeatmapDifficultySegmentedControl" && x->container != nullptr; + m_Template = Resources::FindObjectsOfTypeAll()->First([](auto x) -> bool { + return x->get_name() == u"BeatmapDifficultySegmentedControl" && x->____container != nullptr; }); } auto l_Control = GameObject::Instantiate(m_Template.Ptr(), p_Parent, false); l_Control->set_name(u"BSPTextSegmentedControl"); - l_Control->container = m_Template->container; - l_Control->hideCellBackground = p_HideCellBackground; + l_Control->____container = m_Template->____container; + l_Control->____hideCellBackground = p_HideCellBackground; - auto l_RectTransform = reinterpret_cast(l_Control->get_transform()); + auto l_RectTransform = l_Control->get_transform().try_cast().value_or(nullptr); l_RectTransform->set_anchorMin (Vector2::get_one() * 0.5f); l_RectTransform->set_anchorMax (Vector2::get_one() * 0.5f); l_RectTransform->set_anchoredPosition(Vector2::get_zero() ); @@ -58,7 +59,7 @@ namespace CP_SDK_BS::UI { l_List->Add(l_Current); } - l_Control->SetTexts(l_List->AsReadOnly()->i_IReadOnlyList_1_T()); + l_Control->SetTexts(l_List->AsReadOnly()->i___System__Collections__Generic__IReadOnlyList_1_T_()); return l_Control; } diff --git a/src/CP_SDK_BS/UI/HMUIUIUtils.cpp b/src/CP_SDK_BS/UI/HMUIUIUtils.cpp index 48a43a7..73430b8 100644 --- a/src/CP_SDK_BS/UI/HMUIUIUtils.cpp +++ b/src/CP_SDK_BS/UI/HMUIUIUtils.cpp @@ -26,7 +26,7 @@ namespace CP_SDK_BS::UI { if (m_MainFlowCoordinator) return m_MainFlowCoordinator.Ptr(); - m_MainFlowCoordinator = Resources::FindObjectsOfTypeAll().First(); + m_MainFlowCoordinator = Resources::FindObjectsOfTypeAll()->First(); return m_MainFlowCoordinator.Ptr(); } @@ -38,54 +38,79 @@ namespace CP_SDK_BS::UI { /// @param p_Type Flow coordinator type HMUI::FlowCoordinator* HMUIUIUtils::CreateFlowCoordinator(System::Type* p_Type) { - if (!m_MainFlowCoordinator) - m_MainFlowCoordinator = Resources::FindObjectsOfTypeAll().First(); + try + { + if (!m_MainFlowCoordinator) + m_MainFlowCoordinator = Resources::FindObjectsOfTypeAll()->First(); - auto l_InputModule = m_MainFlowCoordinator->baseInputModule; - auto l_Coordinator = reinterpret_cast(GameObject::New_ctor(p_Type->get_Name())->AddComponent(p_Type)); + auto l_InputModule = m_MainFlowCoordinator->____baseInputModule; + auto l_Coordinator = GameObject::New_ctor(p_Type->get_Name())->AddComponent(p_Type).try_cast().value_or(nullptr); - l_Coordinator->baseInputModule = l_InputModule; + l_Coordinator->____baseInputModule = l_InputModule; - return l_Coordinator; + return l_Coordinator; + } + catch(const std::exception& l_Exception) + { + CP_SDK::ChatPlexSDK::Logger()->Error(u"[HMUIUIUtils.CreateFlowCoordinator] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); + + throw l_Exception; + } } /// @brief Create a view controller /// @param p_Type View controller type HMUI::ViewController* HMUIUIUtils::CreateViewController(System::Type* p_Type) { - if (!m_CanvasTemplate) - m_CanvasTemplate = Resources::FindObjectsOfTypeAll().First([](Canvas* x) -> bool { return x->get_name() == u"DropdownTableView"; }); - - if (!m_PhysicsRaycaster) - m_PhysicsRaycaster = Resources::FindObjectsOfTypeAll().First()->GetComponent()->physicsRaycaster; - - auto l_GameObject = GameObject::New_ctor(p_Type->get_Name()); - auto l_Canvas = l_GameObject->AddComponent(); - l_Canvas->set_renderMode (m_CanvasTemplate->get_renderMode()); - l_Canvas->set_scaleFactor (m_CanvasTemplate->get_scaleFactor()); - l_Canvas->set_referencePixelsPerUnit (m_CanvasTemplate->get_referencePixelsPerUnit()); - //l_Canvas->set_overridePixelPerfect (m_CanvasTemplate->get_overridePixelPerfect()); - l_Canvas->set_pixelPerfect (m_CanvasTemplate->get_pixelPerfect()); - //l_Canvas->set_planeDistance (m_CanvasTemplate->get_planeDistance()); - l_Canvas->set_overrideSorting (m_CanvasTemplate->get_overrideSorting()); - l_Canvas->set_sortingOrder (m_CanvasTemplate->get_sortingOrder()); - //l_Canvas->set_targetDisplay (m_CanvasTemplate->get_targetDisplay()); - l_Canvas->set_sortingLayerID (m_CanvasTemplate->get_sortingLayerID()); - l_Canvas->set_additionalShaderChannels (m_CanvasTemplate->get_additionalShaderChannels()); - //l_Canvas->set_sortingLayerName (m_CanvasTemplate->get_sortingLayerName()); - l_Canvas->set_worldCamera (m_CanvasTemplate->get_worldCamera()); - //l_Canvas->set_normalizedSortingGridSize(m_CanvasTemplate->get_normalizedSortingGridSize()); - - l_GameObject->get_gameObject()->AddComponent()->physicsRaycaster = m_PhysicsRaycaster.Ptr(); - l_GameObject->get_gameObject()->AddComponent(); - - auto l_View = reinterpret_cast(l_GameObject->AddComponent(p_Type)); - l_View->get_rectTransform()->set_anchorMin (Vector2(0.0f, 0.0f)); - l_View->get_rectTransform()->set_anchorMax (Vector2(1.0f, 1.0f)); - l_View->get_rectTransform()->set_sizeDelta (Vector2(0.0f, 0.0f)); - l_View->get_rectTransform()->set_anchoredPosition(Vector2(0.0f, 0.0f)); - l_View->get_gameObject()->SetActive(false); - - return l_View; + try + { + if (!m_CanvasTemplate) + { + m_CanvasTemplate = Resources::FindObjectsOfTypeAll()->FirstOrDefault([](Canvas* x) -> bool { + return CP_SDK::Utils::IsUnityPtrValid(x) && x->get_name() == u"DropdownTableView"; + }); + } + + if (!m_PhysicsRaycaster) + m_PhysicsRaycaster = Resources::FindObjectsOfTypeAll()->First()->GetComponent()->____physicsRaycaster; + + auto l_GameObject = GameObject::New_ctor(p_Type->get_Name()); + auto l_Canvas = l_GameObject->AddComponent(); + l_Canvas->set_renderMode (m_CanvasTemplate->get_renderMode()); + l_Canvas->set_scaleFactor (m_CanvasTemplate->get_scaleFactor()); + l_Canvas->set_referencePixelsPerUnit (m_CanvasTemplate->get_referencePixelsPerUnit()); + //l_Canvas->set_overridePixelPerfect (m_CanvasTemplate->get_overridePixelPerfect()); + l_Canvas->set_pixelPerfect (m_CanvasTemplate->get_pixelPerfect()); + //l_Canvas->set_planeDistance (m_CanvasTemplate->get_planeDistance()); + l_Canvas->set_overrideSorting (m_CanvasTemplate->get_overrideSorting()); + l_Canvas->set_sortingOrder (m_CanvasTemplate->get_sortingOrder()); + //l_Canvas->set_targetDisplay (m_CanvasTemplate->get_targetDisplay()); + l_Canvas->set_sortingLayerID (m_CanvasTemplate->get_sortingLayerID()); + l_Canvas->set_additionalShaderChannels (m_CanvasTemplate->get_additionalShaderChannels()); + //l_Canvas->set_sortingLayerName (m_CanvasTemplate->get_sortingLayerName()); + l_Canvas->set_worldCamera (m_CanvasTemplate->get_worldCamera()); + //l_Canvas->set_normalizedSortingGridSize(m_CanvasTemplate->get_normalizedSortingGridSize()); + + l_GameObject->get_gameObject()->AddComponent()->____physicsRaycaster = m_PhysicsRaycaster.Ptr(); + l_GameObject->get_gameObject()->AddComponent(); + + auto l_View = l_GameObject->AddComponent(p_Type).try_cast().value_or(nullptr); + l_View->get_rectTransform()->set_anchorMin (Vector2(0.0f, 0.0f)); + l_View->get_rectTransform()->set_anchorMax (Vector2(1.0f, 1.0f)); + l_View->get_rectTransform()->set_sizeDelta (Vector2(0.0f, 0.0f)); + l_View->get_rectTransform()->set_anchoredPosition(Vector2(0.0f, 0.0f)); + l_View->get_gameObject()->SetActive(false); + + return l_View; + } + catch(const std::exception& l_Exception) + { + CP_SDK::ChatPlexSDK::Logger()->Error(u"[HMUIUIUtils.CreateViewController] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); + + throw l_Exception; + } + } } ///< namespace CP_SDK_BS::UI \ No newline at end of file diff --git a/src/CP_SDK_BS/UI/HMUIViewFlowCoordinator.cpp b/src/CP_SDK_BS/UI/HMUIViewFlowCoordinator.cpp index 8a5c6e2..93b6b95 100644 --- a/src/CP_SDK_BS/UI/HMUIViewFlowCoordinator.cpp +++ b/src/CP_SDK_BS/UI/HMUIViewFlowCoordinator.cpp @@ -6,8 +6,7 @@ #include -#include -#include +#include #include #include #include @@ -93,7 +92,7 @@ namespace CP_SDK_BS::UI { m_BackupFlowCoordinator = nullptr; - auto l_BackupFlowCoordinator = p_IgnoreBackuping ? nullptr : UnityEngine::Resources::FindObjectsOfTypeAll().LastOrDefault([this](auto x) { + auto l_BackupFlowCoordinator = p_IgnoreBackuping ? nullptr : UnityEngine::Resources::FindObjectsOfTypeAll()->LastOrDefault([this](auto x) { return x->get_isActivated() && x != this && IsFlowCoordinatorInHierarchy(x); }); @@ -162,7 +161,7 @@ namespace CP_SDK_BS::UI { void HMUIViewFlowCoordinator::ChangeView(HMUI::ViewController * p_NewView, HMUI::ViewController * p_Left, HMUI::ViewController * p_Right) { auto l_TopViewController = get_topViewController(); - if (IsFlowCoordinatorInHierarchy(this) && l_TopViewController == p_NewView) + if (IsFlowCoordinatorInHierarchy(this) && l_TopViewController.unsafePtr() == p_NewView) return; m_SwitchQueue.push({p_NewView, p_Left, p_Right}); diff --git a/src/CP_SDK_BS/UI/LevelDetail.cpp b/src/CP_SDK_BS/UI/LevelDetail.cpp index 5fff92d..1770aca 100644 --- a/src/CP_SDK_BS/UI/LevelDetail.cpp +++ b/src/CP_SDK_BS/UI/LevelDetail.cpp @@ -4,35 +4,42 @@ #include "CP_SDK_BS/Game/Levels.hpp" #include "CP_SDK/UI/UISystem.hpp" #include "CP_SDK/Unity/SpriteU.hpp" +#include "CP_SDK/Unity/Operators.hpp" #include "assets.hpp" +#include + #include #include #include #include -#include -#include -#include +#include +#include #include +#include #include -#include +#include #include #include -#include -#include #include #include #include #include -#include +#include #include #include #include #include +#include +#include #include #include #include +#include "songcore/shared/SongLoader/CustomBeatmapLevel.hpp" + +#include "CP_SDK_BS/UI/DefaultComponentsOverrides/Subs/SubFloatingPanelMover.hpp" + using namespace GlobalNamespace; using namespace TMPro; using namespace UnityEngine; @@ -51,7 +58,7 @@ namespace CP_SDK_BS::UI { if (m_SongDetailViewTemplate) return; - auto l_Result = Resources::FindObjectsOfTypeAll().FirstOrDefault([](StandardLevelDetailView* x) -> bool { + auto l_Result = Resources::FindObjectsOfTypeAll()->FirstOrDefault([](StandardLevelDetailView* x) -> bool { return x->get_gameObject()->get_name() == u"LevelDetail"; }); @@ -61,8 +68,23 @@ namespace CP_SDK_BS::UI { m_SongDetailViewTemplate = GameObject::Instantiate(l_Result->get_gameObject()); m_SongDetailViewTemplate->set_name(u"CP_SDK_BS_StandardLevelDetailView_Template"); - GameObject::DestroyImmediate(m_SongDetailViewTemplate->GetComponent()); - GameObject::DontDestroyOnLoad(m_SongDetailViewTemplate.Ptr()); + try + { + auto l_Component = m_SongDetailViewTemplate->GetComponent(); + if (l_Component) + { + auto l_Loader = BeatmapLevelLoader::New_ctor(nullptr, MockBeatmapDataAssetFileModel::New_ctor()->i___GlobalNamespace__IBeatmapDataAssetFileModel(), nullptr, BeatmapLevelLoader::InitData::New_ctor(0)); + auto l_Packs = System::Collections::Generic::List_1<::UnityW>::New_ctor(); + l_Component->____beatmapLevelsModel = BeatmapLevelsModel::New_ctor(nullptr, l_Loader->i___GlobalNamespace__IBeatmapLevelLoader(), l_Packs->i___System__Collections__Generic__IEnumerable_1_T_()); + + GameObject::DestroyImmediate(l_Component); + } + } + catch (const std::exception& l_Exception) + { + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.UI][LevelDetail.Init] Error:"); + CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception); + } } //////////////////////////////////////////////////////////////////////////// @@ -107,9 +129,7 @@ namespace CP_SDK_BS::UI { void LevelDetail::Time(double p_Value) { m_Time = p_Value; - m_SongTimeText->set_text( - p_Value >= 0.0 ? System::Single(System::Math::Floor(p_Value / 60)).ToString("N0") + u":" + System::Single(System::Math::Floor(std::fmod(p_Value, 60))).ToString("00") : u"--" - ); + m_SongTimeText->set_text(p_Value >= 0.0 ? fmt::format("{:.0f}:{:02.0f}", std::floor(p_Value / 60), std::floor(std::fmod(p_Value, 60))) : "--"); } float LevelDetail::BPM() { @@ -118,7 +138,7 @@ namespace CP_SDK_BS::UI { void LevelDetail::BPM(float p_Value) { m_BPM = p_Value; - m_SongBPMText->set_text(System::Single(p_Value).ToString("F0")); + m_SongBPMText->set_text(fmt::format("{:.0f}", p_Value)); } float LevelDetail::NPS() { @@ -127,7 +147,7 @@ namespace CP_SDK_BS::UI { void LevelDetail::NPS(float p_Value) { m_NPS = p_Value; - m_SongNPSText->set_text(p_Value >= 0.0f ? System::Single(p_Value).ToString("F2") : u"--"); + m_SongNPSText->set_text(p_Value >= 0.0f ? fmt::format("{:.2f}", p_Value) : "--"); } int LevelDetail::NJS() { @@ -145,7 +165,7 @@ namespace CP_SDK_BS::UI { void LevelDetail::Offset(float p_Value) { m_Offset = p_Value; - m_SongOffsetText->set_text(!std::isnan(p_Value) ? System::Single(p_Value).ToString("F1") : u"--"); + m_SongOffsetText->set_text(!std::isnan(p_Value) ? fmt::format("{:.1f}", p_Value) : "--"); } int LevelDetail::Notes() { @@ -195,7 +215,7 @@ namespace CP_SDK_BS::UI { l_List->Add(p_Value); m_Difficulty = p_Value; - m_SongDiffSegmentedControl->SetTexts(l_List->AsReadOnly()->i_IReadOnlyList_1_T()); + m_SongDiffSegmentedControl->SetTexts(l_List->AsReadOnly()->i___System__Collections__Generic__IReadOnlyList_1_T_()); } //////////////////////////////////////////////////////////////////////////// @@ -237,7 +257,7 @@ namespace CP_SDK_BS::UI { /// Re-bind play button if (l_PlayButton->GetComponent()) { - auto l_ActionButtonsRTransform = reinterpret_cast(l_ActionButtons->get_transform()); + auto l_ActionButtonsRTransform = l_ActionButtons->get_transform().try_cast().value_or(nullptr); l_ActionButtonsRTransform->set_anchoredPosition(Vector2(-0.5f, l_ActionButtonsRTransform->get_anchoredPosition().y)); auto l_ButtonsParent = l_PlayButton->get_transform()->get_parent(); @@ -261,15 +281,15 @@ namespace CP_SDK_BS::UI { } m_CharacteristicSegmentedControllerClone = m_GameObject->get_transform()->Find(u"BeatmapCharacteristic")->Find(u"BeatmapCharacteristicSegmentedControl")->GetComponent(); - m_SongCharacteristicSegmentedControl = HMUIIconSegmentedControl::Create(reinterpret_cast(m_CharacteristicSegmentedControllerClone->get_transform()), true); + m_SongCharacteristicSegmentedControl = HMUIIconSegmentedControl::Create(m_CharacteristicSegmentedControllerClone->get_transform().try_cast().value_or(nullptr), true); m_DifficultiesSegmentedControllerClone = m_GameObject->get_transform()->Find(u"BeatmapDifficulty")->GetComponentInChildren(); - m_SongDiffSegmentedControl = HMUITextSegmentedControl::Create(reinterpret_cast(m_DifficultiesSegmentedControllerClone->get_transform()), true); + m_SongDiffSegmentedControl = HMUITextSegmentedControl::Create(m_DifficultiesSegmentedControllerClone->get_transform().try_cast().value_or(nullptr), true); auto l_LevelBarBig = m_GameObject->get_transform()->Find(u"LevelBarBig"); - m_SongNameText = l_LevelBarBig->GetComponentsInChildren().First([](auto x) { return x->get_gameObject()->get_name() == u"SongNameText"; }); - m_AuthorNameText = l_LevelBarBig->GetComponentsInChildren().First([](auto x) { return x->get_gameObject()->get_name() == u"AuthorNameText"; }); + m_SongNameText = l_LevelBarBig->GetComponentsInChildren()->First([](auto x) { return x->get_gameObject()->get_name() == u"SongNameText"; }); + m_AuthorNameText = l_LevelBarBig->GetComponentsInChildren()->First([](auto x) { return x->get_gameObject()->get_name() == u"AuthorNameText"; }); m_SongCoverImage = l_LevelBarBig->Find(u"SongArtwork")->GetComponent(); m_SongCoverImage->get_rectTransform()->set_anchoredPosition(Vector2( 2.000f, m_SongCoverImage->get_rectTransform()->get_anchoredPosition().y)); @@ -285,37 +305,37 @@ namespace CP_SDK_BS::UI { l_BeatmapParamsPanel->get_gameObject()->AddComponent()->set_childControlHeight(false); l_BeatmapParamsPanel->get_gameObject()->AddComponent(); - m_SongNPSText = l_BeatmapParamsPanel->GetComponentsInChildren().First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"NPS";}); - m_SongNotesText = l_BeatmapParamsPanel->GetComponentsInChildren().First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"NotesCount";}); - m_SongObstaclesText = l_BeatmapParamsPanel->GetComponentsInChildren().First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"ObstaclesCount";}); - m_SongBombsText = l_BeatmapParamsPanel->GetComponentsInChildren().First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"BombsCount";}); + m_SongNPSText = l_BeatmapParamsPanel->GetComponentsInChildren()->First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"NPS";}); + m_SongNotesText = l_BeatmapParamsPanel->GetComponentsInChildren()->First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"NotesCount";}); + m_SongObstaclesText = l_BeatmapParamsPanel->GetComponentsInChildren()->First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"ObstaclesCount";}); + m_SongBombsText = l_BeatmapParamsPanel->GetComponentsInChildren()->First([](auto x) { return x->get_gameObject()->get_transform()->get_parent()->get_name() == u"BombsCount";}); - auto l_SizeDelta = reinterpret_cast(m_SongNPSText->get_transform()->get_parent()->get_transform())->get_sizeDelta(); + auto l_SizeDelta = m_SongNPSText->get_transform()->get_parent()->get_transform().try_cast().value_or(nullptr)->get_sizeDelta(); l_SizeDelta.y *= 2; m_SongNPSText->get_transform()->get_parent()->get_gameObject()->AddComponent()->set_padding(RectOffset::New_ctor(0, 0, 0, 3)); m_SongNPSText->get_transform()->get_parent()->get_gameObject()->AddComponent(); - reinterpret_cast(m_SongNPSText->get_transform()->get_parent()->get_transform())->set_sizeDelta(l_SizeDelta); + m_SongNPSText->get_transform()->get_parent()->get_transform().try_cast().value_or(nullptr)->set_sizeDelta(l_SizeDelta); m_SongNotesText->get_transform()->get_parent()->get_gameObject()->AddComponent()->set_padding(RectOffset::New_ctor(0, 0, 0, 3)); m_SongNotesText->get_transform()->get_parent()->get_gameObject()->AddComponent(); - reinterpret_cast(m_SongNotesText->get_transform()->get_parent()->get_transform())->set_sizeDelta(l_SizeDelta); + m_SongNotesText->get_transform()->get_parent()->get_transform().try_cast().value_or(nullptr)->set_sizeDelta(l_SizeDelta); m_SongObstaclesText->get_transform()->get_parent()->get_gameObject()->AddComponent()->set_padding(RectOffset::New_ctor(0, 0, 0, 3)); m_SongObstaclesText->get_transform()->get_parent()->get_gameObject()->AddComponent(); - reinterpret_cast(m_SongObstaclesText->get_transform()->get_parent()->get_transform())->set_sizeDelta(l_SizeDelta); + m_SongObstaclesText->get_transform()->get_parent()->get_transform()->get_transform()->get_parent()->get_transform().try_cast().value_or(nullptr)->set_sizeDelta(l_SizeDelta); m_SongBombsText->get_transform()->get_parent()->get_gameObject()->AddComponent()->set_padding(RectOffset::New_ctor(0, 0, 0, 3)); m_SongBombsText->get_transform()->get_parent()->get_gameObject()->AddComponent(); - reinterpret_cast(m_SongBombsText->get_transform()->get_parent()->get_transform())->set_sizeDelta(l_SizeDelta); + m_SongBombsText->get_transform()->get_parent()->get_transform().try_cast().value_or(nullptr)->set_sizeDelta(l_SizeDelta); /// Patch - auto l_OffsetSprite = CP_SDK::Unity::SpriteU::CreateFromRaw(IncludedAssets::Offset_png.Raw(), 100.0f, Vector2::get_one() * 16.0f); + auto l_OffsetSprite = CP_SDK::Unity::SpriteU::CreateFromRaw(Assets::Offset_png, 100.0f, Vector2::get_one() * 16.0f); m_SongOffsetText = GameObject::Instantiate(m_SongNPSText->get_transform()->get_parent()->get_gameObject(), m_SongNPSText->get_transform()->get_parent()->get_parent())->GetComponentInChildren(); m_SongOffsetText->get_transform()->get_parent()->SetAsFirstSibling(); m_SongOffsetText->get_transform()->get_parent()->GetComponentInChildren()->set_sprite(l_OffsetSprite); - auto l_NJSSprite = CP_SDK::Unity::SpriteU::CreateFromRaw(IncludedAssets::NJS_png.Raw(), 100.0f, Vector2::get_one() * 16.0f); + auto l_NJSSprite = CP_SDK::Unity::SpriteU::CreateFromRaw(Assets::NJS_png, 100.0f, Vector2::get_one() * 16.0f); m_SongNJSText = GameObject::Instantiate(m_SongNPSText->get_transform()->get_parent()->get_gameObject(), m_SongNPSText->get_transform()->get_parent()->get_parent())->GetComponentInChildren(); m_SongNJSText->get_transform()->get_parent()->SetAsFirstSibling(); m_SongNJSText->get_transform()->get_parent()->GetComponentInChildren()->set_sprite(l_NJSSprite); @@ -324,20 +344,20 @@ namespace CP_SDK_BS::UI { m_SongBPMText = GameObject::Instantiate(m_SongNPSText->get_transform()->get_parent()->get_gameObject(), m_SongNPSText->get_transform()->get_parent()->get_parent())->GetComponentInChildren(); m_SongBPMText->get_transform()->get_parent()->SetAsFirstSibling(); - m_SongBPMText->get_transform()->get_parent()->GetComponentInChildren()->set_sprite(Resources::FindObjectsOfTypeAll().First([](auto x) { return x->get_name() == u"MetronomeIcon"; })); + m_SongBPMText->get_transform()->get_parent()->GetComponentInChildren()->set_sprite(Resources::FindObjectsOfTypeAll()->First([](auto x) { return x->get_name() == u"MetronomeIcon"; })); m_SongTimeText = GameObject::Instantiate(m_SongNPSText->get_transform()->get_parent()->get_gameObject(), m_SongNPSText->get_transform()->get_parent()->get_parent())->GetComponentInChildren(); m_SongTimeText->get_transform()->get_parent()->SetAsFirstSibling(); - m_SongTimeText->get_transform()->get_parent()->GetComponentInChildren()->set_sprite(Resources::FindObjectsOfTypeAll().First([](auto x) { return x->get_name() == u"ClockIcon"; })); + m_SongTimeText->get_transform()->get_parent()->GetComponentInChildren()->set_sprite(Resources::FindObjectsOfTypeAll()->First([](auto x) { return x->get_name() == u"ClockIcon"; })); /// Bind events m_SongCharacteristicSegmentedControl->add_didSelectCellEvent( - custom_types::MakeDelegate<::System::Action_2<::HMUI::SegmentedControl*, int>*>(std::function([this](HMUI::SegmentedControl* __a, int __b) -> void { + custom_types::MakeDelegate<::System::Action_2, int>*>(std::function([this](UnityW<::HMUI::SegmentedControl> __a, int __b) -> void { OnCharacteristicChanged(__a, __b); })) ); m_SongDiffSegmentedControl->add_didSelectCellEvent( - custom_types::MakeDelegate<::System::Action_2<::HMUI::SegmentedControl*, int>*>(std::function([this](HMUI::SegmentedControl* __a, int __b) -> void { + custom_types::MakeDelegate<::System::Action_2, int>*>(std::function([this](UnityW __a, int __b) -> void { OnDifficultyChanged(__a, __b); })) ); @@ -345,11 +365,11 @@ namespace CP_SDK_BS::UI { try { for (auto l_Text : m_GameObject->GetComponentsInChildren(true)) - l_Text->set_fontStyle(l_Text->get_fontStyle() & ~FontStyles::Italic); + l_Text->set_fontStyle(l_Text->get_fontStyle().value__ & ~FontStyles::Italic.value__); for (auto l_Image : m_GameObject->GetComponentsInChildren(true)) { - m_SongCoverImage->skew = 0.0f; + m_SongCoverImage->____skew = 0.0f; m_SongCoverImage->SetAllDirty(); } } @@ -379,81 +399,41 @@ namespace CP_SDK_BS::UI { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - /// @brief Set from SongCore + /// @brief Set from game /// @param p_BeatMap BeatMap /// @param p_Cover Cover texture /// @param p_Characteristic Game mode /// @param p_Difficulty Difficulty - bool LevelDetail::FromSongCore(IBeatmapLevel* p_BeatMap, Sprite* p_Cover, BeatmapCharacteristicSO* p_Characteristic, BeatmapDifficulty p_Difficulty) + bool LevelDetail::FromGame(BeatmapLevel* p_BeatMap, Sprite* p_Cover, BeatmapCharacteristicSO* p_Characteristic, BeatmapDifficulty p_Difficulty) { m_LocalBeatMap = nullptr; m_BeatMap = nullptr; if (p_BeatMap == nullptr) { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.UI][LevelDetail.FromSongCore] Null Beatmap provided!"); + CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.UI][LevelDetail.FromGame] Null Beatmap provided!"); return false; } - auto l_PreviewBeatmapLevel = p_BeatMap->i_IPreviewBeatmapLevel(); - /// Display mode - Characteristic(HMUI::IconSegmentedControl::DataItem::New_ctor(p_Characteristic->icon, Polyglot::Localization::Get(p_Characteristic->descriptionLocalizationKey))); + Characteristic(HMUI::IconSegmentedControl::DataItem::New_ctor(p_Characteristic->____icon, BGLib::Polyglot::Localization::Get(p_Characteristic->____descriptionLocalizationKey))); - auto l_IDifficultyBeatmap = BeatmapLevelDataExtensions::GetDifficultyBeatmap(p_BeatMap->get_beatmapLevelData(), p_Characteristic, p_Difficulty); + auto l_DifficultyBeatmap = p_BeatMap->GetDifficultyBeatmapData(p_Characteristic, p_Difficulty); /// Display difficulty Difficulty(Game::Levels::BeatmapDifficultySerializedNameToDifficultyName(BeatmapDifficultySerializedMethods::SerializedName(p_Difficulty))); - Name (l_PreviewBeatmapLevel->get_songName()); - AuthorNameText(u"Mapped by " + l_PreviewBeatmapLevel->get_levelAuthorName() + u""); + Name (p_BeatMap->___songName); + AuthorNameText(u"Mapped by " + p_BeatMap->___allMappers->FirstOrDefault() + u""); Cover (p_Cover ? p_Cover : Game::Levels::GetDefaultPackCover()); - Time (l_PreviewBeatmapLevel->get_songDuration()); - BPM (l_PreviewBeatmapLevel->get_beatsPerMinute()); - NJS ((int)l_IDifficultyBeatmap->get_noteJumpMovementSpeed()); - Offset (l_IDifficultyBeatmap->get_noteJumpStartBeatOffset()); - - if (csTypeOf(BeatmapLevelSO::DifficultyBeatmap*)->IsAssignableFrom(reinterpret_cast(l_IDifficultyBeatmap)->GetType())) - { - auto l_DifficultyBeatmap = reinterpret_cast(l_IDifficultyBeatmap); - try - { - /* var l_Task = l_DifficultyBeatmap.GetBeatmapDataBasicInfoAsync(); - l_Task.ConfigureAwait(false); - l_Task.Wait(); - var l_Info = l_Task.Result; - l_DifficultyBeatmap.beatmapLevelData. - NPS = ((float)l_Info.cuttableNotesCount / (float)p_BeatMap.beatsPerMinute); - Notes = l_Info.cuttableNotesCount; - Obstacles = l_Info.obstaclesCount; - Bombs = l_Info.bombsCount;*/ - } - catch (const std::exception&) - { - NPS (-1); - Notes (-1); - Obstacles(-1); - Bombs (-1); - } - } - else if (csTypeOf(CustomDifficultyBeatmap*)->IsAssignableFrom(reinterpret_cast(l_IDifficultyBeatmap)->GetType())) - { - auto l_CustomDifficultyBeatmap = reinterpret_cast(l_IDifficultyBeatmap); - try - { - NPS (((float)l_CustomDifficultyBeatmap->beatmapDataBasicInfo->get_cuttableNotesCount() / (float)l_PreviewBeatmapLevel->get_songDuration())); - Notes (l_CustomDifficultyBeatmap->beatmapDataBasicInfo->get_cuttableNotesCount()); - Obstacles(l_CustomDifficultyBeatmap->beatmapDataBasicInfo->get_obstaclesCount()); - Bombs (l_CustomDifficultyBeatmap->beatmapDataBasicInfo->get_bombsCount()); - } - catch (const std::exception&) - { - NPS (-1); - Notes (-1); - Obstacles(-1); - Bombs (-1); - } - } + Time (p_BeatMap->___songDuration); + BPM (p_BeatMap->___beatsPerMinute); + NJS ((int)l_DifficultyBeatmap->___noteJumpMovementSpeed); + Offset (l_DifficultyBeatmap->___noteJumpStartBeatOffset); + NPS (l_DifficultyBeatmap->___notesCount / p_BeatMap->___songDuration); + Notes (l_DifficultyBeatmap->___notesCount); + Obstacles (l_DifficultyBeatmap->___obstaclesCount); + Bombs (l_DifficultyBeatmap->___bombsCount); return true; } @@ -479,12 +459,12 @@ namespace CP_SDK_BS::UI { } /// Display modes - auto l_Characteristics = List::New_ctor(); + auto l_Characteristics = ListW(); for (auto& l_Current : l_Version->GetBeatmapCharacteristicSOSerializedNamesInOrder()) { auto l_BeatmapCharacteristicSO = (BeatmapCharacteristicSO*)nullptr; if (Game::Levels::TryGetBeatmapCharacteristicSOBySerializedName(l_Current, &l_BeatmapCharacteristicSO)) - l_Characteristics->Add(HMUI::IconSegmentedControl::DataItem::New_ctor(l_BeatmapCharacteristicSO->icon, Polyglot::Localization::Get(l_BeatmapCharacteristicSO->descriptionLocalizationKey))); + l_Characteristics->Add(HMUI::IconSegmentedControl::DataItem::New_ctor(l_BeatmapCharacteristicSO->____icon, BGLib::Polyglot::Localization::Get(l_BeatmapCharacteristicSO->____descriptionLocalizationKey))); } if (l_Characteristics->get_Count() == 0) @@ -537,7 +517,7 @@ namespace CP_SDK_BS::UI { if (l_HoverHint == nullptr || !l_HoverHint) { l_HoverHint = m_FavoriteToggle->AddComponent(); - l_HoverHint->hoverHintController = Resources::FindObjectsOfTypeAll().First(); + l_HoverHint->____hoverHintController = Resources::FindObjectsOfTypeAll()->First(); } l_HoverHint->set_text(p_Hint); @@ -620,41 +600,33 @@ namespace CP_SDK_BS::UI { if (m_LocalBeatMap) { std::vector l_Characs; - auto l_PreviewDifficultyBeatMapSets = m_LocalBeatMap->previewDifficultyBeatmapSets; - auto l_PreviewDifficultyBeatMapSetsCount = m_LocalBeatMap->previewDifficultyBeatmapSets->i_IReadOnlyCollection_1_T()->get_Count(); - for (auto l_I = 0; l_I < l_PreviewDifficultyBeatMapSetsCount; ++l_I) + Game::Levels::BeatmapLevel_ForEachBeatmapKey(m_LocalBeatMap.Ptr(), [&](const BeatmapKey& p_Current) -> bool { - auto l_Current = l_PreviewDifficultyBeatMapSets->get_Item(l_I)->beatmapCharacteristic; - auto l_It = std::find(l_Characs.begin(), l_Characs.end(), l_Current); - + auto l_It = std::find(l_Characs.begin(), l_Characs.end(), p_Current.beatmapCharacteristic.unsafePtr()); if (l_It != l_Characs.end()) - continue; + return true; ///< Continue - l_Characs.push_back(l_Current); - } + l_Characs.push_back(const_cast(p_Current.beatmapCharacteristic.unsafePtr())); + return true; ///< Continue + }); if (p_Index > l_Characs.size()) return; SelectedBeatmapCharacteristicSO = l_Characs[p_Index]; - auto l_Difficulties = System::Collections::Generic::List_1::New_ctor(); - auto l_PreviewDifficultyBeatmapSets = m_LocalBeatMap->previewDifficultyBeatmapSets; - auto l_PreviewDifficultyBeatmapSetsCount = m_LocalBeatMap->previewDifficultyBeatmapSets->i_IReadOnlyCollection_1_T()->get_Count(); - - for (auto l_I = 0; l_I < l_PreviewDifficultyBeatmapSetsCount; ++l_I) + auto l_Difficulties = System::Collections::Generic::List_1::New_ctor(); + Game::Levels::BeatmapLevel_ForEachBeatmapKey(m_LocalBeatMap.Ptr(), [&](const BeatmapKey& p_Current) -> bool { - auto l_Current = l_PreviewDifficultyBeatmapSets->get_Item(l_I); - if (l_Current->beatmapCharacteristic != SelectedBeatmapCharacteristicSO.Ptr()) - continue; + auto l_Name = Game::Levels::BeatmapDifficultySerializedNameToDifficultyName(BeatmapDifficultySerializedMethods::SerializedName(p_Current.difficulty)); + if (l_Difficulties->Contains(l_Name)) + return true; ///< Continue - for (auto l_Difficulty : l_Current->beatmapDifficulties) - l_Difficulties->Add(BeatmapDifficultySerializedMethods::SerializedName(l_Difficulty)); - - break; - } + l_Difficulties->Add(l_Name); + return true; ///< Continue + }); - m_SongDiffSegmentedControl->SetTexts(l_Difficulties->AsReadOnly()->i_IReadOnlyList_1_T()); + m_SongDiffSegmentedControl->SetTexts(l_Difficulties->AsReadOnly()->i___System__Collections__Generic__IReadOnlyList_1_T_()); m_SongDiffSegmentedControl->SelectCellWithNumber(l_Difficulties->get_Count() - 1); OnDifficultyChanged(nullptr, l_Difficulties->get_Count() - 1); } @@ -674,7 +646,7 @@ namespace CP_SDK_BS::UI { for (auto& l_Current : l_Version->GetDifficultiesPerBeatmapCharacteristicSOSerializedName(l_Characs[p_Index])) l_Difficulties->Add(Game::Levels::BeatmapDifficultySerializedNameToDifficultyName(l_Current->difficulty)); - m_SongDiffSegmentedControl->SetTexts(l_Difficulties->AsReadOnly()->i_IReadOnlyList_1_T()); + m_SongDiffSegmentedControl->SetTexts(l_Difficulties->AsReadOnly()->i___System__Collections__Generic__IReadOnlyList_1_T_()); m_SongDiffSegmentedControl->SelectCellWithNumber(l_Difficulties->get_Count() - 1); OnDifficultyChanged(nullptr, l_Difficulties->get_Count() - 1); } @@ -686,83 +658,47 @@ namespace CP_SDK_BS::UI { { if (m_LocalBeatMap) { - std::vector l_Characs; - auto l_PreviewDifficultyBeatMapSets = m_LocalBeatMap->previewDifficultyBeatmapSets; - auto l_PreviewDifficultyBeatMapSetsCount = m_LocalBeatMap->previewDifficultyBeatmapSets->i_IReadOnlyCollection_1_T()->get_Count(); - for (auto l_I = 0; l_I < l_PreviewDifficultyBeatMapSetsCount; ++l_I) + std::vector l_Difficulties; + Game::Levels::BeatmapLevel_ForEachBeatmapKey(m_LocalBeatMap.Ptr(), [&](const BeatmapKey& p_Current) -> bool { - auto l_Current = l_PreviewDifficultyBeatMapSets->get_Item(l_I)->beatmapCharacteristic; - auto l_It = std::find(l_Characs.begin(), l_Characs.end(), l_Current); - - if (l_It != l_Characs.end()) - continue; - - l_Characs.push_back(l_Current); - } + if (p_Current.beatmapCharacteristic.unsafePtr() != SelectedBeatmapCharacteristicSO.Ptr(false)) + return true; ///< Continue - if (m_SongCharacteristicSegmentedControl->get_selectedCellNumber() > l_Characs.size()) - return; + auto l_It = std::find_if(l_Difficulties.begin(), l_Difficulties.end(), [&](const BeatmapKey& p_A) -> bool { + return p_A.beatmapCharacteristic.unsafePtr() == p_Current.beatmapCharacteristic.unsafePtr() && p_A.difficulty == p_Current.difficulty && p_A.levelId == p_Current.levelId; + }); + if (l_It != l_Difficulties.end()) + return true; ///< Continue - StandardLevelInfoSaveData::DifficultyBeatmapSet* l_Difficulties = nullptr; - auto l_DifficultyBeatmapSets = m_LocalBeatMap->standardLevelInfoSaveData->difficultyBeatmapSets; - for (auto l_Current : l_DifficultyBeatmapSets) - { - if (!l_Current->beatmapCharacteristicName->Equals(SelectedBeatmapCharacteristicSO->serializedName)) - continue; - - l_Difficulties = l_Current; - break; - } + l_Difficulties.push_back(p_Current); + return true; ///< Continue + }); - if (p_Index < 0 || p_Index >= l_Difficulties->difficultyBeatmaps->Length()) + if (p_Index < 0 || p_Index >= l_Difficulties.size()) { Time (-1.0f); NPS (-1.0f); NJS (-1); - Offset (System::Single::_get_NaN()); + Offset (std::numeric_limits::quiet_NaN()); Notes (-1); Obstacles(-1); Bombs (-1); return; } - auto l_DifficultyBeatMap = l_Difficulties->difficultyBeatmaps->get(p_Index); - auto l_DifficultyPath = m_LocalBeatMap->customLevelPath + "/" + l_DifficultyBeatMap->beatmapFilename; - auto l_Loader = BeatmapDataLoader::New_ctor(); + auto& l_BeatmapKey = l_Difficulties[p_Index]; + auto l_DifficultyBeatmap = m_LocalBeatMap->GetDifficultyBeatmapData(SelectedBeatmapCharacteristicSO.Ptr(), l_BeatmapKey.difficulty); - try - { - auto l_JSON = System::IO::File::ReadAllText(l_DifficultyPath); - - auto l_BeatmapSaveData = BeatmapSaveDataVersion3::BeatmapSaveData::DeserializeFromJSONString(l_JSON); - auto l_Info = BeatmapDataLoader::GetBeatmapDataBasicInfoFromSaveData(l_BeatmapSaveData); - if (l_Info != nullptr) - { - Time (m_LocalBeatMap->songDuration); - NPS (((float)l_Info->cuttableNotesCount / (float)m_LocalBeatMap->songDuration)); - NJS ((int)l_DifficultyBeatMap->noteJumpMovementSpeed); - Offset (l_DifficultyBeatMap->noteJumpStartBeatOffset); - Notes (l_Info->cuttableNotesCount); - Obstacles(l_Info->obstaclesCount); - Bombs (l_Info->bombsCount); - - OnActiveDifficultyChanged(GetIDifficultyBeatMap()); - } - } - catch (const std::exception& p_Exception) - { - CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.UI][LevelDetail.OnDifficultyChanged] Error:"); - CP_SDK::ChatPlexSDK::Logger()->Error(p_Exception); + Time (m_LocalBeatMap->___songDuration); + BPM (m_LocalBeatMap->___beatsPerMinute); + NJS ((int)l_DifficultyBeatmap->___noteJumpMovementSpeed); + Offset (l_DifficultyBeatmap->___noteJumpStartBeatOffset); + NPS (l_DifficultyBeatmap->___notesCount / m_LocalBeatMap->___songDuration); + Notes (l_DifficultyBeatmap->___notesCount); + Obstacles (l_DifficultyBeatmap->___obstaclesCount); + Bombs (l_DifficultyBeatmap->___bombsCount); - Time (-1.0f); - NPS (-1.0f); - NJS (-1); - Offset (System::Single::_get_NaN()); - Notes (-1); - Obstacles(-1); - Bombs (-1); - return; - } + OnActiveDifficultyChanged(l_BeatmapKey); } else if (m_BeatMap) { @@ -778,7 +714,7 @@ namespace CP_SDK_BS::UI { Time (-1.0f); NPS (-1.0f); NJS (-1); - Offset (System::Single::_get_NaN()); + Offset (std::numeric_limits::quiet_NaN()); Notes (-1); Obstacles(-1); Bombs (-1); @@ -797,7 +733,12 @@ namespace CP_SDK_BS::UI { Obstacles(l_SelectedBeatmapCharacteristicDifficulty->obstacles); Bombs (l_SelectedBeatmapCharacteristicDifficulty->bombs); - OnActiveDifficultyChanged(GetIDifficultyBeatMap()); + std::u16string l_LevelID; + if (Game::Levels::TryGetLevelIDFromHash(l_Version->hash, &l_LevelID)) + { + auto l_BeatmapKey = BeatmapKey(SelectedBeatmapCharacteristicSO.Ptr(), SelectedBeatmapDifficulty, l_LevelID); + OnActiveDifficultyChanged(l_BeatmapKey); + } } } /// @brief Secondary button on click @@ -811,35 +752,4 @@ namespace CP_SDK_BS::UI { OnPrimaryButton(); } - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - /// @brief Get IDifficultyBeatmap - IDifficultyBeatmap* LevelDetail::GetIDifficultyBeatMap() - { - return nullptr; - /* - var l_CharacIndex = m_SongCharacteristicSegmentedControl.selectedCellNumber; - if (l_CharacIndex >= m_BeatMap.Metadata.Characteristics.Count) - return null; - - var l_LocalSong = SongCore.Loader.GetLevelByHash(m_BeatMap.Hash); - if (l_LocalSong != null && SongCore.Loader.CustomLevels.ContainsKey(l_LocalSong.customLevelPath)) - { - IBeatmapLevel l_Level = null; - - var task = Task.Run(async () => { await Game.Level.LoadSong(l_LocalSong.levelID, (x) => l_Level = x); }); - task.Wait(); - - return l_Level.beatmapLevelData.GetDifficultyBeatmap(SelectedBeatmapCharacteristicSO, SelecteBeatmapDifficulty); - } - else - { - var l_BSBeatmapLevel = Game.BeatSaver.CreateFakeCustomBeatmapLevelFromBeatMap(m_BeatMap); - var l_BSIDifficultyBeatmapSet = l_BSBeatmapLevel.beatmapLevelData.difficultyBeatmapSets.Where(x => x.beatmapCharacteristic == SelectedBeatmapCharacteristicSO).FirstOrDefault(); - - return l_BSIDifficultyBeatmapSet.difficultyBeatmaps.Where(x => x.difficulty == SelecteBeatmapDifficulty).FirstOrDefault(); - }*/ - } - } ///< namespace CP_SDK_BS::UI \ No newline at end of file diff --git a/src/CP_SDK_BS/UI/Patches/PVRPointer.cpp b/src/CP_SDK_BS/UI/Patches/PVRPointer.cpp index 322c5c2..ef7f790 100644 --- a/src/CP_SDK_BS/UI/Patches/PVRPointer.cpp +++ b/src/CP_SDK_BS/UI/Patches/PVRPointer.cpp @@ -10,15 +10,9 @@ namespace CP_SDK_BS::UI::Patches { //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// -#if BEATSABER_1_29_4_OR_NEWER CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( - VRPointer__OnEnable, &VRPointer::EnabledLastSelectedPointer, - void, VRPointer* __Instance) -#else - CP_SDK_IL2CPP_HOOK_MAKE_AUTO_HOOK_MATCH( - VRPointer__OnEnable, &VRPointer::OnEnable, - void, VRPointer* __Instance) -#endif + VRPointer__OnEnable, &VRPointer::EnabledLastSelectedPointer, + void, VRPointer* __Instance) { VRPointer__OnEnable(__Instance); diff --git a/src/CP_SDK_BS/UI/ViewController.cpp b/src/CP_SDK_BS/UI/ViewController.cpp index cbc4009..c3247c0 100644 --- a/src/CP_SDK_BS/UI/ViewController.cpp +++ b/src/CP_SDK_BS/UI/ViewController.cpp @@ -175,7 +175,7 @@ namespace CP_SDK_BS::UI { _v::IModal* ViewController::CreateModal_Impl(System::Type* p_Type) { auto l_GameObject = GameObject::New_ctor(p_Type->get_Name(), ArrayW({ - reinterpret_cast(csTypeOf(RectTransform*)), + reinterpret_cast(csTypeOf(RectTransform*).convert()), p_Type, _v::UISystem::Override_UnityComponent_Image.ptr() })); @@ -188,7 +188,7 @@ namespace CP_SDK_BS::UI { l_Modal->RTransform()->set_anchoredPosition(Vector2(0.0f, 0.0f)); l_Modal->RTransform()->set_sizeDelta (Vector2(0.0f, 0.0f)); - auto l_Background = reinterpret_cast(l_GameObject->GetComponent(_v::UISystem::Override_UnityComponent_Image.ptr())); + auto l_Background = l_GameObject->GetComponent(_v::UISystem::Override_UnityComponent_Image.ptr()).try_cast().value_or(nullptr); l_Background->set_material (_v::UISystem::Override_GetUIMaterial()); l_Background->set_raycastTarget (true); l_Background->set_pixelsPerUnitMultiplier (1); diff --git a/src/main.cpp b/src/main.cpp index bbcaf5d..77d4ae1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "CP_SDK/ChatPlexSDK.hpp" #include "CP_SDK/ModuleBase.hpp" -#include "CP_SDK/Logging/BMBFLogger.hpp" +#include "CP_SDK/Logging/PaperLogger.hpp" #include "CP_SDK/UI/FlowCoordinators/MainFlowCoordinator.hpp" #include "CP_SDK/UI/ScreenSystem.hpp" #include "CP_SDK/UI/UISystem.hpp" @@ -25,7 +25,7 @@ #include #include -static ModInfo s_ModInfo; +static modloader::ModInfo s_ModInfo{"ChatPlexSDK-BS", VERSION, GIT_COMMIT}; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -49,25 +49,25 @@ void ScreenSystem_OnPresent() if (!CP_SDK::Utils::IsUnityPtrValid(p_HMUIScreen) || !p_HMUIScreen->get_gameObject()->get_activeSelf()) return; - m_HMUIDeactivatedScreens.push_back(p_HMUIScreen->get_gameObject()); + m_HMUIDeactivatedScreens.push_back(p_HMUIScreen->get_gameObject().ptr()); p_HMUIScreen->get_gameObject()->SetActive(false); }; if (!m_HMUIScreenSystem) { m_HMUIDeactivatedScreens.clear(); - m_HMUIScreenSystem = UnityEngine::Resources::FindObjectsOfTypeAll().FirstOrDefault(); + m_HMUIScreenSystem = UnityEngine::Resources::FindObjectsOfTypeAll()->FirstOrDefault(); } if (!m_HMUIScreenSystem) return; m_HMUIDeactivatedScreens.clear(); - DeactivateScreenSafe(m_HMUIScreenSystem->leftScreen); - DeactivateScreenSafe(m_HMUIScreenSystem->mainScreen); - DeactivateScreenSafe(m_HMUIScreenSystem->rightScreen); - DeactivateScreenSafe(m_HMUIScreenSystem->bottomScreen); - DeactivateScreenSafe(m_HMUIScreenSystem->topScreen); + DeactivateScreenSafe(m_HMUIScreenSystem->____leftScreen); + DeactivateScreenSafe(m_HMUIScreenSystem->____mainScreen); + DeactivateScreenSafe(m_HMUIScreenSystem->____rightScreen); + DeactivateScreenSafe(m_HMUIScreenSystem->____bottomScreen); + DeactivateScreenSafe(m_HMUIScreenSystem->____topScreen); CP_SDK::UI::ScreenSystem::Instance()->get_transform()->set_localScale(m_HMUIScreenSystem->get_transform()->get_localScale()); } @@ -88,19 +88,19 @@ void PatchUI() CP_SDK::UI::UISystem::UILayer = UnityEngine::LayerMask::NameToLayer("UI"); - CP_SDK::UI::UISystem::Override_UnityComponent_Image = csTypeOf(HMUI::ImageView*); - CP_SDK::UI::UISystem::Override_UnityComponent_TextMeshProUGUI = csTypeOf(HMUI::CurvedTextMeshPro*); + CP_SDK::UI::UISystem::Override_UnityComponent_Image = reinterpret_cast(csTypeOf(HMUI::ImageView*).convert()); + CP_SDK::UI::UISystem::Override_UnityComponent_TextMeshProUGUI = reinterpret_cast(csTypeOf(HMUI::CurvedTextMeshPro*).convert()); CP_SDK::UI::UISystem::Override_GetUIMaterial = []() { if (m_UINoGlowMaterial || CP_SDK::ChatPlexSDK::ActiveGenericScene() != CP_SDK::EGenericScene::Menu) return m_UINoGlowMaterial.Ptr(); - m_UINoGlowMaterial = UnityEngine::Material::Instantiate(UnityEngine::Resources::FindObjectsOfTypeAll().FirstOrDefault([](auto x) { return x->get_name() == u"UINoGlow"; })); + m_UINoGlowMaterial = UnityEngine::Material::Instantiate(UnityEngine::Resources::FindObjectsOfTypeAll()->FirstOrDefault([](auto x) { return x->get_name() == u"UINoGlow"; })); return m_UINoGlowMaterial.Ptr(); }; CP_SDK::UI::UISystem::Override_OnClick = [](UnityEngine::MonoBehaviour* p_MonoBehavior) { if (!m_BasicUIAudioManager || CP_SDK::ChatPlexSDK::ActiveGenericScene() != CP_SDK::EGenericScene::Menu) - m_BasicUIAudioManager = UnityEngine::Resources::FindObjectsOfTypeAll().FirstOrDefault(); + m_BasicUIAudioManager = UnityEngine::Resources::FindObjectsOfTypeAll()->FirstOrDefault(); if (m_BasicUIAudioManager) m_BasicUIAudioManager->HandleButtonClickEvent(); }; @@ -110,10 +110,10 @@ void PatchUI() return; if (!m_VRGraphicRaycasterCache) - m_VRGraphicRaycasterCache = UnityEngine::Resources::FindObjectsOfTypeAll().FirstOrDefault([](auto y) { return y->physicsRaycaster != nullptr; }); + m_VRGraphicRaycasterCache = UnityEngine::Resources::FindObjectsOfTypeAll()->FirstOrDefault([](auto y) { return y->_physicsRaycaster != nullptr; }); if (m_VRGraphicRaycasterCache) - x->get_gameObject()->AddComponent()->physicsRaycaster = m_VRGraphicRaycasterCache->physicsRaycaster; + x->get_gameObject()->AddComponent()->____physicsRaycaster = m_VRGraphicRaycasterCache->____physicsRaycaster; }; //////////////////////////////////////////////////////////////////////////// @@ -178,14 +178,13 @@ void OnEnable() //////////////////////////////////////////////////////////////////////////// // Called at the early stages of game loading -extern "C" void setup(ModInfo & p_ModInfo) +extern "C" void setup(CModInfo* p_ModInfo) { - p_ModInfo.id = "ChatPlexSDK-BS"; - p_ModInfo.version = VERSION; + p_ModInfo->id = s_ModInfo.id.c_str(); + p_ModInfo->version = s_ModInfo.version.c_str(); + p_ModInfo->version_long = s_ModInfo.versionLong; - s_ModInfo = p_ModInfo; - - auto l_Logger = new CP_SDK::Logging::BMBFLogger(new Logger(p_ModInfo, LoggerOptions(false, true))); + auto l_Logger = new CP_SDK::Logging::PaperLogger(p_ModInfo->id); CP_SDK::ChatPlexSDK::Configure( l_Logger, @@ -196,13 +195,13 @@ extern "C" void setup(ModInfo & p_ModInfo) CP_SDK::ChatPlexSDK::OnAssemblyLoaded(); CP_SDK::Unity::FontManager::Setup([](TMPro::TMP_FontAsset* p_Input) -> TMPro::TMP_FontAsset* { - auto l_MainFont = UnityEngine::Resources::FindObjectsOfTypeAll().FirstOrDefault([](auto x) { return x->get_name() == u"Teko-Medium SDF"; }); + auto l_MainFont = UnityEngine::Resources::FindObjectsOfTypeAll()->FirstOrDefault([](auto x) { return x->get_name() == u"Teko-Medium SDF"; }); if (l_MainFont && p_Input) { - p_Input->material->set_shader(l_MainFont->material->get_shader()); - p_Input->material->SetColor("_FaceColor", p_Input->material->GetColor(u"_FaceColor")); - p_Input->material->EnableKeyword("CURVED"); - p_Input->material->EnableKeyword("UNITY_UI_CLIP_RECT"); + p_Input->___material->set_shader(l_MainFont->___material->get_shader()); + p_Input->___material->SetColor("_FaceColor", p_Input->___material->GetColor(u"_FaceColor")); + p_Input->___material->EnableKeyword("CURVED"); + p_Input->___material->EnableKeyword("UNITY_UI_CLIP_RECT"); } return p_Input; @@ -217,7 +216,7 @@ extern "C" void setup(ModInfo & p_ModInfo) static bool s_IsLoaded = false; // Called later on in the game loading - a good time to install function hooks -extern "C" void load() +extern "C" void late_load() { if (s_IsLoaded) return; diff --git a/start-logging.ps1 b/start-logging.ps1 index bd8a05c..9f8ab3a 100644 --- a/start-logging.ps1 +++ b/start-logging.ps1 @@ -36,7 +36,7 @@ if ($help -eq $true) { $bspid = adb shell pidof com.beatgames.beatsaber $command = "adb logcat " -if ($all -eq $false) { +if ($all -eq $true) { $loops = 0 while ([string]::IsNullOrEmpty($bspid) -and $loops -lt 3) { Start-Sleep -Milliseconds 100 @@ -62,7 +62,7 @@ if ($all -eq $false) { $pattern += "$custom|" } if ($pattern -eq "(") { - $pattern = "(QuestHook|modloader|" + $pattern = "(QuestHook|modloader|scotland2|" } $pattern += "AndroidRuntime|CRASH)" $command += " | Select-String -pattern `"$pattern`""