From 6b8cd760b689673a57202352440a6429c42bfb0f Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 11:25:00 +0200 Subject: [PATCH 01/55] Remove old files --- Android.mk | 71 --------------------------------------------- Android_Template.mk | 71 --------------------------------------------- Application.mk | 6 ---- bmbfmod.json | 25 ---------------- mod.bak.json | 19 ------------ 5 files changed, 192 deletions(-) delete mode 100644 Android.mk delete mode 100644 Android_Template.mk delete mode 100644 Application.mk delete mode 100644 bmbfmod.json delete mode 100644 mod.bak.json diff --git a/Android.mk b/Android.mk deleted file mode 100644 index 2a24bc9..0000000 --- a/Android.mk +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2009 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -LOCAL_PATH := $(call my-dir) -TARGET_ARCH_ABI := $(APP_ABI) - -rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) - -# Build the modloader shared library -include $(CLEAR_VARS) -LOCAL_MODULE := -include $(CLEAR_VARS) -# Creating prebuilt for dependency: beatsaber-hook - version: 1.3.3 -include $(CLEAR_VARS) -LOCAL_MODULE := beatsaber-hook_3_4_4 -LOCAL_EXPORT_C_INCLUDES := extern/beatsaber-hook -LOCAL_SRC_FILES := extern/libbeatsaber-hook_3_4_4.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: codegen - version: 0.14.0 -include $(CLEAR_VARS) -LOCAL_MODULE := codegen -LOCAL_EXPORT_C_INCLUDES := extern/codegen -LOCAL_SRC_FILES := extern/libcodegen.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: custom-types - version: 0.8.2 -include $(CLEAR_VARS) -LOCAL_MODULE := custom-types -LOCAL_EXPORT_C_INCLUDES := extern/custom-types -LOCAL_SRC_FILES := extern/libcustom-types.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: modloader - version: 1.1.0 -include $(CLEAR_VARS) -LOCAL_MODULE := modloader -LOCAL_EXPORT_C_INCLUDES := extern/modloader -LOCAL_SRC_FILES := extern/libmodloader.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: questui - version: 0.6.5 -include $(CLEAR_VARS) -LOCAL_MODULE := questui -LOCAL_EXPORT_C_INCLUDES := extern/questui -LOCAL_SRC_FILES := extern/libquestui.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := QuestSounds -LOCAL_SRC_FILES += $(call rwildcard,src/,*.cpp) -LOCAL_SRC_FILES += $(call rwildcard,extern/beatsaber-hook/src/inline-hook,*.cpp) -LOCAL_SRC_FILES += $(call rwildcard,extern/beatsaber-hook/src/inline-hook,*.c) -LOCAL_SHARED_LIBRARIES += modloader -LOCAL_SHARED_LIBRARIES += beatsaber-hook_3_4_4 -LOCAL_SHARED_LIBRARIES += codegen -LOCAL_SHARED_LIBRARIES += custom-types -LOCAL_SHARED_LIBRARIES += questui -LOCAL_LDLIBS += -llog -LOCAL_CFLAGS += -I'extern/libil2cpp/il2cpp/libil2cpp' -DID='"QuestSounds"' -DVERSION='"$(VERSION)"' -DBS__1_16=1 -I'./shared' -I'./extern' -isystem'extern/codegen/include' -Ofast -LOCAL_CPP_FEATURES += rtti exceptions -LOCAL_CPPFLAGS += -std=c++2a -Ofast -LOCAL_C_INCLUDES += ./include ./src -include $(BUILD_SHARED_LIBRARY) diff --git a/Android_Template.mk b/Android_Template.mk deleted file mode 100644 index 4cf731b..0000000 --- a/Android_Template.mk +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2009 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -LOCAL_PATH := $(call my-dir) -TARGET_ARCH_ABI := $(APP_ABI) - -rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) - -# Build the modloader shared library -include $(CLEAR_VARS) -LOCAL_MODULE := -include $(CLEAR_VARS) -# Creating prebuilt for dependency: beatsaber-hook - version: 1.3.3 -include $(CLEAR_VARS) -LOCAL_MODULE := beatsaber-hook_{BS_Hook} -LOCAL_EXPORT_C_INCLUDES := extern/beatsaber-hook -LOCAL_SRC_FILES := extern/libbeatsaber-hook_{BS_Hook}.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: codegen - version: 0.14.0 -include $(CLEAR_VARS) -LOCAL_MODULE := codegen -LOCAL_EXPORT_C_INCLUDES := extern/codegen -LOCAL_SRC_FILES := extern/libcodegen.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: custom-types - version: 0.8.2 -include $(CLEAR_VARS) -LOCAL_MODULE := custom-types -LOCAL_EXPORT_C_INCLUDES := extern/custom-types -LOCAL_SRC_FILES := extern/libcustom-types.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: modloader - version: 1.1.0 -include $(CLEAR_VARS) -LOCAL_MODULE := modloader -LOCAL_EXPORT_C_INCLUDES := extern/modloader -LOCAL_SRC_FILES := extern/libmodloader.so -include $(PREBUILT_SHARED_LIBRARY) -# Creating prebuilt for dependency: questui - version: 0.6.5 -include $(CLEAR_VARS) -LOCAL_MODULE := questui -LOCAL_EXPORT_C_INCLUDES := extern/questui -LOCAL_SRC_FILES := extern/libquestui.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := QuestSounds -LOCAL_SRC_FILES += $(call rwildcard,src/,*.cpp) -LOCAL_SRC_FILES += $(call rwildcard,extern/beatsaber-hook/src/inline-hook,*.cpp) -LOCAL_SRC_FILES += $(call rwildcard,extern/beatsaber-hook/src/inline-hook,*.c) -LOCAL_SHARED_LIBRARIES += modloader -LOCAL_SHARED_LIBRARIES += beatsaber-hook_{BS_Hook} -LOCAL_SHARED_LIBRARIES += codegen -LOCAL_SHARED_LIBRARIES += custom-types -LOCAL_SHARED_LIBRARIES += questui -LOCAL_LDLIBS += -llog -LOCAL_CFLAGS += -I'extern/libil2cpp/il2cpp/libil2cpp' -DID='"QuestSounds"' -DVERSION='"$(VERSION)"' -DBS__1_16=1 -I'./shared' -I'./extern' -isystem'extern/codegen/include' -Ofast -LOCAL_CPP_FEATURES += rtti exceptions -LOCAL_CPPFLAGS += -std=c++2a -Ofast -LOCAL_C_INCLUDES += ./include ./src -include $(BUILD_SHARED_LIBRARY) diff --git a/Application.mk b/Application.mk deleted file mode 100644 index d7e70ca..0000000 --- a/Application.mk +++ /dev/null @@ -1,6 +0,0 @@ -APP_ABI := arm64-v8a -# 25 -APP_PLATFORM := android-24 -APP_PIE:= true -APP_STL := c++_static -APP_CPPFLAGS := -std=c++2a \ No newline at end of file diff --git a/bmbfmod.json b/bmbfmod.json deleted file mode 100644 index a383a5e..0000000 --- a/bmbfmod.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "id": "QuestSounds", - "name": "QuestSounds", - "author": "Rugtveit, EnderdracheLP", - "description": [ - - "Allows users to change their sfx sounds easily!" - - ], - "category": "Gameplay", - "gameVersion": "1.13.2", - "version": "1.0.0-InDev", - "platform": "Quest", - "components": [ - { - "type": "HookMod", - "installAction": { - "installLibraryFile": "libquestsounds.so" - }, - "uninstallAction": { - "removeLibraryFile": "libquestsounds.so" - } - } - ] -} diff --git a/mod.bak.json b/mod.bak.json deleted file mode 100644 index 33f3524..0000000 --- a/mod.bak.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "_QPVersion": "0.1.1", - "id": "QuestSounds", - "name": "Quest Sounds", - "version": "1.0.4-Dev", - "author": "Rugtveit, EnderdracheLP", - "packageId": "com.beatgames.beatsaber", - "packageVersion": "1.19.0", - "description": "Allows users to change their sfx sounds and in-game music easily!", - "coverImage": "Cover.jpg", - "modFiles": [ - "libQuestSounds.so" - ], - "libraryFiles": [ - "libbeatsaber-hook_3_4_4.so" - ], - "dependencies": [], - "fileCopies": [] -} From 2802bc982ae8aba6a1af702e61a405b054f4a046 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 21:28:13 +0200 Subject: [PATCH 02/55] Update build scripts --- build.ps1 | 27 ++++++++++-------- buildQMOD.ps1 | 76 ++++++++++----------------------------------------- 2 files changed, 30 insertions(+), 73 deletions(-) diff --git a/build.ps1 b/build.ps1 index b6e26d3..776d220 100644 --- a/build.ps1 +++ b/build.ps1 @@ -19,12 +19,12 @@ $NDKPath = Get-Content $PSScriptRoot/ndkpath.txt # elseif ($args[$i] -eq "--release") { $release = $true } # } -$qpm = "./qpm.json" +$qpm = "./qpm.shared.json" $qpmJson = Get-Content $qpm -Raw | ConvertFrom-Json if ($args.Count -eq 0 -or $actions -ne $true) { -$ModID = $qpmJson.info.id -$VERSION = $qpmJson.info.version + $ModID = $qpmJson.config.info.id + $VERSION = $qpmJson.config.info.version if ($release -ne $true) { $VERSION += "-Dev" } elseif ($release -eq $true -and $VERSION.Contains("-Dev")) { @@ -36,19 +36,24 @@ $VERSION = $qpmJson.info.version if ($actions -eq $true) { $ModID = $env:module_id $VERSION = $env:version + if ([string]::IsNullOrEmpty($VERSION)) { + $qpmsharedJson = Get-Content $qpmshared -Raw | ConvertFrom-Json + $VERSION = $qpmsharedJson.config.info.version.replace("-Dev", "") + } } else { - & qpm-rust package edit --version $VERSION + & qpm package edit --version $VERSION } -if ((Test-Path "./extern/includes/beatsaber-hook/src/inline-hook/And64InlineHook.cpp", "./extern/includes/beatsaber-hook/src/inline-hook/inlineHook.c", "./extern/includes/beatsaber-hook/src/inline-hook/relocate.c") -contains $false) { + +if ((Test-Path "./extern/includes/beatsaber-hook/shared/inline-hook/And64InlineHook.cpp", "./extern/includes/beatsaber-hook/shared/inline-hook/inlineHook.c", "./extern/includes/beatsaber-hook/shared/inline-hook/relocate.c") -contains $false) { Write-Host "Critical: Missing inline-hook" - if (!(Test-Path "./extern/includes/beatsaber-hook/src/inline-hook/And64InlineHook.cpp")) { - Write-Host "./extern/includes/beatsaber-hook/src/inline-hook/And64InlineHook.cpp" + if (!(Test-Path "./extern/includes/beatsaber-hook/shared/inline-hook/And64InlineHook.cpp")) { + Write-Host "./extern/includes/beatsaber-hook/shared/inline-hook/And64InlineHook.cpp" } - if (!(Test-Path "./extern/includes/beatsaber-hook/src/inline-hook/inlineHook.c")) { - Write-Host "./extern/includes/beatsaber-hook/src/inline-hook/inlineHook.c" + if (!(Test-Path "./extern/includes/beatsaber-hook/shared/inline-hook/inlineHook.c")) { + Write-Host "./extern/includes/beatsaber-hook/shared/inline-hook/inlineHook.c" } - if (!(Test-Path "./extern/includes/beatsaber-hook/inline-hook/src/relocate.c")) { - Write-Host "./extern/includes/beatsaber-hook/src/inline-hook/relocate.c" + if (!(Test-Path "./extern/includes/beatsaber-hook/inline-hook/shared/relocate.c")) { + Write-Host "./extern/includes/beatsaber-hook/shared/inline-hook/relocate.c" } Write-Host "Task Failed" exit 1; diff --git a/buildQMOD.ps1 b/buildQMOD.ps1 index 4ceeb68..a3ea972 100644 --- a/buildQMOD.ps1 +++ b/buildQMOD.ps1 @@ -40,83 +40,35 @@ if ($qmodName -eq "") } if (($args.Count -eq 0 -or $dev -eq $true) -And $package -eq $false) { -echo "Packaging QMod $qmodName" + echo "Packaging QMod $qmodName" & $PSScriptRoot/build.ps1 -clean:$clean -release:$release if ($LASTEXITCODE -ne 0) { echo "Failed to build, exiting..." exit $LASTEXITCODE } - - qpm-rust qmod build - # Compress-Archive -Path "./libs/arm64-v8a/lib$ModID.so", "./libs/arm64-v8a/libbeatsaber-hook_$BSHook.so", ".\Cover.jpg", ".\mod.json" -DestinationPath "./Temp$ModID.zip" -Update - # Move-Item "./Temp$ModID.zip" "./$ModID.qmod" -Force } -echo "Creating qmod from mod.json" - -$mod = "./mod.json" -$modJson = Get-Content $mod -Raw | ConvertFrom-Json - -$filelist = @($mod) - -$cover = "./" + $modJson.coverImage -if ((-not ($cover -eq "./")) -and (Test-Path $cover)) -{ - $filelist += ,$cover -} else { - echo "No cover Image found" -} +$qpmsharedJson = Get-Content "./qpm.shared.json" -Raw | ConvertFrom-Json -if ($package -eq $true -And $env:version.Contains('-Dev') -Or $release -eq $false) { +if ($package -eq $true) { $qmodName = "$($env:module_id)_$($env:version)" -echo "Actions: Packaging QMod $qmodName" - # Compress-Archive -Path "./libs/arm64-v8a/lib$ModID.so", "./libs/arm64-v8a/libbeatsaber-hook_$BSHook.so", ".\Cover.jpg", ".\mod.json" -DestinationPath "./Temp$ModID.zip" -Update - # Move-Item "./Temp$ModID.zip" "./$ModID.qmod" -Force -} elseif ($package -eq $true) { - $qmodName = "$($env:module_id)" -echo "Actions: Packaging QMod $qmodName" + echo "Actions: Packaging QMod $qmodName" } else { - $qmodName += "_$($modJson.version)" -} - - -foreach ($mod in $modJson.modFiles) -{ - $path = "./build/" + $mod - if (-not (Test-Path $path)) - { - $path = "./extern/libs/" + $mod - } - $filelist += $path + $qmodName += "_$($qpmsharedJson.config.info.version)" } -foreach ($lib in $modJson.libraryFiles) -{ - $path = "./extern/libs/" + $lib - if (-not (Test-Path $path)) - { - $path = "./build/" + $lib - } - $filelist += $path -} - -foreach ($file in $modJson.fileCopies) -{ - $path = "./Examples/" + $file.name - $filelist += $path -} - -$zip = $qmodName + ".zip" $qmod = $qmodName + ".qmod" -if ((-not ($clean.IsPresent)) -and (Test-Path $qmod)) -{ - echo "Making Clean Qmod" - Move-Item $qmod $zip -Force -} +# if ((-not ($clean.IsPresent)) -and (Test-Path $qmod)) +# { +# echo "Making Clean Qmod" +# Move-Item $qmod $zip -Force +# } + +qpm qmod zip -i ./build/ -i ./extern/libs/ $qmod -Compress-Archive -Path $filelist -DestinationPath $zip -Update -Move-Item $zip $qmod -Force +# Compress-Archive -Path $filelist -DestinationPath $zip -Update +# Move-Item $zip $qmod -Force echo "Task Completed" \ No newline at end of file From 1d160bb19e788d62fb2bfcb863bb184cd6a6750f Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 21:28:29 +0200 Subject: [PATCH 03/55] Bump deps --- qpm.json | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/qpm.json b/qpm.json index db810b2..1aca5a5 100644 --- a/qpm.json +++ b/qpm.json @@ -1,45 +1,60 @@ { + "version": "0.1.0", "sharedDir": "shared", "dependenciesDir": "extern", "info": { "name": "QuestSounds", "id": "QuestSounds", - "version": "1.4.1", + "version": "1.5.0-Dev", "url": null, "additionalData": { "overrideSoName": "libQuestSounds.so" } }, + "workspace": { + "scripts": {}, + "qmodIncludeDirs": [], + "qmodIncludeFiles": [], + "qmodOutput": null + }, "dependencies": [ { "id": "beatsaber-hook", - "versionRange": "^3.14.0", + "versionRange": "^5.1.9", + "additionalData": {} + }, + { + "id": "scotland2", + "versionRange": "^0.1.4", "additionalData": { - "extraFiles": [ - "src/inline-hook" - ] + "includeQmod": false, + "private": true } }, { - "id": "questui", - "versionRange": "^0.17.11", + "id": "bs-cordl", + "versionRange": "^3700.0.0", "additionalData": {} }, { - "id": "codegen", - "versionRange": "^0.33.0", + "id": "custom-types", + "versionRange": "^0.17.10", "additionalData": {} }, { - "id": "custom-types", - "versionRange": "^0.15.23", + "id": "bsml", + "versionRange": "^0.4.43", + "additionalData": {} + }, + { + "id": "config-utils", + "versionRange": "^1.4.2", "additionalData": {} }, { - "id": "modloader", - "versionRange": "^1.2.3", + "id": "paper", + "versionRange": "^3.6.4", "additionalData": {} } - ], - "additionalData": {} + ] } \ No newline at end of file From 679cea107e050b3d8bf1fff6d23c3be6f95c81a1 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 21:32:23 +0200 Subject: [PATCH 04/55] Update workflow --- .github/workflows/BuildQSounds.yml | 78 +++++++++------------- .github/workflows/Release.yml | 101 ++++++++--------------------- 2 files changed, 58 insertions(+), 121 deletions(-) diff --git a/.github/workflows/BuildQSounds.yml b/.github/workflows/BuildQSounds.yml index 350860c..8bce333 100644 --- a/.github/workflows/BuildQSounds.yml +++ b/.github/workflows/BuildQSounds.yml @@ -21,48 +21,31 @@ on: env: module_id: QuestSounds - version: 1.4.1-Dev.${{ github.run_number }} - BSVersion: 1.28.0_4124311467 -# ndkname: android-ndk-r24 + #version: 1.4.1-Dev.${{ github.run_number }} jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 name: Checkout with: submodules: true lfs: true - - uses: seanmiddleditch/gha-setup-ninja@v3 - -# - name: Install Powershell -# run: sudo apt-get install -y powershell - -# - name: Cache Android NDK -# id: cache-ndk -# uses: actions/cache@v2 -# env: -# cache-name: cache-ndk -# with: -# path: ndk -# key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.ndkname }} -# restore-keys: | -# ${{ runner.os }}-${{ env.cache-name }}-${{ env.ndkname }} - -# - name: Install Android NDK -# if: steps.cache-ndk.outputs.cache-hit != 'true' -# run: | -# wget -q -O ndk.zip https://dl.google.com/android/repository/${ndkname}-linux-x86_64.zip -# unzip -q ndk.zip -# mv ${ndkname} ndk - -# - name: Create ndkpath.txt -# run: | -# cd ndk -# pwd > ${GITHUB_WORKSPACE}/ndkpath.txt + - name: Get Version + shell: pwsh + run: | + $branchParts = '${{ github.ref_name }}'.Split('/'); $branchMain = $branchParts[0]; if ($branchParts[0] -match "^\d+$") { $branchMain = 'pr'; $branchSub = "$($branchParts[0])." } elseif ($branchParts.Length -eq 2) { $branchSub = "$($branchParts[1].Replace('.', '-'))." }; echo "version=$((Get-Content ./qpm.shared.json -Raw | ConvertFrom-Json).config.info.version.Split('-')[0])-$($branchMain).${{ github.run_number }}+$($branchSub)ra${{ github.run_attempt }}.$($env:GITHUB_SHA.Substring(0, 7))" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + # Not sure this is used in this workflow + - name: Get BSVersion + shell: pwsh + run: | + echo "BSVersion=$((Get-Content ./mod.template.json -Raw | ConvertFrom-Json).packageVersion)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - uses: seanmiddleditch/gha-setup-ninja@v5 - name: Create ndkpath.txt run: | @@ -74,14 +57,14 @@ jobs: with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: cargo-build.yml - name: linux-qpm-rust + name: linux-qpm path: QPM - repo: RedBrumbler/QuestPackageManager-Rust + repo: QuestPackageManager/QPM.CLI - name: QPM Collapse run: | - chmod +x ./QPM/qpm-rust - ./QPM/qpm-rust collapse + chmod +x ./QPM/qpm + ./QPM/qpm collapse - name: QPM Dependencies Cache id: cache-qpm-deps @@ -89,15 +72,16 @@ jobs: env: cache-name: cache-qpm-deps with: - path: /home/runner/.local/share/QPM-Rust/cache - key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('qpm.json', '.github/BuildQSounds.yml') }} + path: /home/runner/.local/share/QPM-RS/cache + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('qpm.shared.json') }} restore-keys: | ${{ runner.os }}-${{ env.cache-name }}- ${{ runner.os }}-${{ env.cache-name }} - - name: QPM Restore + - name: QPM Set Version & Restore run: | - ./QPM/qpm-rust restore + ./QPM/qpm package edit --version ${{ env.version }} + ./QPM/qpm restore - name: Check dependency Folders run: | @@ -107,15 +91,13 @@ jobs: echo "Checking libs" ls -lh ${GITHUB_WORKSPACE}/extern/libs echo "" - echo "Checking QPM-Rust/cache Folder" - ls -lh $HOME/.local/share/QPM-Rust/cache + echo "Checking QPM/cache Folder" + ls -lh $HOME/.local/share/QPM-RS/cache echo "" - name: Build run: | cd ${GITHUB_WORKSPACE} - ./QPM/qpm-rust package edit --version ${{ env.version }} - ./QPM/qpm-rust qmod build pwsh -Command ./build.ps1 -actions - name: Get Library Name @@ -124,16 +106,16 @@ jobs: cd ./build/ pattern="lib${module_id}*.so" files=( $pattern ) - echo ::set-output name=NAME::"${files[0]}" + echo "NAME=${files[0]}" >> $GITHUB_OUTPUT - name: Package QMOD run: | cd ${GITHUB_WORKSPACE} - pwsh -Command ./buildQMOD.ps1 -package + ./QPM/qpm qmod zip -i ./build/ -i ./extern/libs/ ${module_id}_${version}.qmod - name: Upload non-debug artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ steps.libname.outputs.NAME }} path: ./build/${{ steps.libname.outputs.NAME }} @@ -141,7 +123,7 @@ jobs: - name: Upload debug artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: debug_${{ steps.libname.outputs.NAME }} path: ./build/debug/${{ steps.libname.outputs.NAME }} @@ -149,7 +131,7 @@ jobs: - name: Upload QMOD - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ env.module_id }}-(UNZIP-for-QMOD).qmod path: ./${{ env.module_id }}_${{ env.version }}.qmod diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index abf0576..85e3a58 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -9,69 +9,46 @@ on: env: module_id: QuestSounds - BSVersion: 1.28.0_4124311467 - ndkname: android-ndk-r24 jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 name: Checkout with: submodules: true lfs: true - - uses: seanmiddleditch/gha-setup-ninja@v3 - - #- name: Install Powershell - # run: sudo apt-get install -y powershell + - uses: seanmiddleditch/gha-setup-ninja@v5 - name: Get the tag name run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - #- name: Cache Android NDK - # id: cache-ndk - # uses: actions/cache@v2 - # env: - # cache-name: cache-ndk - # with: - # path: ndk - # key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.ndkname }} - # restore-keys: | - # ${{ runner.os }}-${{ env.cache-name }}-${{ env.ndkname }} - - #- name: Install Android NDK - # if: steps.cache-ndk.outputs.cache-hit != 'true' - # run: | - # wget -q -O ndk.zip https://dl.google.com/android/repository/${ndkname}-linux-x86_64.zip - # unzip -q ndk.zip - # mv ${ndkname} ndk - - #- name: Create ndkpath.txt - # run: | - # cd ndk - # pwd > ${GITHUB_WORKSPACE}/ndkpath.txt + - name: Get BSVersion + shell: pwsh + run: | + echo "BSVersion=$((Get-Content ./mod.template.json -Raw | ConvertFrom-Json).packageVersion)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Create ndkpath.txt run: | echo "$ANDROID_NDK_LATEST_HOME" > ${GITHUB_WORKSPACE}/ndkpath.txt - - name: Get QPM - if: steps.cache-qpm.outputs.cache-hit != 'true' - uses: dawidd6/action-download-artifact@v2 - with: - github_token: ${{secrets.GITHUB_TOKEN}} - workflow: cargo-build.yml - name: linux-qpm-rust - path: QPM - repo: RedBrumbler/QuestPackageManager-Rust - + - name: Get QPM + if: steps.cache-qpm.outputs.cache-hit != 'true' + uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: cargo-build.yml + name: linux-qpm + path: QPM + repo: QuestPackageManager/QPM.CLI + - name: QPM Collapse run: | - chmod +x ./QPM/qpm-rust - ./QPM/qpm-rust collapse + chmod +x ./QPM/qpm + ./QPM/qpm collapse - name: QPM Dependencies Cache id: cache-qpm-deps @@ -79,15 +56,17 @@ jobs: env: cache-name: cache-qpm-deps with: - path: /home/runner/.local/share/QPM-Rust/cache - key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('qpm.json', '.github/BuildQSounds.yml') }} + path: /home/runner/.local/share/QPM-RS/cache + key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('qpm.shared.json') }} restore-keys: | ${{ runner.os }}-${{ env.cache-name }}- ${{ runner.os }}-${{ env.cache-name }} - - name: QPM Restore + - name: QPM Set Version & Restore run: | - ./QPM/qpm-rust restore + ./QPM/qpm package edit --version ${{ env.version }} + ./QPM/qpm restore + - name: Check dependency Folders run: | @@ -98,14 +77,12 @@ jobs: ls -lh ${GITHUB_WORKSPACE}/extern/libs echo "" echo "Checking QPM-Rust/cache Folder" - ls -lh $HOME/.local/share/QPM-Rust/cache + ls -lh $HOME/.local/share/QPM-RS/cache echo "" - name: Build run: | cd ${GITHUB_WORKSPACE} - ./QPM/qpm-rust package edit --version ${{ env.version }} - ./QPM/qpm-rust qmod build pwsh -Command ./build.ps1 -actions - name: Get Library Name @@ -114,40 +91,18 @@ jobs: cd ./build/ pattern="lib${module_id}*.so" files=( $pattern ) - echo ::set-output name=NAME::"${files[0]}" + echo "NAME=${files[0]}" >> $GITHUB_OUTPUT - name: Package QMOD run: | cd ${GITHUB_WORKSPACE} - pwsh -Command ./buildQMOD.ps1 -package -release + ./QPM/qpm qmod zip -i ./build/ -i ./extern/libs/ ${module_id}_${version}.qmod - name: Release uses: softprops/action-gh-release@v1 with: name: ${{ env.module_id }} ${{ env.version }} for Beat Saber ${{ env.BSVersion }} files: | - ./${{ env.module_id }}.qmod + ./${{ env.module_id }}_${{ env.version }}.qmod body_path: ./rl-notes.md draft: true - - #- name: Create Release - # id: create_release - # uses: actions/create-release@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # with: - # tag_name: ${{ github.ref }} - # release_name: ${{ env.module_id }} ${{ github.ref }} for Beat Saber ${{ env.BSVersion }} - # body_path: ./rl-notes.md - # draft: true - # prerelease: false - #- name: Upload QMOD Release Asset - # id: upload-release-QMOD - # uses: actions/upload-release-asset@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # with: - # upload_url: ${{ steps.create_release.outputs.upload_url }} - # asset_path: ./${{ env.module_id }}.qmod - # asset_name: ${{ env.module_id }}.qmod - # asset_content_type: application/qmod \ No newline at end of file From d3aa9bbd3818a7e2a5a5e380ea887639a154c6ee Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 21:47:15 +0200 Subject: [PATCH 05/55] Update includes and logger, add export macro --- include/main.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/main.hpp b/include/main.hpp index 0279153..7c89aa1 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -1,23 +1,24 @@ #pragma once +// Logging +#include "paper/shared/Logger.hpp" + // 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/loader.hpp" // 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 -//#include "beatsaber-hook/shared/utils/utils.h" #include "beatsaber-hook/shared/utils/logging.hpp" -//#include "beatsaber-hook/shared/utils/typedefs.h" #include "beatsaber-hook/shared/utils/il2cpp-utils.hpp" #include "beatsaber-hook/shared/utils/il2cpp-functions.hpp" #include "beatsaber-hook/shared/config/config-utils.hpp" -#if !defined(MAKE_HOOK_OFFSETLESS) #include "beatsaber-hook/shared/utils/hooking.hpp" -#endif #include "System/Collections/IEnumerator.hpp" #include "custom-types/shared/coroutine.hpp" // Define these functions here so that we can easily read configuration and log information from other files Configuration& getConfig(); -Logger& getLogger(); \ No newline at end of file +Paper::ConstLoggerContext<9UL> getLogger(); + +#define QS_EXPORT extern "C" __attribute__((visibility("default"))) From 4d6dfacdb840de1685d19870616211a5a6304606 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 21:52:43 +0200 Subject: [PATCH 06/55] Remove legacy code, from main --- include/main.hpp | 2 +- src/main.cpp | 55 ++++++++++++++++++------------------------------ 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/include/main.hpp b/include/main.hpp index 7c89aa1..c0f8dcd 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -19,6 +19,6 @@ // Define these functions here so that we can easily read configuration and log information from other files Configuration& getConfig(); -Paper::ConstLoggerContext<9UL> getLogger(); +Paper::ConstLoggerContext<9UL>& getLogger(); #define QS_EXPORT extern "C" __attribute__((visibility("default"))) diff --git a/src/main.cpp b/src/main.cpp index 771e808..065363f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,9 +33,7 @@ using namespace GlobalNamespace; #include "UnityEngine/Time.hpp" using namespace UnityEngine::SceneManagement; -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/QuestUI.hpp" -using namespace QuestUI; +// TODO BSML #include "ViewControllers/MenuSdListViewController.hpp" #include "ViewControllers/HitSdListViewController.hpp" @@ -51,26 +49,19 @@ using namespace QuestSounds; #include "custom-types/shared/register.hpp" using namespace custom_types; -#if defined(MAKE_HOOK_OFFSETLESS) && !defined(MAKE_HOOK_MATCH) -#error Incompatible hook macro -#elif defined(MAKE_HOOK_MATCH) -#else -#error No Compatible HOOK macro found -#endif - #define RAPIDJSON_HAS_STDSTRING 1 -ModInfo modInfo; +inline modloader::ModInfo modInfo = {MOD_ID, VERSION, 0}; // Stores the ID and version of our mod, and is sent to the modloader upon startup Configuration& getConfig() { static Configuration config(modInfo); - //config.Load(); return config; } -Logger& getLogger() { - static auto logger = new Logger(modInfo, LoggerOptions(false, true)); - return *logger; +// TODO: Proper paper logging +Paper::ConstLoggerContext<9UL>& getLogger() { + static auto fastContext = Paper::Logger::WithContext(); + return fastContext; } void makeFolder() @@ -171,9 +162,7 @@ AsyncAudioClipLoader::loader hitSoundLoader, // hitSound fireworkSoundLoader, levelClearedLoader, levelFailedLoader, // For LevelFailed sound -#ifndef BS__1_13_2 lobbyAmbienceLoader; // Added for LobbyMusic -#endif Array * hitSoundArr, // hitSoundArray * badHitSoundArr, // badHitSoundArray * menuClickArr, @@ -284,7 +273,6 @@ MAKE_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, SongPreviewPlayer_OnEnable(self); } -#ifndef BS__1_13_2 MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlowCoordinator::DidActivate, void, GameServerLobbyFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); @@ -342,11 +330,10 @@ MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidDeactivate, &Multipla MultiplayerModeSelectionFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); } -#endif #ifdef DEBUG MAKE_HOOK_MATCH(FileHelpers_GetEscapedURLForFilePath, &FileHelpers::GetEscapedURLForFilePath, StringW, StringW filePath) { - return il2cpp_utils::newcsstr(std::u16string(u"file://") + std::u16string(csstrtostr(filePath))); + return StringW("file://" + filePath); } #endif @@ -445,7 +432,7 @@ MAKE_HOOK_MATCH(PauseMenuManager_MenuButtonPressed, &PauseMenuManager::MenuButto MAKE_HOOK_MATCH(SceneManager_Internal_ActiveSceneChanged, &SceneManager::Internal_ActiveSceneChanged, void, Scene previousActiveScene, Scene newActiveScene) { SceneManager_Internal_ActiveSceneChanged(previousActiveScene, newActiveScene); if (newActiveScene.IsValid()) { - std::string sceneName = to_utf8(csstrtostr(newActiveScene.get_name())); + std::string sceneName = newActiveScene.get_name(); getLogger().info("Scene found: %s", sceneName.data()); std::string questInit = "QuestInit"; @@ -453,12 +440,15 @@ MAKE_HOOK_MATCH(SceneManager_Internal_ActiveSceneChanged, &SceneManager::Interna } } -extern "C" void setup(ModInfo &info) -{ +QS_EXPORT void setup(CModInfo *info) { + *info = modInfo.to_c(); + info.id = MOD_ID; info.version = VERSION; modInfo = info; + Paper::Logger::RegisterFileContextId(getLogger().tag); + getLogger().info("Modloader name: %s", Modloader::getInfo().name.c_str()); getLogger().debug("Config Path is: %s", getConfig().getConfigFilePath(modInfo).c_str()); getLogger().info("Loading Config"); @@ -466,17 +456,14 @@ extern "C" void setup(ModInfo &info) getLogger().info("Completed setup!"); } -extern "C" void load() +QS_EXPORT void late_load() { il2cpp_functions::Init(); - QuestUI::Init(); Logger& hkLog = getLogger(); //custom_types::Register::RegisterType(); custom_types::Register::AutoRegister(); - //QuestUI::Register::RegisterModSettingsFlowCoordinator(modInfo); - QuestUI::Register::RegisterMainMenuModSettingsFlowCoordinator(modInfo); if(!LoadConfig()) SaveConfig(); makeFolder(); @@ -495,12 +482,12 @@ extern "C" void load() INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music - #ifdef DEBUG - auto ModList = Modloader::getMods(); - if (ModList.find("SongLoader") == ModList.end()) { - getLogger().info("SongLoader missing, installing FilePath check"); - INSTALL_HOOK(hkLog, FileHelpers_GetEscapedURLForFilePath); - } - #endif + // #ifdef DEBUG + // auto ModList = Modloader::getMods(); + // if (ModList.find("SongLoader") == ModList.end()) { + // getLogger().info("SongLoader missing, installing FilePath check"); + // INSTALL_HOOK(hkLog, FileHelpers_GetEscapedURLForFilePath); + // } + // #endif getLogger().debug("Installed QuestSounds!"); } From 544da1b79f058bab8f829a78c9ea6973cd205469 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 21:54:56 +0200 Subject: [PATCH 07/55] Remove all legacy strings --- include/Utils/AsyncAudiocliploader.hpp | 3 ++- src/UI/QSoundsFlowCoordinator.cpp | 2 +- src/UI/ViewControllers/ConfigViewController.cpp | 2 +- src/Utils/AsyncAudiocliploader.cpp | 12 ++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/Utils/AsyncAudiocliploader.hpp b/include/Utils/AsyncAudiocliploader.hpp index ff54071..11df93e 100644 --- a/include/Utils/AsyncAudiocliploader.hpp +++ b/include/Utils/AsyncAudiocliploader.hpp @@ -17,6 +17,7 @@ namespace AsyncAudioClipLoader { + // TODO: CustomTypes/Zenject? class loader : public Il2CppObject { public: @@ -33,7 +34,7 @@ namespace AsyncAudioClipLoader private: UnityEngine::GameObject* audioClipGO; static void audioClipCompleted(loader* obj, Il2CppObject* asyncOp); - Il2CppString* path; + StringW path; bool UsesUWR = false; System::Threading::Tasks::Task_1* audioClipTask; diff --git a/src/UI/QSoundsFlowCoordinator.cpp b/src/UI/QSoundsFlowCoordinator.cpp index 5d318aa..7525e07 100644 --- a/src/UI/QSoundsFlowCoordinator.cpp +++ b/src/UI/QSoundsFlowCoordinator.cpp @@ -55,7 +55,7 @@ void QSoundsFlowCoordinator::DidActivate(bool firstActivation, bool addedToHiera CurrentActive = 1; if (firstActivation) { - this->SetTitle(il2cpp_utils::newcsstr("QuestSounds MenuMusic"), HMUI::ViewController::AnimationDirection::Vertical); + this->SetTitle("QuestSounds MenuMusic", HMUI::ViewController::AnimationDirection::Vertical); this->showBackButton = true; if (!this->QSConfigView) this->QSConfigView = QuestUI::BeatSaberUI::CreateViewController(); diff --git a/src/UI/ViewControllers/ConfigViewController.cpp b/src/UI/ViewControllers/ConfigViewController.cpp index 99a0fbd..091f645 100644 --- a/src/UI/ViewControllers/ConfigViewController.cpp +++ b/src/UI/ViewControllers/ConfigViewController.cpp @@ -56,7 +56,7 @@ namespace QuestSounds::ViewControllers { VerticalLayoutGroup* settingsLayout = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(parent); RectTransform* settingsLayoutTransform = settingsLayout->GetComponent(); - settingsLayout->get_gameObject()->AddComponent()->ApplyBackground(il2cpp_utils::newcsstr("round-rect-panel")); + settingsLayout->get_gameObject()->AddComponent()->ApplyBackground("round-rect-panel"); settingsLayout->set_spacing(1.2f); settingsLayout->set_padding(UnityEngine::RectOffset::New_ctor(3, 3, 2, 2)); diff --git a/src/Utils/AsyncAudiocliploader.cpp b/src/Utils/AsyncAudiocliploader.cpp index e54e2dd..a84c670 100644 --- a/src/Utils/AsyncAudiocliploader.cpp +++ b/src/Utils/AsyncAudiocliploader.cpp @@ -52,7 +52,7 @@ bool AsyncAudioClipLoader::loader::load() bool fileError; getLogger().info("Starting Stage 0"); getLogger().info("FilePath to check is %s", filePath.c_str()); - Il2CppString* filePathStr; + StringW filePathStr; if (filePath.starts_with("https://") || filePath.starts_with("http://")) { getLogger().info("Filepath is URL, skipping file checks and try loading it"); fileError = true; @@ -74,7 +74,7 @@ bool AsyncAudioClipLoader::loader::load() if (!(filePath == QSoundsConfig::Config.hitSound_filepath) && filePath.ends_with(".ogg")) { getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath %s", filePath.c_str()); UsesUWR = false; - filePathStr = il2cpp_utils::newcsstr(filePath); + filePathStr = filePath; audioClipTask = GlobalNamespace::MediaAsyncLoader::New_ctor()->LoadAudioClipFromFilePathAsync(filePathStr); ////Stage 2 auto actionMAL = il2cpp_utils::MakeDelegate*>(classof(System::Action_1*), this, audioClipCompleted); @@ -84,10 +84,10 @@ bool AsyncAudioClipLoader::loader::load() getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath %s", filePath.c_str()); UsesUWR = true; if (filePath.starts_with("https://") || filePath.starts_with("http://")) { - filePathStr = il2cpp_utils::newcsstr(filePath); + filePathStr = filePath; } else { - filePathStr = il2cpp_utils::newcsstr("file:///" + filePath); + filePathStr = "file:///" + filePath; } audioType = getAudioType(filePath); @@ -120,7 +120,7 @@ void AsyncAudioClipLoader::loader::audioClipCompleted(loader* obj, Il2CppObject* if(temporaryClip != nullptr) { if (!obj->audioClipGO) { - static auto goName = il2cpp_utils::newcsstr("AudioClipGO"); + static auto goName = "AudioClipGO"; obj->audioClipGO = GameObject::New_ctor(goName); obj->audioSource = obj->audioClipGO->AddComponent(); UnityEngine::Object::DontDestroyOnLoad(obj->audioClipGO); @@ -156,7 +156,7 @@ void AsyncAudioClipLoader::loader::set_OriginalClip(AudioClip* OriginalAudioClip // Stage 1 if (OriginalAudioClip != nullptr) { - static auto goName = il2cpp_utils::newcsstr("OrigAudioClipGO"); + static auto goName = "OrigAudioClipGO"; GameObject* audioClipGO = GameObject::New_ctor(goName); OriginalAudioSource = audioClipGO->AddComponent(); OriginalAudioSource->set_playOnAwake(false); From adbd785c776b5692a5f8dec626d43f8e14bedd4b Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 22:00:57 +0200 Subject: [PATCH 08/55] Remove qpm.shared from gitignore --- .gitignore | 3 - qpm.shared.json | 239 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 qpm.shared.json diff --git a/.gitignore b/.gitignore index 59fd1a2..d1133ff 100644 --- a/.gitignore +++ b/.gitignore @@ -52,9 +52,6 @@ ndkpath.txt # Other files extern/ - -qpm.shared.json -extern/ *.backup *.log diff --git a/qpm.shared.json b/qpm.shared.json new file mode 100644 index 0000000..dccb89a --- /dev/null +++ b/qpm.shared.json @@ -0,0 +1,239 @@ +{ + "config": { + "version": "0.1.0", + "sharedDir": "shared", + "dependenciesDir": "extern", + "info": { + "name": "QuestSounds", + "id": "QuestSounds", + "version": "1.5.0-Dev", + "url": null, + "additionalData": { + "overrideSoName": "libQuestSounds.so" + } + }, + "workspace": { + "scripts": {}, + "qmodIncludeDirs": [], + "qmodIncludeFiles": [], + "qmodOutput": null + }, + "dependencies": [ + { + "id": "beatsaber-hook", + "versionRange": "^5.1.9", + "additionalData": {} + }, + { + "id": "scotland2", + "versionRange": "^0.1.4", + "additionalData": { + "includeQmod": false, + "private": true + } + }, + { + "id": "bs-cordl", + "versionRange": "^3700.0.0", + "additionalData": {} + }, + { + "id": "custom-types", + "versionRange": "^0.17.10", + "additionalData": {} + }, + { + "id": "bsml", + "versionRange": "^0.4.43", + "additionalData": {} + }, + { + "id": "config-utils", + "versionRange": "^1.4.2", + "additionalData": {} + }, + { + "id": "paper", + "versionRange": "^3.6.4", + "additionalData": {} + } + ] + }, + "restoredDependencies": [ + { + "dependency": { + "id": "paper", + "versionRange": "=3.6.4", + "additionalData": { + "soLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.4/libpaperlog.so", + "debugSoLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.4/debug_libpaperlog.so", + "overrideSoName": "libpaperlog.so", + "modLink": "https://github.com/Fernthedev/paperlog/releases/download/v3.6.4/paperlog.qmod", + "branchName": "version/v3_6_4", + "compileOptions": { + "systemIncludes": [ + "shared/utfcpp/source" + ] + }, + "cmake": false + } + }, + "version": "3.6.4" + }, + { + "dependency": { + "id": "bsml", + "versionRange": "=0.4.43", + "additionalData": { + "soLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.43/libbsml.so", + "debugSoLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.43/debug_libbsml.so", + "overrideSoName": "libbsml.so", + "modLink": "https://github.com/RedBrumbler/Quest-BSML/releases/download/v0.4.43/BSML.qmod", + "branchName": "version/v0_4_43", + "cmake": true + } + }, + "version": "0.4.43" + }, + { + "dependency": { + "id": "libil2cpp", + "versionRange": "=0.3.2", + "additionalData": { + "headersOnly": true, + "cmake": false + } + }, + "version": "0.3.2" + }, + { + "dependency": { + "id": "config-utils", + "versionRange": "=1.4.2", + "additionalData": { + "headersOnly": true, + "soLink": "https://github.com/darknight1050/config-utils/releases/download/v1.4.2/libconfig-utils_test.so", + "overrideSoName": "libconfig-utils_test.so", + "branchName": "version/v1_4_2", + "cmake": true + } + }, + "version": "1.4.2" + }, + { + "dependency": { + "id": "custom-types", + "versionRange": "=0.17.10", + "additionalData": { + "soLink": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.10/libcustom-types.so", + "debugSoLink": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.10/debug_libcustom-types.so", + "overrideSoName": "libcustom-types.so", + "modLink": "https://github.com/QuestPackageManager/Il2CppQuestTypePatching/releases/download/v0.17.10/CustomTypes.qmod", + "branchName": "version/v0_17_10", + "compileOptions": { + "cppFlags": [ + "-Wno-invalid-offsetof" + ] + }, + "cmake": true + } + }, + "version": "0.17.10" + }, + { + "dependency": { + "id": "rapidjson-macros", + "versionRange": "=1.2.1", + "additionalData": { + "headersOnly": true, + "branchName": "version/v1_2_1", + "cmake": true + } + }, + "version": "1.2.1" + }, + { + "dependency": { + "id": "bs-cordl", + "versionRange": "=3700.0.0", + "additionalData": { + "headersOnly": true, + "branchName": "version/v3700_0_0", + "compileOptions": { + "includePaths": [ + "include" + ], + "cppFeatures": [], + "cppFlags": [ + "-DNEED_UNSAFE_CSHARP", + "-fdeclspec", + "-DUNITY_2021", + "-DHAS_CODEGEN" + ] + } + } + }, + "version": "3700.0.0" + }, + { + "dependency": { + "id": "beatsaber-hook", + "versionRange": "=5.1.9", + "additionalData": { + "soLink": "https://github.com/QuestPackageManager/beatsaber-hook/releases/download/v5.1.9/libbeatsaber-hook_5_1_9.so", + "debugSoLink": "https://github.com/QuestPackageManager/beatsaber-hook/releases/download/v5.1.9/debug_libbeatsaber-hook_5_1_9.so", + "branchName": "version/v5_1_9", + "cmake": true + } + }, + "version": "5.1.9" + }, + { + "dependency": { + "id": "scotland2", + "versionRange": "=0.1.4", + "additionalData": { + "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.1.4" + }, + { + "dependency": { + "id": "fmt", + "versionRange": "=10.0.0", + "additionalData": { + "headersOnly": true, + "branchName": "version/v10_0_0", + "compileOptions": { + "systemIncludes": [ + "fmt/include/" + ], + "cppFlags": [ + "-DFMT_HEADER_ONLY" + ] + } + } + }, + "version": "10.0.0" + }, + { + "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" + } + ] +} \ No newline at end of file From 02b03ac07dd578987cf25b0228f497170ee2b9da Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 22:04:36 +0200 Subject: [PATCH 09/55] Fix casing --- include/main.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/main.hpp b/include/main.hpp index c0f8dcd..75e98f9 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -1,7 +1,7 @@ #pragma once // Logging -#include "paper/shared/Logger.hpp" +#include "paper/shared/logger.hpp" // Include the modloader header, which allows us to tell the modloader which mod this is, and the version etc. #include "scotland2/shared/loader.hpp" From 6224174809026333bea7bcf439fc454547e705d5 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Wed, 10 Jul 2024 22:11:36 +0200 Subject: [PATCH 10/55] Remove ID define --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0379af1..01384c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,6 @@ add_compile_options(-frtti -fexceptions) add_compile_options(-Ofast) # compile definitions used add_compile_definitions(VERSION=\"${MOD_VERSION}\") -add_compile_definitions(ID=\"${MOD_ID}\") add_compile_definitions(MOD_ID=\"${MOD_ID}\") # recursively get all src files From 70ac1d174fd294e217ea3bbce819d722fbfb0d08 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Thu, 18 Jul 2024 15:31:07 +0200 Subject: [PATCH 11/55] Temporary remove questui includes --- include/QSoundsConfig.hpp | 4 +-- .../BadHitSdListViewController.hpp | 2 +- .../FireworkSdListViewController.hpp | 2 +- .../HitSdListViewController.hpp | 2 +- .../LevelClearedSdListViewController.hpp | 2 +- .../LevelFailedSdListViewController.hpp | 2 +- .../LobbyMusicSdListViewController.hpp | 16 +++--------- .../MenuClickSdListViewController.hpp | 2 +- .../MenuSdListViewController.hpp | 2 +- .../NoteMissedSdListViewController.hpp | 2 +- src/UI/QSoundsFlowCoordinator.cpp | 25 ++----------------- .../BadHitSdListViewController.cpp | 12 +++------ .../ViewControllers/ConfigViewController.cpp | 2 +- .../FireworkSdListViewController.cpp | 6 ++--- .../HitSdListViewController.cpp | 6 ++--- .../LevelClearedSdListViewController.cpp | 6 ++--- .../LevelFailedSdListViewController.cpp | 4 +-- .../LobbyMusicSdListViewController.cpp | 6 ++--- .../MenuClickSdListViewController.cpp | 6 ++--- .../MenuSdListViewController.cpp | 6 ++--- .../NoteMissedSdListViewController.cpp | 4 +-- 21 files changed, 40 insertions(+), 79 deletions(-) diff --git a/include/QSoundsConfig.hpp b/include/QSoundsConfig.hpp index c030782..516d688 100644 --- a/include/QSoundsConfig.hpp +++ b/include/QSoundsConfig.hpp @@ -7,7 +7,7 @@ #define CONFIG_VERSION_PRE_R "SoundsConfig_v1" #define CONFIG_VERSION_LEGACY "Sounds" #include "UnityEngine/UI/Toggle.hpp" -#include "questui/shared/BeatSaberUI.hpp" + namespace QSoundsConfig { static std::string soundPath = string_format(SOUND_PATH_FORMAT, Modloader::getApplicationId().c_str());; @@ -20,9 +20,7 @@ namespace QSoundsConfig { static std::string FireworkSoundPath = soundPath + "Fireworks/"; static std::string LevelClearedPath = soundPath + "LevelCleared/"; static std::string LevelFailedPath = soundPath + "LevelFailed/"; -#ifndef BS__1_13_2 static std::string LobbyMusicPath = soundPath + "LobbyMusic/"; -#endif extern bool LegacyConfig; diff --git a/include/ViewControllers/BadHitSdListViewController.hpp b/include/ViewControllers/BadHitSdListViewController.hpp index ccd8324..eb12bac 100644 --- a/include/ViewControllers/BadHitSdListViewController.hpp +++ b/include/ViewControllers/BadHitSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/include/ViewControllers/FireworkSdListViewController.hpp b/include/ViewControllers/FireworkSdListViewController.hpp index ffc4a4a..8b93b5f 100644 --- a/include/ViewControllers/FireworkSdListViewController.hpp +++ b/include/ViewControllers/FireworkSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/include/ViewControllers/HitSdListViewController.hpp b/include/ViewControllers/HitSdListViewController.hpp index 2523397..f710607 100644 --- a/include/ViewControllers/HitSdListViewController.hpp +++ b/include/ViewControllers/HitSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/include/ViewControllers/LevelClearedSdListViewController.hpp b/include/ViewControllers/LevelClearedSdListViewController.hpp index 782e2e8..e4b6584 100644 --- a/include/ViewControllers/LevelClearedSdListViewController.hpp +++ b/include/ViewControllers/LevelClearedSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/include/ViewControllers/LevelFailedSdListViewController.hpp b/include/ViewControllers/LevelFailedSdListViewController.hpp index f90fa02..2b62589 100644 --- a/include/ViewControllers/LevelFailedSdListViewController.hpp +++ b/include/ViewControllers/LevelFailedSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/include/ViewControllers/LobbyMusicSdListViewController.hpp b/include/ViewControllers/LobbyMusicSdListViewController.hpp index a62d890..fd2c449 100644 --- a/include/ViewControllers/LobbyMusicSdListViewController.hpp +++ b/include/ViewControllers/LobbyMusicSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" @@ -8,16 +8,6 @@ DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, LobbyMusicSdListViewControll DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(LobbyMusicSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif + DECLARE_OVERRIDE_METHOD_MATCH(void, DidActivate, &HMUI::ViewController::DidActivate, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); + DECLARE_OVERRIDE_METHOD_MATCH(void, DidDeactivate, &HMUI::ViewController::DidDeactivate, bool removedFromHierarchy, bool systemScreenDisabling); ); \ No newline at end of file diff --git a/include/ViewControllers/MenuClickSdListViewController.hpp b/include/ViewControllers/MenuClickSdListViewController.hpp index 99a9218..0447c9c 100644 --- a/include/ViewControllers/MenuClickSdListViewController.hpp +++ b/include/ViewControllers/MenuClickSdListViewController.hpp @@ -1,4 +1,4 @@ -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/include/ViewControllers/MenuSdListViewController.hpp b/include/ViewControllers/MenuSdListViewController.hpp index 6ccc96c..6523428 100644 --- a/include/ViewControllers/MenuSdListViewController.hpp +++ b/include/ViewControllers/MenuSdListViewController.hpp @@ -1,4 +1,4 @@ -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" #include "HMUI/ModalView.hpp" diff --git a/include/ViewControllers/NoteMissedSdListViewController.hpp b/include/ViewControllers/NoteMissedSdListViewController.hpp index eae3c8c..fa63f48 100644 --- a/include/ViewControllers/NoteMissedSdListViewController.hpp +++ b/include/ViewControllers/NoteMissedSdListViewController.hpp @@ -1,5 +1,5 @@ #pragma once -#include "questui/shared/BeatSaberUI.hpp" + #include "custom-types/shared/macros.hpp" #include "HMUI/ViewController.hpp" diff --git a/src/UI/QSoundsFlowCoordinator.cpp b/src/UI/QSoundsFlowCoordinator.cpp index 7525e07..f8cfb0a 100644 --- a/src/UI/QSoundsFlowCoordinator.cpp +++ b/src/UI/QSoundsFlowCoordinator.cpp @@ -17,8 +17,8 @@ #include "AudioClips.hpp" #include "ObjectInstances.hpp" -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/QuestUI.hpp" + +#include "bsml/shared/BSML-Lite.hpp" #include "HMUI/ViewController.hpp" #include "HMUI/ViewController_AnimationType.hpp" @@ -27,26 +27,7 @@ using namespace QuestSounds; using namespace QuestSounds::ViewControllers; -#ifndef REGISTER_FUNCTION DEFINE_TYPE(QuestSounds, QSoundsFlowCoordinator); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QSoundsFlowCoordinator); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QSoundsFlowCoordinator); -#else -#error Unsupported Custom-Types version! -#endif - -//void FindViewControllers(QuestSounds::QSoundsFlowCoordinator* self) -//{ -// //self->QSMenuSoundListView = UnityUtils::GetFirstObjectOfType(); -// -// //self->QSHitSoundListView = UnityUtils::GetFirstObjectOfType(); -// -// //self->WallSwitcherViewController = UnityUtils::GetFirstObjectOfType(); -// -// //self->QosmeticsViewController = UnityUtils::GetFirstObjectOfType(); -//} int CurrentActive; @@ -67,9 +48,7 @@ void QSoundsFlowCoordinator::DidActivate(bool firstActivation, bool addedToHiera if (!this->QSFireworkSoundListView) this->QSFireworkSoundListView = QuestUI::BeatSaberUI::CreateViewController(); if (!this->QSLevelClearedSoundListView) this->QSLevelClearedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); if (!this->QSLevelFailedSoundListView) this->QSLevelFailedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); -#ifndef BS__1_13_2 if (!this->QSLobbyMusicSoundListView) this->QSLobbyMusicSoundListView = QuestUI::BeatSaberUI::CreateViewController(); -#endif QSConfigViewController = reinterpret_cast(QSConfigView); diff --git a/src/UI/ViewControllers/BadHitSdListViewController.cpp b/src/UI/ViewControllers/BadHitSdListViewController.cpp index d113584..7d66b34 100644 --- a/src/UI/ViewControllers/BadHitSdListViewController.cpp +++ b/src/UI/ViewControllers/BadHitSdListViewController.cpp @@ -7,8 +7,6 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" @@ -21,15 +19,10 @@ #include "UnityEngine/Events/UnityAction.hpp" #include "TMPro/TextMeshProUGUI.hpp" +#include "bsml/shared/BSML-Lite.hpp" using namespace QuestSounds; -#ifndef REGISTER_FUNCTION DEFINE_TYPE(QuestSounds::ViewControllers, BadHitSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::BadHitSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::BadHitSdListViewController); -#endif namespace QuestSounds::ViewControllers { @@ -42,11 +35,12 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.badHitSound_filepath = QSoundsConfig::BadHitSoundPath + filename; AudioClips::badHitSoundLoader.filePath = QSoundsConfig::Config.badHitSound_filepath; if (AudioClips::badHitSoundLoader.audioSource != nullptr) AudioClips::badHitSoundLoader.audioSource->Stop(); AudioClips::badHitSoundLoader.load(); + // TODO: Proper thread handling std::thread PlayAudio([&]() { while (!AudioClips::badHitSoundLoader.loaded && QSoundsConfig::Config.badHitSound_Active) { usleep(100); diff --git a/src/UI/ViewControllers/ConfigViewController.cpp b/src/UI/ViewControllers/ConfigViewController.cpp index 091f645..8f863e7 100644 --- a/src/UI/ViewControllers/ConfigViewController.cpp +++ b/src/UI/ViewControllers/ConfigViewController.cpp @@ -3,7 +3,7 @@ #include "ViewControllers/ConfigViewController.hpp" #include "main.hpp" -#include "questui/shared/BeatSaberUI.hpp" + #include "questui/shared/CustomTypes/Components/Backgroundable.hpp" #include "questui/shared/QuestUI.hpp" diff --git a/src/UI/ViewControllers/FireworkSdListViewController.cpp b/src/UI/ViewControllers/FireworkSdListViewController.cpp index c8877d4..92482b5 100644 --- a/src/UI/ViewControllers/FireworkSdListViewController.cpp +++ b/src/UI/ViewControllers/FireworkSdListViewController.cpp @@ -7,8 +7,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" @@ -48,7 +48,7 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.firework_filepath = QSoundsConfig::FireworkSoundPath + filename; AudioClips::fireworkSoundLoader.filePath = QSoundsConfig::Config.firework_filepath; if (AudioClips::fireworkSoundLoader.audioSource != nullptr) AudioClips::fireworkSoundLoader.audioSource->Stop(); diff --git a/src/UI/ViewControllers/HitSdListViewController.cpp b/src/UI/ViewControllers/HitSdListViewController.cpp index a998311..69f7ef0 100644 --- a/src/UI/ViewControllers/HitSdListViewController.cpp +++ b/src/UI/ViewControllers/HitSdListViewController.cpp @@ -7,8 +7,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" @@ -42,7 +42,7 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.hitSound_filepath = QSoundsConfig::HitSoundPath + filename; AudioClips::hitSoundLoader.filePath = QSoundsConfig::Config.hitSound_filepath; if (AudioClips::hitSoundLoader.audioSource != nullptr) AudioClips::hitSoundLoader.audioSource->Stop(); diff --git a/src/UI/ViewControllers/LevelClearedSdListViewController.cpp b/src/UI/ViewControllers/LevelClearedSdListViewController.cpp index a5a7e95..04cfc70 100644 --- a/src/UI/ViewControllers/LevelClearedSdListViewController.cpp +++ b/src/UI/ViewControllers/LevelClearedSdListViewController.cpp @@ -8,8 +8,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" @@ -43,7 +43,7 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.levelCleared_filepath = QSoundsConfig::LevelClearedPath + filename; QuestSounds::AudioClips::levelClearedLoader.filePath = QSoundsConfig::Config.levelCleared_filepath; if (AudioClips::levelClearedLoader.audioSource != nullptr) AudioClips::levelClearedLoader.audioSource->Stop(); diff --git a/src/UI/ViewControllers/LevelFailedSdListViewController.cpp b/src/UI/ViewControllers/LevelFailedSdListViewController.cpp index 2d48af4..1381cb3 100644 --- a/src/UI/ViewControllers/LevelFailedSdListViewController.cpp +++ b/src/UI/ViewControllers/LevelFailedSdListViewController.cpp @@ -8,8 +8,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" diff --git a/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp b/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp index a57ce16..e049a8b 100644 --- a/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp +++ b/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp @@ -8,8 +8,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" @@ -45,7 +45,7 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.lobbyAmbience_filepath = QSoundsConfig::LobbyMusicPath + filename; QuestSounds::AudioClips::lobbyAmbienceLoader.filePath = QSoundsConfig::Config.lobbyAmbience_filepath; if (AudioClips::lobbyAmbienceLoader.audioSource != nullptr) AudioClips::lobbyAmbienceLoader.audioSource->Stop(); diff --git a/src/UI/ViewControllers/MenuClickSdListViewController.cpp b/src/UI/ViewControllers/MenuClickSdListViewController.cpp index cf30ef5..89f6a3a 100644 --- a/src/UI/ViewControllers/MenuClickSdListViewController.cpp +++ b/src/UI/ViewControllers/MenuClickSdListViewController.cpp @@ -7,8 +7,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" @@ -46,7 +46,7 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.menuClick_filepath = QSoundsConfig::MenuClickPath + filename; AudioClips::menuClickLoader.filePath = QSoundsConfig::Config.menuClick_filepath; if (AudioClips::menuClickLoader.audioSource != nullptr) AudioClips::menuClickLoader.audioSource->Stop(); diff --git a/src/UI/ViewControllers/MenuSdListViewController.cpp b/src/UI/ViewControllers/MenuSdListViewController.cpp index fc6f86e..f98bb6b 100644 --- a/src/UI/ViewControllers/MenuSdListViewController.cpp +++ b/src/UI/ViewControllers/MenuSdListViewController.cpp @@ -9,8 +9,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "questui/shared/CustomTypes/Components/MainThreadScheduler.hpp" #include "UnityEngine/Object.hpp" @@ -52,7 +52,7 @@ namespace QuestSounds::ViewControllers { { if (button->get_hasSelection()) { - std::string filename = to_utf8(csstrtostr(button->GetComponentInChildren()->get_text())); + std::string filename = button->GetComponentInChildren()->get_text(); QSoundsConfig::Config.menuMusic_filepath = QSoundsConfig::MenuMusicPath + filename; QuestSounds::AudioClips::menuMusicLoader.filePath = QSoundsConfig::Config.menuMusic_filepath; AudioClips::menuMusicLoader.loaded = false; diff --git a/src/UI/ViewControllers/NoteMissedSdListViewController.cpp b/src/UI/ViewControllers/NoteMissedSdListViewController.cpp index 6f79085..606844c 100644 --- a/src/UI/ViewControllers/NoteMissedSdListViewController.cpp +++ b/src/UI/ViewControllers/NoteMissedSdListViewController.cpp @@ -7,8 +7,8 @@ #include #include -#include "questui/shared/BeatSaberUI.hpp" -#include "questui/shared/CustomTypes/Components/ExternalComponents.hpp" + + #include "UnityEngine/Object.hpp" #include "UnityEngine/GameObject.hpp" From af73cdb695f0c3cd7021d19d3a70ee8a1e769314 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Thu, 18 Jul 2024 15:37:55 +0200 Subject: [PATCH 12/55] Cleanup ObjectInstances.hpp --- include/ObjectInstances.hpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/include/ObjectInstances.hpp b/include/ObjectInstances.hpp index cb62b1b..19cce87 100644 --- a/include/ObjectInstances.hpp +++ b/include/ObjectInstances.hpp @@ -1,16 +1,8 @@ #pragma once #include "main.hpp" -#include "QSoundsFlowCoordinator.hpp" +// #include "QSoundsFlowCoordinator.hpp" -//#include "GlobalNamespace/ResultsViewController.hpp" #include "GlobalNamespace/SongPreviewPlayer.hpp" -//#include "GlobalNamespace/NoteCutSoundEffectManager.hpp" -//#include "GlobalNamespace/NoteCutSoundEffect.hpp" -//#include "GlobalNamespace/BasicUIAudioManager.hpp" -//#include "GlobalNamespace/FireworkItemController.hpp" -//#include "GlobalNamespace/GameServerLobbyFlowCoordinator.hpp" -//#include "GlobalNamespace/MultiplayerModeSelectionFlowCoordinator.hpp" - namespace QuestSounds::ObjectInstances { extern GlobalNamespace::SongPreviewPlayer* SPP; From 3d572c72b2ae977e62bad323c29859946a7a3936 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Thu, 18 Jul 2024 15:38:23 +0200 Subject: [PATCH 13/55] Remove all UI --- include/QSoundsFlowCoordinator.hpp | 50 ----- include/Utils/AsyncAudiocliploader.hpp | 2 +- .../BadHitSdListViewController.hpp | 23 -- .../ViewControllers/ConfigViewController.hpp | 26 --- .../FireworkSdListViewController.hpp | 23 -- .../HitSdListViewController.hpp | 23 -- .../LevelClearedSdListViewController.hpp | 23 -- .../LevelFailedSdListViewController.hpp | 23 -- .../LobbyMusicSdListViewController.hpp | 13 -- .../MenuClickSdListViewController.hpp | 23 -- .../MenuSdListViewController.hpp | 26 --- .../NoteMissedSdListViewController.hpp | 23 -- src/UI/QSoundsFlowCoordinator.cpp | 145 ------------- .../BadHitSdListViewController.cpp | 150 ------------- .../ViewControllers/ConfigViewController.cpp | 129 ----------- .../FireworkSdListViewController.cpp | 179 ---------------- .../HitSdListViewController.cpp | 160 -------------- .../LevelClearedSdListViewController.cpp | 145 ------------- .../LevelFailedSdListViewController.cpp | 157 -------------- .../LobbyMusicSdListViewController.cpp | 149 ------------- .../MenuClickSdListViewController.cpp | 161 -------------- .../MenuSdListViewController.cpp | 202 ------------------ .../NoteMissedSdListViewController.cpp | 156 -------------- 23 files changed, 1 insertion(+), 2010 deletions(-) delete mode 100644 include/QSoundsFlowCoordinator.hpp delete mode 100644 include/ViewControllers/BadHitSdListViewController.hpp delete mode 100644 include/ViewControllers/ConfigViewController.hpp delete mode 100644 include/ViewControllers/FireworkSdListViewController.hpp delete mode 100644 include/ViewControllers/HitSdListViewController.hpp delete mode 100644 include/ViewControllers/LevelClearedSdListViewController.hpp delete mode 100644 include/ViewControllers/LevelFailedSdListViewController.hpp delete mode 100644 include/ViewControllers/LobbyMusicSdListViewController.hpp delete mode 100644 include/ViewControllers/MenuClickSdListViewController.hpp delete mode 100644 include/ViewControllers/MenuSdListViewController.hpp delete mode 100644 include/ViewControllers/NoteMissedSdListViewController.hpp delete mode 100644 src/UI/QSoundsFlowCoordinator.cpp delete mode 100644 src/UI/ViewControllers/BadHitSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/ConfigViewController.cpp delete mode 100644 src/UI/ViewControllers/FireworkSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/HitSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/LevelClearedSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/LevelFailedSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/LobbyMusicSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/MenuClickSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/MenuSdListViewController.cpp delete mode 100644 src/UI/ViewControllers/NoteMissedSdListViewController.cpp diff --git a/include/QSoundsFlowCoordinator.hpp b/include/QSoundsFlowCoordinator.hpp deleted file mode 100644 index 9f4d3ae..0000000 --- a/include/QSoundsFlowCoordinator.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once -#include "custom-types/shared/macros.hpp" -#include "HMUI/FlowCoordinator.hpp" -#include "HMUI/ViewController.hpp" - -#include "ViewControllers/ConfigViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds, QSoundsFlowCoordinator, HMUI::FlowCoordinator, - - DECLARE_INSTANCE_FIELD_DEFAULT(QuestSounds::ViewControllers::ConfigViewController*, QSConfigViewController, nullptr); - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "FlowCoordinator", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, BackButtonWasPressed, il2cpp_utils::FindMethodUnsafe("HMUI", "FlowCoordinator", "BackButtonWasPressed", 1), HMUI::ViewController* topViewController); - - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSConfigView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSMenuSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSHitSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSMenuClickSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSBadHitSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSNoteMissedSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSFireworkSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSLevelClearedSoundListView); - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSLevelFailedSoundListView); -#ifndef BS__1_13_2 - DECLARE_INSTANCE_FIELD(HMUI::ViewController*, QSLobbyMusicSoundListView); -#endif - - - public: - void SubMenuButtonWasPressed(int VCtype); - -#if defined(BS__1_16) && defined(REGISTER_FUNCTION) - REGISTER_FUNCTION( -#elif defined(BS__1_13_2) - REGISTER_FUNCTION(QSoundsFlowCoordinator, -#endif -#if defined(REGISTER_METHOD) - REGISTER_FIELD(QSConfigViewController); - REGISTER_FIELD(QSConfigView); - REGISTER_METHOD(QSMenuSoundListView); - REGISTER_METHOD(QSHitSoundListView); - REGISTER_METHOD(QSMenuClickSoundListView); - REGISTER_METHOD(QSBadHitSoundListView); - REGISTER_METHOD(QSFireworkSoundListView); - REGISTER_METHOD(QSLevelClearedSoundListView); - REGISTER_METHOD(QSLevelFailedSoundListView); - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(BackButtonWasPressed); - ) -#endif -); \ No newline at end of file diff --git a/include/Utils/AsyncAudiocliploader.hpp b/include/Utils/AsyncAudiocliploader.hpp index 11df93e..f2249cd 100644 --- a/include/Utils/AsyncAudiocliploader.hpp +++ b/include/Utils/AsyncAudiocliploader.hpp @@ -17,7 +17,7 @@ namespace AsyncAudioClipLoader { - // TODO: CustomTypes/Zenject? + // TODO: CustomTypes/Zenject or just a cpp class? class loader : public Il2CppObject { public: diff --git a/include/ViewControllers/BadHitSdListViewController.hpp b/include/ViewControllers/BadHitSdListViewController.hpp deleted file mode 100644 index eb12bac..0000000 --- a/include/ViewControllers/BadHitSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, BadHitSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(BadHitSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/ConfigViewController.hpp b/include/ViewControllers/ConfigViewController.hpp deleted file mode 100644 index bd7ac1a..0000000 --- a/include/ViewControllers/ConfigViewController.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -// ViewController for the settings UI -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, ConfigViewController, HMUI::ViewController, - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - //DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); - - public: - void set_selectCallback(std::function callback); - std::function callback; - -#if defined(BS__1_16) && defined(REGISTER_FUNCTION) - REGISTER_FUNCTION( -#elif defined(BS__1_13_2) - REGISTER_FUNCTION(ConfigViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - //REGISTER_METHOD(DidDeactivate); - ) -#endif -); - - diff --git a/include/ViewControllers/FireworkSdListViewController.hpp b/include/ViewControllers/FireworkSdListViewController.hpp deleted file mode 100644 index 8b93b5f..0000000 --- a/include/ViewControllers/FireworkSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, FireworkSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(FireworkSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/HitSdListViewController.hpp b/include/ViewControllers/HitSdListViewController.hpp deleted file mode 100644 index f710607..0000000 --- a/include/ViewControllers/HitSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, HitSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(HitSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/LevelClearedSdListViewController.hpp b/include/ViewControllers/LevelClearedSdListViewController.hpp deleted file mode 100644 index e4b6584..0000000 --- a/include/ViewControllers/LevelClearedSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, LevelClearedSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(LevelClearedSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/LevelFailedSdListViewController.hpp b/include/ViewControllers/LevelFailedSdListViewController.hpp deleted file mode 100644 index 2b62589..0000000 --- a/include/ViewControllers/LevelFailedSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, LevelFailedSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(LevelClearedSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/LobbyMusicSdListViewController.hpp b/include/ViewControllers/LobbyMusicSdListViewController.hpp deleted file mode 100644 index fd2c449..0000000 --- a/include/ViewControllers/LobbyMusicSdListViewController.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, LobbyMusicSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD_MATCH(void, DidActivate, &HMUI::ViewController::DidActivate, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD_MATCH(void, DidDeactivate, &HMUI::ViewController::DidDeactivate, bool removedFromHierarchy, bool systemScreenDisabling); -); \ No newline at end of file diff --git a/include/ViewControllers/MenuClickSdListViewController.hpp b/include/ViewControllers/MenuClickSdListViewController.hpp deleted file mode 100644 index 0447c9c..0000000 --- a/include/ViewControllers/MenuClickSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, MenuClickSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); - -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(MenuClickSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/MenuSdListViewController.hpp b/include/ViewControllers/MenuSdListViewController.hpp deleted file mode 100644 index 6523428..0000000 --- a/include/ViewControllers/MenuSdListViewController.hpp +++ /dev/null @@ -1,26 +0,0 @@ - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" -#include "HMUI/ModalView.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, MenuSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); - - DECLARE_INSTANCE_FIELD(HMUI::ModalView*, modal); - -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(MenuSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/include/ViewControllers/NoteMissedSdListViewController.hpp b/include/ViewControllers/NoteMissedSdListViewController.hpp deleted file mode 100644 index fa63f48..0000000 --- a/include/ViewControllers/NoteMissedSdListViewController.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "custom-types/shared/macros.hpp" -#include "HMUI/ViewController.hpp" - -DECLARE_CLASS_CODEGEN(QuestSounds::ViewControllers, NoteMissedSdListViewController, HMUI::ViewController, - DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, QSconfigcontainer); - DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, listtxtgroup); - DECLARE_INSTANCE_FIELD(UnityEngine::GameObject*, SDlistscroll); - - DECLARE_OVERRIDE_METHOD(void, DidActivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidActivate", 3), bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); - DECLARE_OVERRIDE_METHOD(void, DidDeactivate, il2cpp_utils::FindMethodUnsafe("HMUI", "ViewController", "DidDeactivate", 2), bool removedFromHierarchy, bool systemScreenDisabling); -#if defined(REGISTER_FUNCTION) && defined(BS__1_16) - REGISTER_FUNCTION( -#elif defined(REGISTER_FUNCTION) && defined(BS__1_13_2) - REGISTER_FUNCTION(BadHitSdListViewController, -#endif -#if defined(REGISTER_METHOD) - REGISTER_METHOD(DidActivate); - REGISTER_METHOD(DidDeactivate); - ) -#endif -); \ No newline at end of file diff --git a/src/UI/QSoundsFlowCoordinator.cpp b/src/UI/QSoundsFlowCoordinator.cpp deleted file mode 100644 index f8cfb0a..0000000 --- a/src/UI/QSoundsFlowCoordinator.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "main.hpp" -#include "QSoundsFlowCoordinator.hpp" -#include "ViewControllers/MenuSdListViewController.hpp" -#include "ViewControllers/HitSdListViewController.hpp" -#include "ViewControllers/MenuClickSdListViewController.hpp" -#include "ViewControllers/BadHitSdListViewController.hpp" -#include "ViewControllers/NoteMissedSdListViewController.hpp" -#include "ViewControllers/FireworkSdListViewController.hpp" -#include "ViewControllers/LevelClearedSdListViewController.hpp" -#include "ViewControllers/LevelFailedSdListViewController.hpp" -#ifndef BS__1_13_2 -#include "ViewControllers/LobbyMusicSdListViewController.hpp" -#endif -#include "ViewControllers/ConfigViewController.hpp" -#include "QSoundsConfig.hpp" -//#include "audiocliploader.hpp" -#include "AudioClips.hpp" -#include "ObjectInstances.hpp" - - -#include "bsml/shared/BSML-Lite.hpp" - -#include "HMUI/ViewController.hpp" -#include "HMUI/ViewController_AnimationType.hpp" -#include "HMUI/ViewController_AnimationDirection.hpp" -#include "HMUI/FlowCoordinator.hpp" -using namespace QuestSounds; -using namespace QuestSounds::ViewControllers; - -DEFINE_TYPE(QuestSounds, QSoundsFlowCoordinator); - -int CurrentActive; - -void QSoundsFlowCoordinator::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) -{ - CurrentActive = 1; - if (firstActivation) - { - this->SetTitle("QuestSounds MenuMusic", HMUI::ViewController::AnimationDirection::Vertical); - this->showBackButton = true; - - if (!this->QSConfigView) this->QSConfigView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSMenuSoundListView) this->QSMenuSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSHitSoundListView) this->QSHitSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSBadHitSoundListView) this->QSBadHitSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSNoteMissedSoundListView) this->QSNoteMissedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSMenuClickSoundListView) this->QSMenuClickSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSFireworkSoundListView) this->QSFireworkSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSLevelClearedSoundListView) this->QSLevelClearedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSLevelFailedSoundListView) this->QSLevelFailedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSLobbyMusicSoundListView) this->QSLobbyMusicSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - - QSConfigViewController = reinterpret_cast(QSConfigView); - - std::function func = std::bind(&QSoundsFlowCoordinator::SubMenuButtonWasPressed, this, std::placeholders::_1); - QSConfigViewController->set_selectCallback(func); - - QSoundsFlowCoordinator::ProvideInitialViewControllers(QSMenuSoundListView, QSConfigViewController, nullptr, nullptr, nullptr); - } -} - -void QSoundsFlowCoordinator::SubMenuButtonWasPressed(int VCtype) { - if (!VCtype) return; - //FindViewControllers(self); - if (CurrentActive == VCtype) return; - switch (VCtype) - { - case 1: - if (!this->QSMenuSoundListView) this->QSMenuSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSMenuSoundListView) break; - this->SetTitle("Menu Music", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSMenuSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 2: - if (!this->QSHitSoundListView) this->QSHitSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSHitSoundListView) break; - this->SetTitle("Hit Sounds", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSHitSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 3: - if (!this->QSMenuClickSoundListView) this->QSMenuClickSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSMenuClickSoundListView || this->providedMainViewController == this->QSMenuClickSoundListView) break; - this->SetTitle("Menu Clicks", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSMenuClickSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 4: - if (!this->QSBadHitSoundListView) this->QSBadHitSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSBadHitSoundListView || this->providedMainViewController == this->QSBadHitSoundListView) break; - this->SetTitle("Bad Hit Sounds", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSBadHitSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 5: - if (!this->QSNoteMissedSoundListView) this->QSNoteMissedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSNoteMissedSoundListView || this->providedMainViewController == this->QSNoteMissedSoundListView) break; - this->SetTitle("Note Missed Sounds", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSNoteMissedSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 6: - if (!this->QSFireworkSoundListView) this->QSFireworkSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSFireworkSoundListView || this->providedMainViewController == this->QSFireworkSoundListView) break; - this->SetTitle("Firework Sounds", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSFireworkSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 7: - if (!this->QSLevelClearedSoundListView) this->QSLevelClearedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSLevelClearedSoundListView || this->providedMainViewController == this->QSLevelClearedSoundListView) break; - this->SetTitle("Level Cleared Sounds", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSLevelClearedSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; - case 8: - if (!this->QSLevelFailedSoundListView) this->QSLevelFailedSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSLevelFailedSoundListView || this->providedMainViewController == this->QSLevelFailedSoundListView) break; - this->SetTitle("Level Failed Sounds", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSLevelFailedSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; -#ifndef BS__1_13_2 - case 9: - if (!this->QSLobbyMusicSoundListView) this->QSLobbyMusicSoundListView = QuestUI::BeatSaberUI::CreateViewController(); - if (!this->QSLobbyMusicSoundListView || this->providedMainViewController == this->QSLobbyMusicSoundListView) break; - this->SetTitle("LobbyMusic", HMUI::ViewController::AnimationType::In); - this->ReplaceTopViewController(this->QSLobbyMusicSoundListView, this, this, nullptr, HMUI::ViewController::AnimationType::In, HMUI::ViewController::AnimationDirection::Horizontal); - CurrentActive = VCtype; - break; -#endif - default: - getLogger().debug("switch default"); - break; - } -} - - -void QSoundsFlowCoordinator::BackButtonWasPressed(HMUI::ViewController* topView) -{ - QSoundsConfig::SaveConfig(); - //QuestSounds::AudioClips::loadAudioClips(); - this->parentFlowCoordinator->DismissFlowCoordinator(this, HMUI::ViewController::AnimationDirection::Horizontal, nullptr, false); -} \ No newline at end of file diff --git a/src/UI/ViewControllers/BadHitSdListViewController.cpp b/src/UI/ViewControllers/BadHitSdListViewController.cpp deleted file mode 100644 index 7d66b34..0000000 --- a/src/UI/ViewControllers/BadHitSdListViewController.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/BadHitSdListViewController.hpp" -#include "AudioClips.hpp" - -#include -#include -#include - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -#include "bsml/shared/BSML-Lite.hpp" -using namespace QuestSounds; - -DEFINE_TYPE(QuestSounds::ViewControllers, BadHitSdListViewController); - -namespace QuestSounds::ViewControllers { - - BadHitSdListViewController* BadHitListView; - std::list BadHitQSlist = {}; - - void BadHitSelectSound() - { - for (UnityEngine::UI::Button* button : BadHitQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.badHitSound_filepath = QSoundsConfig::BadHitSoundPath + filename; - AudioClips::badHitSoundLoader.filePath = QSoundsConfig::Config.badHitSound_filepath; - if (AudioClips::badHitSoundLoader.audioSource != nullptr) AudioClips::badHitSoundLoader.audioSource->Stop(); - AudioClips::badHitSoundLoader.load(); - // TODO: Proper thread handling - std::thread PlayAudio([&]() { - while (!AudioClips::badHitSoundLoader.loaded && QSoundsConfig::Config.badHitSound_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.badHitSound_Active) { - return; - } - if (AudioClips::badHitSoundLoader.audioSource != nullptr) { - AudioClips::badHitSoundLoader.audioSource->set_volume(0.6f + QSoundsConfig::Config.badHitSound_audioVolumeOffset); - return AudioClips::badHitSoundLoader.audioSource->Play(); - } - }); - PlayAudio.detach(); - getLogger().debug("Selected Sound Path %s", QSoundsConfig::Config.badHitSound_filepath.c_str()); - } - } - } - - void BadHitRefreshList() - { - if (BadHitListView->listtxtgroup && BadHitListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(BadHitListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : BadHitQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - BadHitQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::BadHitSoundPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(BadHitListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, BadHitSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - BadHitQSlist.push_back(button); - } - } - if (BadHitQSlist.size() < 1) - { - BadHitListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(BadHitListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(BadHitListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n"+ QSoundsConfig::BadHitSoundPath +"\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void BadHitSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - BadHitListView = this; - if (firstActivation && addedToHierarchy) - { - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable BadHitSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom BadHitSounds", &QSoundsConfig::Config.badHitSound_Active, this, "Activates or deactivates Custom BadHitSounds"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Bad Hit Sounds", QSoundsConfig::Config.badHitSound_Active, - [&](bool value) { - if (value) BadHitRefreshList(); - QSoundsConfig::Config.badHitSound_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::badHitSoundLoader.audioSource != nullptr) AudioClips::badHitSoundLoader.audioSource->Stop(); - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom Bad Hit Sounds"); - - // AudioVolumeOffset Slider - QuestUI::SliderSetting* volumeSlider = ::QuestUI::BeatSaberUI::CreateSliderSetting(QSconfigcontainer->get_rectTransform(), "Volume Offset", 0.01f, QSoundsConfig::Config.badHitSound_audioVolumeOffset, -1.0f, 1.0f, 0.5f, [](float volume) { - // Checks for safety - QSoundsConfig::Config.badHitSound_audioVolumeOffset = volume; - if (AudioClips::badHitSoundLoader.loaded) { - if (AudioClips::badHitSoundLoader.audioSource->get_isPlaying()) AudioClips::badHitSoundLoader.audioSource->Stop(); - AudioClips::badHitSoundLoader.audioSource->set_volume(1.0f + volume); - AudioClips::badHitSoundLoader.audioSource->Play(); - } - //std::thread PlayAudio([&]() { - // usleep(100); - //}); - }); - QuestUI::BeatSaberUI::AddHoverHint(volumeSlider->get_gameObject(), "Lets you select a Volume Offset that is applied to the sound (Preview volume does not necessarily match volume played in-map)"); - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.badHitSound_Active); - } - BadHitRefreshList(); - } - - void BadHitSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : BadHitQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - BadHitQSlist = {}; - } -} diff --git a/src/UI/ViewControllers/ConfigViewController.cpp b/src/UI/ViewControllers/ConfigViewController.cpp deleted file mode 100644 index 8f863e7..0000000 --- a/src/UI/ViewControllers/ConfigViewController.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "QSoundsConfig.hpp" -#include "QSoundsFlowCoordinator.hpp" -#include "ViewControllers/ConfigViewController.hpp" -#include "main.hpp" - - -#include "questui/shared/CustomTypes/Components/Backgroundable.hpp" -#include "questui/shared/QuestUI.hpp" - -#include "UnityEngine/RectOffset.hpp" - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/Events/UnityAction_1.hpp" -#include "UnityEngine/GameObject.hpp" -#include "HMUI/Touchable.hpp" -#include "HMUI/ScrollView.hpp" -using namespace QuestUI; -using namespace UnityEngine::UI; -using namespace UnityEngine; -using namespace HMUI; -using namespace QSoundsConfig; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, ConfigViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::ConfigViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::ConfigViewController); -#endif - -//ConfigValue SoundValue; -//ConfigValue HitSoundValue; -//ConfigValue HitSoundString = HitSoundValue["filepath"]; - -//void HitSoundToggle(QuestSounds::QSoundsConfigViewController* parent, bool newValue) { -// //HitSoundValue["activated"].SetBool(newValue); -// Config.hitSound_Active = newValue; -// getConfig().Write(); -//} -//void HitSoundVolume(QuestSounds::QSoundsViewController* parent, float newValue) { -// HitSoundValue["Volume"].SetFloat(newValue); -// getConfig().Write(); -//} -namespace QuestSounds::ViewControllers { - - void ConfigViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { - if (firstActivation) { - get_gameObject()->AddComponent(); - - GameObject* mainLayout = GameObject::New_ctor(); - RectTransform* parent = mainLayout->AddComponent(); - parent->SetParent(get_transform(), false); - parent->set_localPosition({38.0f, 3.0f, 0.0f }); - - VerticalLayoutGroup* settingsLayout = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(parent); - RectTransform* settingsLayoutTransform = settingsLayout->GetComponent(); - settingsLayout->get_gameObject()->AddComponent()->ApplyBackground("round-rect-panel"); - settingsLayout->set_spacing(1.2f); - settingsLayout->set_padding(UnityEngine::RectOffset::New_ctor(3, 3, 2, 2)); - - ContentSizeFitter* contentSizeFitter = settingsLayout->get_gameObject()->AddComponent(); - contentSizeFitter->set_horizontalFit(ContentSizeFitter::FitMode::PreferredSize); - contentSizeFitter->set_verticalFit(ContentSizeFitter::FitMode::PreferredSize); - - QuestUI::BeatSaberUI::CreateText(settingsLayoutTransform, "Quest Sounds", false)->set_alignment(TMPro::TextAlignmentOptions::Center); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Menu Music", - [&]() { - getLogger().debug("MenuMusic Button pressed!"); - this->callback(1); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Menu Click Sounds", - [&]() { - getLogger().debug("MenuClickSounds Button pressed!"); - this->callback(3); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Hit Sounds", - [&]() { - getLogger().debug("HitSounds Button pressed!"); - this->callback(2); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Bad Hit Sounds", - [&]() { - getLogger().debug("BadHitSounds Button pressed!"); - this->callback(4); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Note Missed Sounds", - [&]() { - getLogger().debug("NoteMissedSounds Button pressed!"); - this->callback(5); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Firework Sounds", - [&]() { - getLogger().debug("FireworkSounds Button pressed!"); - this->callback(6); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Level Cleared Sounds", - [&]() { - getLogger().debug("LevelClearedSounds Button pressed!"); - this->callback(7); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Level Failed Sounds", - [&]() { - getLogger().debug("LevelFailedSounds Button pressed!"); - this->callback(8); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - BeatSaberUI::CreateUIButton(settingsLayoutTransform, "Lobby Music", - [&]() { - getLogger().debug("LobbyMusic Button pressed!"); - this->callback(9); - })->get_transform()->GetParent()->GetComponent()->set_preferredWidth(50.0f); - } - } - - void ConfigViewController::set_selectCallback(std::function callback) - { - this->callback = callback; - } -} diff --git a/src/UI/ViewControllers/FireworkSdListViewController.cpp b/src/UI/ViewControllers/FireworkSdListViewController.cpp deleted file mode 100644 index 92482b5..0000000 --- a/src/UI/ViewControllers/FireworkSdListViewController.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/FireworkSdListViewController.hpp" -#include "AudioClips.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -//#include "GlobalNamespace/FireworkItemController.hpp" -//#include "GlobalNamespace/RandomObjectPicker_1.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, FireworkSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::FireworkSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::FireworkSdListViewController); -#endif - -namespace QuestSounds::ViewControllers { - - bool FireworkSelectionChanged = false; - //GlobalNamespace::FireworkItemController* FIC; - - FireworkSdListViewController* FireworkListView; - std::list FireworkQSlist = {}; - - void FireworkSelectSound() - { - for (UnityEngine::UI::Button* button : FireworkQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.firework_filepath = QSoundsConfig::FireworkSoundPath + filename; - AudioClips::fireworkSoundLoader.filePath = QSoundsConfig::Config.firework_filepath; - if (AudioClips::fireworkSoundLoader.audioSource != nullptr) AudioClips::fireworkSoundLoader.audioSource->Stop(); - AudioClips::fireworkSoundLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::fireworkSoundLoader.loaded && QSoundsConfig::Config.firework_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.firework_Active) { - return; - } - FireworkSelectionChanged = true; - AudioClips::fireworkSoundLoader.audioSource->set_volume(0.6f); - return AudioClips::fireworkSoundLoader.audioSource->Play(); - }); - PlayAudio.detach(); - getLogger().debug("Selected filename %s, Sound Path %s", filename.c_str(), QSoundsConfig::Config.firework_filepath.c_str()); - } - } - } - - void FireworkRefreshList() - { - if (FireworkListView->listtxtgroup && FireworkListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(FireworkListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : FireworkQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - FireworkQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::FireworkSoundPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(FireworkListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, FireworkSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - FireworkQSlist.push_back(button); - } - } - if (FireworkQSlist.size() < 1) - { - FireworkListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(FireworkListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(FireworkListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n" + QSoundsConfig::FireworkSoundPath + "\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void FireworkSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - FireworkListView = this; - if (firstActivation && addedToHierarchy) - { - FireworkSelectionChanged = false; - //FIC = UnityEngine::GameObject::FindObjectOfType(); - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable FireworkSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom FireworkSounds", &QSoundsConfig::Config.firework_Active, this, "Activates or deactivates Custom FireworkSounds"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Firework Sounds", QSoundsConfig::Config.firework_Active, - [&](bool value) { - if (value) FireworkRefreshList(); - QSoundsConfig::Config.firework_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::fireworkSoundLoader.audioSource != nullptr) AudioClips::fireworkSoundLoader.audioSource->Stop(); - //if (value && AudioClips::fireworkSoundLoader.loaded) { - // AudioClips::fireworkSoundArr = AudioClips::createAudioClipArray(AudioClips::fireworkSoundLoader); - // if (FIC != nullptr) { - // FIC->explosionClips = AudioClips::fireworkSoundArr; - // FIC->randomAudioPicker->objects = AudioClips::fireworkSoundArr; - // } - // else getLogger().warning("Could not set custom FireworkSoundArray"); - //} - //else { - // if (FIC != nullptr && AudioClips::origFireworkSoundArr != nullptr) { - // FIC->explosionClips = AudioClips::origFireworkSoundArr; - // FIC->randomAudioPicker->objects = AudioClips::origFireworkSoundArr; - // } - // else getLogger().warning("Could not set OriginalFireworkSoundArray"); - //} - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom Firework Sounds"); - - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.firework_Active); - } - FireworkRefreshList(); - } - - void FireworkSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : FireworkQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - FireworkQSlist = {}; - //if (FireworkSelectionChanged && QSoundsConfig::Config.firework_Active && AudioClips::fireworkSoundLoader.loaded) { - // AudioClips::fireworkSoundArr = AudioClips::createAudioClipArray(AudioClips::fireworkSoundLoader); - // if (FIC != nullptr) { - // FIC->explosionClips = AudioClips::fireworkSoundArr; - // FIC->randomAudioPicker->objects = AudioClips::fireworkSoundArr; - // } - // else getLogger().warning("Could not set custom FireworkSoundArray"); - //} - //else { - // if (FIC != nullptr && AudioClips::origFireworkSoundArr != nullptr) { - // FIC->explosionClips = AudioClips::origFireworkSoundArr; - // FIC->randomAudioPicker->objects = AudioClips::origFireworkSoundArr; - // } - // else getLogger().warning("Could not set OriginalFireworkSoundArray"); - //} - } -} \ No newline at end of file diff --git a/src/UI/ViewControllers/HitSdListViewController.cpp b/src/UI/ViewControllers/HitSdListViewController.cpp deleted file mode 100644 index 69f7ef0..0000000 --- a/src/UI/ViewControllers/HitSdListViewController.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/HitSdListViewController.hpp" -#include "AudioClips.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/AudioSource.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, HitSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::HitSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::HitSdListViewController); -#endif -namespace QuestSounds::ViewControllers { - - HitSdListViewController* HitListView; - std::list HitQSlist = {}; - - void HitSelectSound() - { - for (UnityEngine::UI::Button* button : HitQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.hitSound_filepath = QSoundsConfig::HitSoundPath + filename; - AudioClips::hitSoundLoader.filePath = QSoundsConfig::Config.hitSound_filepath; - if (AudioClips::hitSoundLoader.audioSource != nullptr) AudioClips::hitSoundLoader.audioSource->Stop(); - AudioClips::hitSoundLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::hitSoundLoader.loaded && QSoundsConfig::Config.hitSound_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.hitSound_Active) { - return; - } - if (AudioClips::hitSoundLoader.audioSource != nullptr) { - AudioClips::hitSoundLoader.audioSource->set_volume(0.6f + QSoundsConfig::Config.hitSound_audioVolumeOffset); - return AudioClips::hitSoundLoader.audioSource->Play(); - } - }); - PlayAudio.detach(); - getLogger().debug("Selected filename %s, Sound Path %s", filename.c_str(), QSoundsConfig::Config.hitSound_filepath.c_str()); - } - } - } - - void HitRefreshList() - { - if (HitListView->listtxtgroup && HitListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(HitListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : HitQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - HitQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::HitSoundPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(HitListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, HitSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - HitQSlist.push_back(button); - } - } - if (HitQSlist.size() < 1) - { - HitListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(HitListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(HitListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n" + QSoundsConfig::HitSoundPath + "\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void HitSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - HitListView = this; - if (firstActivation && addedToHierarchy) - { - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable HitSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom HitSounds", &QSoundsConfig::Config.hitSound_Active, this, "Activates or deactivates Custom HitSounds"); - auto HSToggle = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Hit Sounds", QSoundsConfig::Config.hitSound_Active, - [&](bool value) { - if (value) HitRefreshList(); - QSoundsConfig::Config.hitSound_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::hitSoundLoader.audioSource != nullptr) AudioClips::hitSoundLoader.audioSource->Stop(); - }); - QuestUI::BeatSaberUI::AddHoverHint(HSToggle->get_gameObject(), "Activates or deactivates Custom Hit Sounds"); - - QuestUI::SliderSetting* volumeSlider = ::QuestUI::BeatSaberUI::CreateSliderSetting(QSconfigcontainer->get_rectTransform(), "Volume Offset", 0.01f, QSoundsConfig::Config.hitSound_audioVolumeOffset, -1.0f, 1.0f, 0.5f, [](float volume) { - // Checks for safety - QSoundsConfig::Config.hitSound_audioVolumeOffset = volume; - if (AudioClips::hitSoundLoader.loaded) { - if (AudioClips::hitSoundLoader.audioSource->get_isPlaying()) AudioClips::hitSoundLoader.audioSource->Stop(); - AudioClips::hitSoundLoader.audioSource->set_volume(0.6f + volume); - AudioClips::hitSoundLoader.audioSource->Play(); - } - }); - QuestUI::BeatSaberUI::AddHoverHint(volumeSlider->get_gameObject(), "Lets you select a Volume Offset that is applied to the sound (Preview volume does not necessarily match volume played in-map)"); - - auto HSOffSet = ::QuestUI::BeatSaberUI::CreateIncrementSetting(QSconfigcontainer->get_rectTransform(), "Hit Sound OffSet (ms)", 3, 0.005f, QSoundsConfig::Config.hitSound_beatOffSet, 0.0f, 0.25f, - [&](float value) { - QSoundsConfig::Config.hitSound_beatOffSet = value; - }); - QuestUI::BeatSaberUI::AddHoverHint(HSOffSet->get_gameObject(), "Sets a custom HitSound beatOffSet (default: 0.185 ms)"); - - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.hitSound_Active); - } - HitRefreshList(); - } - - void HitSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : HitQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - HitQSlist = {}; - if (AudioClips::hitSoundLoader.audioSource != nullptr) AudioClips::hitSoundLoader.audioSource->Stop(); - } -} \ No newline at end of file diff --git a/src/UI/ViewControllers/LevelClearedSdListViewController.cpp b/src/UI/ViewControllers/LevelClearedSdListViewController.cpp deleted file mode 100644 index 04cfc70..0000000 --- a/src/UI/ViewControllers/LevelClearedSdListViewController.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/LevelClearedSdListViewController.hpp" -#include "AudioClips.hpp" -#include "ObjectInstances.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, LevelClearedSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::LevelClearedSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::QSoundsLevelClearedSdListViewController); -#endif - -namespace QuestSounds::ViewControllers { - - LevelClearedSdListViewController* LevelClearedListView; - std::list LevelClearedQSlist = {}; - - void LevelClearedSelectSound() - { - for (UnityEngine::UI::Button* button : LevelClearedQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.levelCleared_filepath = QSoundsConfig::LevelClearedPath + filename; - QuestSounds::AudioClips::levelClearedLoader.filePath = QSoundsConfig::Config.levelCleared_filepath; - if (AudioClips::levelClearedLoader.audioSource != nullptr) AudioClips::levelClearedLoader.audioSource->Stop(); - AudioClips::levelClearedLoader.loaded = false; - AudioClips::levelClearedLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::levelClearedLoader.loaded && QSoundsConfig::Config.levelCleared_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.levelCleared_Active) { - return; - } - AudioClips::levelClearedLoader.audioSource->Stop(); // TODO: Figure out why this Stop won't work - AudioClips::levelClearedLoader.audioSource->set_volume(0.6f); - return AudioClips::levelClearedLoader.audioSource->Play(); - }); - PlayAudio.detach(); - getLogger().debug("Selected filename %s, Sound Path %s", filename.c_str(), QSoundsConfig::Config.levelCleared_filepath.c_str()); - } - } - } - - void LevelClearedRefreshList() - { - if (LevelClearedListView->listtxtgroup && LevelClearedListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(LevelClearedListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : LevelClearedQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - LevelClearedQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::LevelClearedPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(LevelClearedListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, LevelClearedSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - LevelClearedQSlist.push_back(button); - } - } - if (LevelClearedQSlist.size() < 1) - { - LevelClearedListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(LevelClearedListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(LevelClearedListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n" + QSoundsConfig::LevelClearedPath + "\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void LevelClearedSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - LevelClearedListView = this; - if (firstActivation && addedToHierarchy) - { - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable LevelClearedSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom LevelClearedSounds", &QSoundsConfig::Config.levelCleared_Active, this, "Activates or deactivates Custom LevelClearedSounds"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom LevelCleared Sounds", QSoundsConfig::Config.levelCleared_Active, - [&](bool value) { - if (value) LevelClearedRefreshList(); - QSoundsConfig::Config.levelCleared_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::levelClearedLoader.audioSource != nullptr) AudioClips::levelClearedLoader.audioSource->Stop(); - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom LevelCleared Sounds"); - - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.levelCleared_Active); - } - LevelClearedRefreshList(); - } - - void LevelClearedSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : LevelClearedQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - LevelClearedQSlist = {}; - if (AudioClips::levelClearedLoader.audioSource != nullptr) AudioClips::levelClearedLoader.audioSource->Stop(); - - } -} \ No newline at end of file diff --git a/src/UI/ViewControllers/LevelFailedSdListViewController.cpp b/src/UI/ViewControllers/LevelFailedSdListViewController.cpp deleted file mode 100644 index 1381cb3..0000000 --- a/src/UI/ViewControllers/LevelFailedSdListViewController.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/LevelFailedSdListViewController.hpp" -#include "AudioClips.hpp" -#include "ObjectInstances.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, LevelFailedSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::LevelFailedSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::LevelFailedSdListViewController); -#endif - -namespace QuestSounds::ViewControllers { - - LevelFailedSdListViewController* LevelFailedListView; - std::list LevelFailedQSlist = {}; - - void SelectSound() - { - for (UnityEngine::UI::Button* button : LevelFailedQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = static_cast(button->GetComponentInChildren()->get_text()); - QSoundsConfig::Config.levelFailed_filepath = QSoundsConfig::LevelFailedPath + filename; - QuestSounds::AudioClips::levelFailedLoader.filePath = QSoundsConfig::Config.levelFailed_filepath; - if (AudioClips::levelFailedLoader.audioSource != nullptr) AudioClips::levelFailedLoader.audioSource->Stop(); - AudioClips::levelFailedLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::levelFailedLoader.loaded && QSoundsConfig::Config.levelFailed_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.levelFailed_Active) { - return; - } - AudioClips::levelFailedLoader.audioSource->Stop(); - float defaultVolume = QuestSounds::ObjectInstances::SPP ? QuestSounds::ObjectInstances::SPP->volume * QuestSounds::ObjectInstances::SPP->ambientVolumeScale : 0.6f; - AudioClips::levelFailedLoader.audioSource->set_volume(defaultVolume + QSoundsConfig::Config.levelFailed_audioVolumeOffset); - return AudioClips::levelFailedLoader.audioSource->Play(); - }); - PlayAudio.detach(); - getLogger().debug("Selected filename %s, Sound Path %s", filename.c_str(), QSoundsConfig::Config.levelFailed_filepath.c_str()); - } - } - } - - void LevelFailedRefreshList() - { - if (LevelFailedListView->listtxtgroup && LevelFailedListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(LevelFailedListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : LevelFailedQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - LevelFailedQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::LevelFailedPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(LevelFailedListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, SelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - LevelFailedQSlist.push_back(button); - } - } - if (LevelFailedQSlist.size() < 1) - { - LevelFailedListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(LevelFailedListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(LevelFailedListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n"+ QSoundsConfig::LevelFailedPath +"\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void LevelFailedSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - LevelFailedListView = this; - if (firstActivation && addedToHierarchy) - { - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable LevelFailedSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom LevelFailedSounds", &QSoundsConfig::Config.levelFailed_Active, this, "Activates or deactivates Custom LevelFailedSounds"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom LevelFailed Sounds", QSoundsConfig::Config.levelFailed_Active, - [&](bool value) { - if (value) LevelFailedRefreshList(); - QSoundsConfig::Config.levelFailed_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::levelFailedLoader.audioSource != nullptr) AudioClips::levelFailedLoader.audioSource->Stop(); - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom LevelFailed Sounds"); - - QuestUI::SliderSetting* volumeSlider = ::QuestUI::BeatSaberUI::CreateSliderSetting(QSconfigcontainer->get_rectTransform(), "Volume Offset", 0.01f, QSoundsConfig::Config.levelFailed_audioVolumeOffset, -1.0f, 1.0f, 0.5f, [](float volume) { - // Checks for safety - QSoundsConfig::Config.levelFailed_audioVolumeOffset = volume; - if (AudioClips::levelFailedLoader.loaded) { - if (AudioClips::levelFailedLoader.audioSource->get_isPlaying()) AudioClips::levelFailedLoader.audioSource->Stop(); - float defaultVolume = QuestSounds::ObjectInstances::SPP ? QuestSounds::ObjectInstances::SPP->volume * QuestSounds::ObjectInstances::SPP->ambientVolumeScale : 0.6f; - AudioClips::levelFailedLoader.audioSource->set_volume(defaultVolume + volume); - AudioClips::levelFailedLoader.audioSource->Play(); - } - }); - QuestUI::BeatSaberUI::AddHoverHint(volumeSlider->get_gameObject(), "Lets you select a Volume Offset that is applied to the sound"); - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.levelFailed_Active); - } - LevelFailedRefreshList(); - } - - void LevelFailedSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : LevelFailedQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - LevelFailedQSlist = {}; - if (AudioClips::levelFailedLoader.audioSource != nullptr) AudioClips::levelFailedLoader.audioSource->Stop(); - - } - -} \ No newline at end of file diff --git a/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp b/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp deleted file mode 100644 index e049a8b..0000000 --- a/src/UI/ViewControllers/LobbyMusicSdListViewController.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/LobbyMusicSdListViewController.hpp" -#include "AudioClips.hpp" -#include "ObjectInstances.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -#include "GlobalNamespace/SongPreviewPlayer.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, LobbyMusicSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::LobbyMusicSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::LobbyMusicSdListViewController); -#endif - -namespace QuestSounds::ViewControllers { - - LobbyMusicSdListViewController* LobbyMusicListView; - std::list LobbyMusicQSlist = {}; - - void LobbyMusicSelectSound() - { - for (UnityEngine::UI::Button* button : LobbyMusicQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.lobbyAmbience_filepath = QSoundsConfig::LobbyMusicPath + filename; - QuestSounds::AudioClips::lobbyAmbienceLoader.filePath = QSoundsConfig::Config.lobbyAmbience_filepath; - if (AudioClips::lobbyAmbienceLoader.audioSource != nullptr) AudioClips::lobbyAmbienceLoader.audioSource->Stop(); - AudioClips::lobbyAmbienceLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::lobbyAmbienceLoader.loaded && QSoundsConfig::Config.lobbyAmbience_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.lobbyAmbience_Active) { - return; - } - AudioClips::lobbyAmbienceLoader.audioSource->set_volume(0.6f); - return AudioClips::lobbyAmbienceLoader.audioSource->Play(); - }); - PlayAudio.detach(); - getLogger().debug("Selected filename %s, Sound Path %s", filename.c_str(), QSoundsConfig::Config.lobbyAmbience_filepath.c_str()); - } - } - } - - void LobbyMusicRefreshList() - { - if (LobbyMusicListView->listtxtgroup && LobbyMusicListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(LobbyMusicListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : LobbyMusicQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - LobbyMusicQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::LobbyMusicPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(LobbyMusicListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, LobbyMusicSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - LobbyMusicQSlist.push_back(button); - } - } - if (LobbyMusicQSlist.size() < 1) - { - LobbyMusicListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(LobbyMusicListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(LobbyMusicListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n" + QSoundsConfig::LobbyMusicPath + "\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void LobbyMusicSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - LobbyMusicListView = this; - if (firstActivation && addedToHierarchy) - { - //QuestSounds::ObjectInstances::SPP = UnityEngine::GameObject::FindObjectOfType(); - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - QuestUI::BeatSaberUI::CreateText(QSconfigcontainer->get_rectTransform(), "Menu Music will be Paused here", false); - - // Enable or Disable LobbyMusic - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom Lobby Music", &QSoundsConfig::Config.lobbyAmbience_Active, this, "Activates or deactivates Custom Lobby Music"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Lobby Music", QSoundsConfig::Config.lobbyAmbience_Active, - [&](bool value) { - if (value) LobbyMusicRefreshList(); - QSoundsConfig::Config.lobbyAmbience_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::lobbyAmbienceLoader.audioSource != nullptr) AudioClips::lobbyAmbienceLoader.audioSource->Stop(); - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom Lobby Music"); - - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.lobbyAmbience_Active); - } - QuestSounds::ObjectInstances::SPP->PauseCurrentChannel(); - LobbyMusicRefreshList(); - } - - void LobbyMusicSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - QuestSounds::ObjectInstances::SPP->UnPauseCurrentChannel(); - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : LobbyMusicQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - LobbyMusicQSlist = {}; - if (AudioClips::lobbyAmbienceLoader.audioSource != nullptr) AudioClips::lobbyAmbienceLoader.audioSource->Stop(); - } -} \ No newline at end of file diff --git a/src/UI/ViewControllers/MenuClickSdListViewController.cpp b/src/UI/ViewControllers/MenuClickSdListViewController.cpp deleted file mode 100644 index 89f6a3a..0000000 --- a/src/UI/ViewControllers/MenuClickSdListViewController.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/MenuClickSdListViewController.hpp" -#include "AudioClips.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" -using namespace QuestSounds; - -#include "GlobalNamespace/BasicUIAudioManager.hpp" -#include "GlobalNamespace/RandomObjectPicker_1.hpp" - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, MenuClickSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::MenuClickSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::MenuClickSdListViewController); -#endif - -namespace QuestSounds::ViewControllers { - - GlobalNamespace::BasicUIAudioManager* BUIAM; - - MenuClickSdListViewController* MenuClickListView; - std::list MenuClickQSlist = {}; - - void MenuClickSelectSound() - { - for (UnityEngine::UI::Button* button : MenuClickQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.menuClick_filepath = QSoundsConfig::MenuClickPath + filename; - AudioClips::menuClickLoader.filePath = QSoundsConfig::Config.menuClick_filepath; - if (AudioClips::menuClickLoader.audioSource != nullptr) AudioClips::menuClickLoader.audioSource->Stop(); - AudioClips::menuClickLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::menuClickLoader.loaded && QSoundsConfig::Config.menuClick_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.menuClick_Active) { - return; - } - AudioClips::menuClickLoader.audioSource->set_volume(0.6f); - return AudioClips::menuClickLoader.audioSource->Play(); - }); - PlayAudio.detach(); - getLogger().debug("Selected filename %s, Sound Path %s", filename.c_str(), QSoundsConfig::Config.menuClick_filepath.c_str()); - } - } - } - - void MenuClickRefreshList() - { - if (MenuClickListView->listtxtgroup && MenuClickListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(MenuClickListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : MenuClickQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - MenuClickQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::MenuClickPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(MenuClickListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, MenuClickSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - MenuClickQSlist.push_back(button); - } - } - if (MenuClickQSlist.size() < 1) - { - MenuClickListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(MenuClickListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(MenuClickListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n" + QSoundsConfig::MenuClickPath + "\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void MenuClickSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - MenuClickListView = this; - if (firstActivation && addedToHierarchy) - { - BUIAM = UnityEngine::GameObject::FindObjectOfType(); - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable MenuClickSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom MenuClickSounds", &QSoundsConfig::Config.menuClick_Active, SDlistscroll, "Activates or deactivates Custom MenuClickSounds"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Menu ClickSounds", QSoundsConfig::Config.menuClick_Active, - [&](bool value) { - if (value) MenuClickRefreshList(); - QSoundsConfig::Config.menuClick_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::menuClickLoader.audioSource) AudioClips::menuClickLoader.audioSource->Stop(); - if (value && AudioClips::menuClickLoader.loaded) { - AudioClips::menuClickArr = AudioClips::createAudioClipArray(AudioClips::menuClickLoader); - BUIAM->randomSoundPicker->objects = AudioClips::menuClickArr; - } - else { - AudioClips::origMenuClickArr = AudioClips::createAudioClipArray(AudioClips::menuClickLoader, true); - BUIAM->randomSoundPicker->objects = AudioClips::origMenuClickArr; - } - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom Menu ClickSounds"); - - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.menuClick_Active); - } - MenuClickRefreshList(); - } - - void MenuClickSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : MenuClickQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - MenuClickQSlist = {}; - if (QSoundsConfig::Config.menuClick_Active && AudioClips::menuClickLoader.loaded) { - AudioClips::menuClickArr = AudioClips::createAudioClipArray(AudioClips::menuClickLoader); - BUIAM->randomSoundPicker->objects = AudioClips::menuClickArr; - } - else { - AudioClips::origMenuClickArr = AudioClips::createAudioClipArray(AudioClips::menuClickLoader, true); - BUIAM->randomSoundPicker->objects = AudioClips::origMenuClickArr; - } - } -} \ No newline at end of file diff --git a/src/UI/ViewControllers/MenuSdListViewController.cpp b/src/UI/ViewControllers/MenuSdListViewController.cpp deleted file mode 100644 index f98bb6b..0000000 --- a/src/UI/ViewControllers/MenuSdListViewController.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/MenuSdListViewController.hpp" -#include "AudioClips.hpp" - -#include -#include -#include -#include -#include - - - -#include "questui/shared/CustomTypes/Components/MainThreadScheduler.hpp" - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -#include "GlobalNamespace/SongPreviewPlayer.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, MenuSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::MenuSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::MenuSdListViewController); -#endif - -namespace QuestSounds::ObjectInstances { - GlobalNamespace::SongPreviewPlayer* SPP; -} -using namespace QuestSounds::ObjectInstances; - -namespace QuestSounds::ViewControllers { - - MenuSdListViewController* MenuListView; - std::list MenuQSlist = {}; - - void MenuSelectSound() - { - for (UnityEngine::UI::Button* button : MenuQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = button->GetComponentInChildren()->get_text(); - QSoundsConfig::Config.menuMusic_filepath = QSoundsConfig::MenuMusicPath + filename; - QuestSounds::AudioClips::menuMusicLoader.filePath = QSoundsConfig::Config.menuMusic_filepath; - AudioClips::menuMusicLoader.loaded = false; - AudioClips::menuMusicLoader.load(); - std::thread replaceAudio([&]() { - while (!AudioClips::menuMusicLoader.loaded && QSoundsConfig::Config.menuMusic_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.menuMusic_Active) { - return; - } - if (AudioClips::menuMusicLoader.audioSource != nullptr) { - return SPP->CrossfadeToNewDefault(AudioClips::menuMusicLoader.getClip()); - } - }); - replaceAudio.detach(); - getLogger().debug("Selected Sound Path %s", QSoundsConfig::Config.menuMusic_filepath.c_str()); - - } - } - } - - void MenuRefreshList() - { - if (MenuListView->listtxtgroup && MenuListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(MenuListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : MenuQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - MenuQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::MenuMusicPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(MenuListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, MenuSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - MenuQSlist.push_back(button); - } - } - if (MenuQSlist.size() < 1) - { - MenuListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(MenuListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(MenuListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n"+ QSoundsConfig::MenuMusicPath +"\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void MenuSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - MenuListView = this; - if (firstActivation && addedToHierarchy) - { - SPP = UnityEngine::GameObject::FindObjectOfType(); - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - - //Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable Custom Menu Music - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom Menu Music", &QSoundsConfig::Config.menuMusic_Active, SDlistscroll, "Activates or deactivates Custom Menu Music"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Menu Music", QSoundsConfig::Config.menuMusic_Active, - [&](bool value) { - if (value) MenuRefreshList(); - QSoundsConfig::Config.menuMusic_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::menuMusicLoader.loaded && value) { - SPP->CrossfadeToNewDefault(AudioClips::menuMusicLoader.getClip()); - } - else { - if (AudioClips::menuMusicLoader.OriginalAudioSource) SPP->CrossfadeToNewDefault(AudioClips::menuMusicLoader.get_OriginalClip()); - } - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom Menu Music"); - - - //if (QSoundsConfig::LegacyConfig) QuestUI::BeatSaberUI::CreateText(settingsLayoutTransform, "Legacy Config Detected,\nplease move your files into the new folders,\nfor selection in-game", false); - if (QSoundsConfig::LegacyConfig) { - modal = QuestUI::BeatSaberUI::CreateModal(get_transform(), {40, 35}, nullptr); - - auto wrapper = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(modal->get_transform()); - auto container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(wrapper->get_transform()); - container->set_childAlignment(UnityEngine::TextAnchor::MiddleCenter); - - QuestUI::BeatSaberUI::CreateText(container->get_transform(), "Legacy Config Detected\nplease move your files\ninto the new folders,\nfor selection in-game\n\n", false)->set_alignment(TMPro::TextAlignmentOptions::Center); - - auto horizon = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(container->get_transform()); - - QuestUI::BeatSaberUI::CreateUIButton(horizon->get_transform(), "Close", UnityEngine::Vector2(0, -3), { 10, 7 }, [this]() -> void { - modal->Hide(true, nullptr); - }); - - std::thread showModal([&]() { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - QuestUI::MainThreadScheduler::Schedule([this]() { - modal->Show(true, true, nullptr); - }); - }); - showModal.detach(); - } - - - //QSconfigcontainer->set_childForceExpandHeight(false); - //QSconfigcontainer->set_childControlHeight(true); - - //UnityEngine::UI::Button::Button(); - - //bool enabled_initval = getConfig().config["enabled"].GetBool(); - //this->masterEnabled = QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Enable Quest Sounds", enabled_initval, UnityEngine::Vector2(0, 0), OnChangeEnabled); - - // Sound List (recursively adds buttons as MenuListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - //this->SDlistscroll->get_gameObject()->SetActive(enabled_initval); - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.menuMusic_Active); - } - MenuRefreshList(); - } - - void MenuSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - for (UnityEngine::UI::Button* button : MenuQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - MenuQSlist = {}; - //if (AudioClips::menuMusicLoader.loaded && QSoundsConfig::Config.menuMusic_Active) { - // getLogger().debug("Returning custom audioClip"); - // SPP->CrossfadeToNewDefault(AudioClips::menuMusicLoader.getClip()); - //} - //else { - // getLogger().debug("Returning default audioClip"); - // SPP->CrossfadeToNewDefault(AudioClips::menuMusicLoader.get_OriginalClip()); - //} - } -} diff --git a/src/UI/ViewControllers/NoteMissedSdListViewController.cpp b/src/UI/ViewControllers/NoteMissedSdListViewController.cpp deleted file mode 100644 index 606844c..0000000 --- a/src/UI/ViewControllers/NoteMissedSdListViewController.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include "main.hpp" -#include "QSoundsConfig.hpp" -#include "ViewControllers/NoteMissedSdListViewController.hpp" -#include "AudioClips.hpp" - -#include -#include -#include - - - - -#include "UnityEngine/Object.hpp" -#include "UnityEngine/GameObject.hpp" -#include "UnityEngine/Transform.hpp" -#include "UnityEngine/RectTransform.hpp" -#include "UnityEngine/UI/Button.hpp" -#include "UnityEngine/UI/LayoutElement.hpp" -#include "UnityEngine/UI/VerticalLayoutGroup.hpp" -#include "UnityEngine/UI/HorizontalLayoutGroup.hpp" -#include "UnityEngine/Events/UnityAction.hpp" -#include "TMPro/TextMeshProUGUI.hpp" - -using namespace QuestSounds; - -#ifndef REGISTER_FUNCTION -DEFINE_TYPE(QuestSounds::ViewControllers, NoteMissedSdListViewController); -#elif defined(DEFINE_TYPE) -DEFINE_TYPE(QuestSounds::ViewControllers::NoteMissedSdListViewController); -#elif defined(DEFINE_CLASS) -DEFINE_CLASS(QuestSounds::ViewControllers::NoteMissedSdListViewController); -#endif - -namespace QuestSounds::ViewControllers { - - NoteMissedSdListViewController* NoteMissedListView; - std::list NoteMissedQSlist = {}; - - void NoteMissedSelectSound() - { - for (UnityEngine::UI::Button* button : NoteMissedQSlist) - { - if (button->get_hasSelection()) - { - std::string filename = static_cast(button->GetComponentInChildren()->get_text()); - QSoundsConfig::Config.noteMissedSound_filepath = QSoundsConfig::NoteMissedSoundPath + filename; - AudioClips::noteMissedSoundLoader.filePath = QSoundsConfig::Config.noteMissedSound_filepath; - if (AudioClips::noteMissedSoundLoader.audioSource != nullptr) AudioClips::noteMissedSoundLoader.audioSource->Stop(); - AudioClips::noteMissedSoundLoader.load(); - std::thread PlayAudio([&]() { - while (!AudioClips::noteMissedSoundLoader.loaded && QSoundsConfig::Config.noteMissedSound_Active) { - usleep(100); - } - if (!QSoundsConfig::Config.noteMissedSound_Active) { - return; - } - if (AudioClips::noteMissedSoundLoader.audioSource != nullptr) { - AudioClips::noteMissedSoundLoader.audioSource->set_volume(0.5f + QSoundsConfig::Config.noteMissedSound_audioVolumeOffset); - return AudioClips::noteMissedSoundLoader.audioSource->Play(); - } - }); - PlayAudio.detach(); - getLogger().debug("Selected Sound Path %s", QSoundsConfig::Config.badHitSound_filepath.c_str()); - } - } - } - - void NoteMissedRefreshList() - { - if (NoteMissedListView->listtxtgroup && NoteMissedListView->listtxtgroup->m_CachedPtr.m_value) UnityEngine::GameObject::Destroy(NoteMissedListView->listtxtgroup->get_gameObject()); - for (UnityEngine::UI::Button* button : NoteMissedQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - NoteMissedQSlist = {}; - DIR* sounddir = opendir(QSoundsConfig::NoteMissedSoundPath.c_str()); - dirent* fileent; - while ((fileent = readdir(sounddir)) != NULL) - { - std::string filename = fileent->d_name; - for (char& ch : filename) ch = tolower(ch); - - if (std::regex_search(filename, std::regex(".ogg|.mp3|.mp2|.wav|.aiff|.aif"))) - { - UnityEngine::UI::HorizontalLayoutGroup* rowgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(NoteMissedListView->SDlistscroll->get_transform()); - UnityEngine::UI::Button* button = QuestUI::BeatSaberUI::CreateUIButton(rowgroup->get_rectTransform(), fileent->d_name, NoteMissedSelectSound); - button->get_gameObject()->GetComponentInChildren()->set_fontStyle(2); - NoteMissedQSlist.push_back(button); - } - } - if (NoteMissedQSlist.size() < 1) - { - NoteMissedListView->listtxtgroup = QuestUI::BeatSaberUI::CreateHorizontalLayoutGroup(NoteMissedListView->SDlistscroll->get_transform()); - QuestUI::BeatSaberUI::CreateText(NoteMissedListView->listtxtgroup->get_rectTransform(), "No sound files were found!\nPlease add a sound file into\n"+ QSoundsConfig::NoteMissedSoundPath +"\nto continue.", false)->set_enableWordWrapping(true); - } - (void)closedir(sounddir); - } - - void NoteMissedSdListViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) - { - NoteMissedListView = this; - if (firstActivation && addedToHierarchy) - { - UnityEngine::UI::VerticalLayoutGroup* container = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(get_rectTransform()); - container->set_spacing(0.4f); - container->GetComponent()->set_minWidth(125.0); - - // Bool settings - this->QSconfigcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(container->get_rectTransform()); - QSconfigcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - QSconfigcontainer->set_childForceExpandHeight(false); - QSconfigcontainer->set_childControlHeight(true); - - // Enable or Disable BadHitSounds - //QSoundsConfig::QSAddConfigValueToggle(QSconfigcontainer->get_rectTransform(), "Custom BadHitSounds", &QSoundsConfig::Config.noteMissedSound_Active, this, "Activates or deactivates Custom BadHitSounds"); - auto object = ::QuestUI::BeatSaberUI::CreateToggle(QSconfigcontainer->get_rectTransform(), "Custom Note Missed Sounds", QSoundsConfig::Config.noteMissedSound_Active, - [&](bool value) { - if (value) NoteMissedRefreshList(); - QSoundsConfig::Config.noteMissedSound_Active = value; - this->SDlistscroll->get_gameObject()->SetActive(value); - if (AudioClips::noteMissedSoundLoader.audioSource != nullptr) AudioClips::noteMissedSoundLoader.audioSource->Stop(); - }); - ::QuestUI::BeatSaberUI::AddHoverHint(object->get_gameObject(), "Activates or deactivates Custom Note Missed Sounds"); - - // AudioVolumeOffset Slider - QuestUI::SliderSetting* volumeSlider = ::QuestUI::BeatSaberUI::CreateSliderSetting(QSconfigcontainer->get_rectTransform(), "Volume Offset", 0.01f, QSoundsConfig::Config.noteMissedSound_audioVolumeOffset, -1.0f, 1.0f, 0.5f, [](float volume) { - // Checks for safety - QSoundsConfig::Config.noteMissedSound_audioVolumeOffset = volume; - if (AudioClips::noteMissedSoundLoader.loaded) { - if (AudioClips::noteMissedSoundLoader.audioSource->get_isPlaying()) AudioClips::noteMissedSoundLoader.audioSource->Stop(); - AudioClips::noteMissedSoundLoader.audioSource->set_volume(0.5f + volume); - AudioClips::noteMissedSoundLoader.audioSource->Play(); - } - //std::thread PlayAudio([&]() { - // usleep(100); - //}); - }); - QuestUI::BeatSaberUI::AddHoverHint(volumeSlider->get_gameObject(), "Lets you select a Volume Offset that is applied to the sound"); - - // Sound List (recursively adds buttons as ListView isn't an easy type to deal with) - this->SDlistscroll = QuestUI::BeatSaberUI::CreateScrollView(container->get_rectTransform()); - SDlistscroll->GetComponent()->Get()->set_minHeight(56.0); - auto* SDlistcontainer = QuestUI::BeatSaberUI::CreateVerticalLayoutGroup(SDlistscroll->get_transform()); - SDlistcontainer->set_childAlignment(UnityEngine::TextAnchor::UpperCenter); - SDlistcontainer->set_childForceExpandHeight(false); - SDlistcontainer->set_childControlHeight(true); - - this->SDlistscroll->get_gameObject()->SetActive(QSoundsConfig::Config.noteMissedSound_Active); - } - NoteMissedRefreshList(); - } - - void NoteMissedSdListViewController::DidDeactivate(bool removedFromHierarchy, bool systemScreenDisabling) - { - //QSoundsConfig::SaveConfig(); - for (UnityEngine::UI::Button* button : NoteMissedQSlist) UnityEngine::Object::Destroy(button->get_transform()->get_parent()->get_gameObject()); - NoteMissedQSlist = {}; - } -} From df3d881e0e3b6653d9b249ba75fb525ab6f3e132 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:17:55 +0200 Subject: [PATCH 14/55] build script temp disable -Dev suffix --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 776d220..456d809 100644 --- a/build.ps1 +++ b/build.ps1 @@ -26,7 +26,7 @@ if ($args.Count -eq 0 -or $actions -ne $true) { $ModID = $qpmJson.config.info.id $VERSION = $qpmJson.config.info.version if ($release -ne $true) { - $VERSION += "-Dev" + # $VERSION += "-Dev" } elseif ($release -eq $true -and $VERSION.Contains("-Dev")) { $VERSION.Replace("-Dev", "") } From 75f55573653c9b1d3ebadac6a7b937d10b3323ea Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:46:43 +0200 Subject: [PATCH 15/55] Remove old QSoundsConfig --- include/QSoundsConfig.hpp | 72 ---------- src/QSoundsConfig.cpp | 283 -------------------------------------- 2 files changed, 355 deletions(-) delete mode 100644 include/QSoundsConfig.hpp delete mode 100644 src/QSoundsConfig.cpp diff --git a/include/QSoundsConfig.hpp b/include/QSoundsConfig.hpp deleted file mode 100644 index 516d688..0000000 --- a/include/QSoundsConfig.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once -#include "main.hpp" -#define RAPIDJSON_HAS_STDSTRING 1 -#define SOUND_PATH_FORMAT "/sdcard/ModData/%s/Mods/QuestSounds/" -#define CONFIG_VERSION "SoundsConfig_v3" -#define CONFIG_VERSION_PRE_1_20 "SoundsConfig_v2" -#define CONFIG_VERSION_PRE_R "SoundsConfig_v1" -#define CONFIG_VERSION_LEGACY "Sounds" -#include "UnityEngine/UI/Toggle.hpp" - - -namespace QSoundsConfig { - static std::string soundPath = string_format(SOUND_PATH_FORMAT, Modloader::getApplicationId().c_str());; - - static std::string MenuMusicPath = soundPath + "MenuMusic/"; - static std::string HitSoundPath = soundPath + "HitSounds/"; - static std::string BadHitSoundPath = soundPath + "BadHitSounds/"; - static std::string NoteMissedSoundPath = soundPath + "NoteMissedSounds/"; - static std::string MenuClickPath = soundPath + "MenuClicks/"; - static std::string FireworkSoundPath = soundPath + "Fireworks/"; - static std::string LevelClearedPath = soundPath + "LevelCleared/"; - static std::string LevelFailedPath = soundPath + "LevelFailed/"; - static std::string LobbyMusicPath = soundPath + "LobbyMusic/"; - - extern bool LegacyConfig; - - //static const ConfigValue soundsConfigParent = getConfig().config[CONFIG_VERSION].GetObject(); - //Config stuff - struct Config_t - { - bool hitSound_Active = true; - bool badHitSound_Active = true; - bool noteMissedSound_Active = true; - bool menuMusic_Active = true; - bool menuClick_Active = true; - bool firework_Active = true; - bool levelCleared_Active = true; - bool levelFailed_Active = true; - bool lobbyAmbience_Active = true; - - std::string hitSound_filepath = HitSoundPath + "HitSound.ogg"; - std::string badHitSound_filepath = BadHitSoundPath + "BadHitSound.ogg"; - std::string noteMissedSound_filepath = NoteMissedSoundPath + "NoteMissedSound.ogg"; - std::string menuMusic_filepath = MenuMusicPath + "MenuMusic.ogg"; - std::string menuClick_filepath = MenuClickPath + "MenuClick.ogg"; - std::string firework_filepath = FireworkSoundPath + "Firework.ogg"; - std::string levelCleared_filepath = LevelClearedPath + "LevelCleared.ogg"; - std::string levelFailed_filepath = LevelFailedPath + "LevelFailed.ogg"; - std::string lobbyAmbience_filepath = LobbyMusicPath + "LobbyMusic.ogg"; - - float hitSound_audioVolumeOffset = 0; - float badHitSound_audioVolumeOffset = 0; - float noteMissedSound_audioVolumeOffset = 0; - //float menuMusic_audioVolumeOffset = 0; - //float menuClick_audioVolumeOffset = 0; - //float firework_audioVolumeOffset = 0; - //float levelCleared_audioVolumeOffset = 0; - float levelFailed_audioVolumeOffset = 0; - //float lobbyAmbience_audioVolumeOffset = 0; - - float hitSound_beatOffSet = 0.185f; - }; - extern Config_t Config; - - void AddChildSound(ConfigValue& parent, std::string_view soundName, bool active, std::string filePath, ConfigDocument::AllocatorType& allocator); - void AddChildSound(ConfigValue& parent, std::string_view soundName, bool active, std::string filePath, float beatOffSet, ConfigDocument::AllocatorType& allocator); - bool ParseSound(bool& active, std::string& filepath, ConfigValue& parent, std::string_view soundName); - bool ParseSound(bool& active, std::string& filepath, float& beatOffSet, ConfigValue& parent, std::string_view soundName); - - void SaveConfig(); - bool LoadConfig(); -} diff --git a/src/QSoundsConfig.cpp b/src/QSoundsConfig.cpp deleted file mode 100644 index c4db12b..0000000 --- a/src/QSoundsConfig.cpp +++ /dev/null @@ -1,283 +0,0 @@ -//#include "audiocliploader.hpp" -//#include "AsyncAudiocliploader.hpp" -#include "QSoundsConfig.hpp" - -namespace QSoundsConfig { - - //std::string soundPath = string_format(SOUND_PATH_FORMAT, Modloader::getApplicationId().c_str()); - - Config_t Config; - - bool LegacyConfig = false; - - void AddChildSound(ConfigValue& parent, std::string_view soundName, bool active, std::string filePath, ConfigDocument::AllocatorType& allocator) - { - ConfigValue value(rapidjson::kObjectType); - value.AddMember("activated", active, allocator); - std::string data(filePath); - value.AddMember("filepath", data, allocator); - parent.AddMember((ConfigValue::StringRefType)soundName.data(), value, allocator); - } - - - void AddChildSound(ConfigValue& parent, std::string_view soundName, bool active, std::string filePath, float audioVolumeOffset, ConfigDocument::AllocatorType& allocator) - { - ConfigValue value(rapidjson::kObjectType); - value.AddMember("activated", active, allocator); - std::string data(filePath); - value.AddMember("filepath", data, allocator); - value.AddMember("audioVolumeOffset", audioVolumeOffset, allocator); - parent.AddMember((ConfigValue::StringRefType)soundName.data(), value, allocator); - } - - void AddChildSound(ConfigValue& parent, std::string_view soundName, bool active, std::string filePath, float beatOffSet, float audioVolumeOffset, ConfigDocument::AllocatorType& allocator) - { - ConfigValue value(rapidjson::kObjectType); - value.AddMember("activated", active, allocator); - std::string data(filePath); - value.AddMember("filepath", data, allocator); - value.AddMember("beatOffSet", beatOffSet, allocator); - value.AddMember("audioVolumeOffset", audioVolumeOffset, allocator); - parent.AddMember((ConfigValue::StringRefType)soundName.data(), value, allocator); - } - - - // Edited ParseVector made by Darknight1050 - namespace Legacy { - bool TryParseSound(bool& active, std::string& filepath, float& beatOffSet, ConfigValue& parent, std::string_view soundName) - { - if (!parent.HasMember(soundName.data()) || !parent[soundName.data()].IsObject()) { - getLogger().error("ERROR: Parsing, %s, parent HasMember bool: %d, Member IsObject bool: %d", soundName.data(), parent.HasMember(soundName.data()), parent[soundName.data()].IsObject()); - return false; - } - ConfigValue value = static_cast(parent[soundName.data()].GetObject()); - bool success = true; - if (value.HasMember("activated") && value["activated"].IsBool()) { - active = value["activated"].GetBool(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does activated exist '%s' and is it a float '%s'", - soundName.data(), - value.HasMember("activated") ? "true" : "false", value.HasMember("activated") ? value["activated"].IsBool() ? "true" : "false" : "unknown"); - success = false; - } - if (value.HasMember("beatOffSet") && value["beatOffSet"].IsFloat()) { - beatOffSet = value["beatOffSet"].GetFloat(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does beatOffSet exist '%s' and is it a float '%s'", - soundName.data(), - value.HasMember("beatOffSet") ? "true" : "false", value.HasMember("beatOffSet") ? value["beatOffSet"].IsFloat() ? "true" : "false" : "unknown"); - success = false; - } - if (!(value.HasMember("filepath") && value["filepath"].IsString())) { - getLogger().error("ERROR: important members missing skipping sound.\nWhile Parsing: '%s', does filepath exist: '%s' is it a string: '%s'", - soundName.data(), - value.HasMember("filepath") ? "true" : "false", value.HasMember("filepath") ? value["filepath"].IsString() ? "true" : "false" : "unknown"); - return false; - } - filepath = value["filepath"].GetString(); - return success; - } - } - - bool TryParseSound(bool& active, std::string& filepath, float& beatOffSet, float& audioVolumeOffset, ConfigValue& parent, std::string_view soundName) - { - if (!parent.HasMember(soundName.data()) || !parent[soundName.data()].IsObject()) { - getLogger().error("ERROR: Parsing, %s, parent HasMember bool: %d, Member IsObject bool: %d", soundName.data(), parent.HasMember(soundName.data()), parent[soundName.data()].IsObject()); - return false; - } - ConfigValue value = static_cast(parent[soundName.data()].GetObject()); - bool success = true; - if (value.HasMember("activated") && value["activated"].IsBool()) { - active = value["activated"].GetBool(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does activated exist '%s' and is it a float '%s'", - soundName.data(), - value.HasMember("activated") ? "true" : "false", value.HasMember("activated") ? value["activated"].IsBool() ? "true" : "false" : "unknown"); - success = false; - } - if (value.HasMember("beatOffSet") && value["beatOffSet"].IsFloat()) { - beatOffSet = value["beatOffSet"].GetFloat(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does beatOffSet exist '%s' and is it a float '%s'", - soundName.data(), - value.HasMember("beatOffSet") ? "true" : "false", value.HasMember("beatOffSet") ? value["beatOffSet"].IsFloat() ? "true" : "false" : "unknown"); - success = false; - } - if (value.HasMember("audioVolumeOffset") && value["audioVolumeOffset"].IsFloat()) { - audioVolumeOffset = value["audioVolumeOffset"].GetFloat(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does audioVolumeOffset exist '%s' and is it a float '%s'", - soundName.data(), - value.HasMember("audioVolumeOffset") ? "true" : "false", value.HasMember("audioVolumeOffset") ? value["audioVolumeOffset"].IsFloat() ? "true" : "false" : "unknown"); - success = false; - } - if (!(value.HasMember("filepath") && value["filepath"].IsString())) { - getLogger().error("ERROR: important members missing skipping sound.\nWhile Parsing: '%s', does filepath exist: '%s' is it a string: '%s'", - soundName.data(), - value.HasMember("filepath") ? "true" : "false", value.HasMember("filepath") ? value["filepath"].IsString() ? "true" : "false" : "unknown"); - return false; - } - filepath = value["filepath"].GetString(); - return success; - } - - bool TryParseSound(bool& active, std::string& filepath, float& audioVolumeOffset, ConfigValue& parent, std::string_view soundName) - { - if (!parent.HasMember(soundName.data()) || !parent[soundName.data()].IsObject()) { - getLogger().error("ERROR: Parsing, %s, parent HasMember bool: %d, Member IsObject bool: %d", soundName.data(), parent.HasMember(soundName.data()), parent[soundName.data()].IsObject()); - return false; - } - ConfigValue value = static_cast(parent[soundName.data()].GetObject()); - bool success = true; - if (value.HasMember("activated") && value["activated"].IsBool()) { - active = value["activated"].GetBool(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does activated exist '%s' and is it a bool '%s'", - soundName.data(), - value.HasMember("activated") ? "true" : "false", value.HasMember("activated") ? value["activated"].IsBool() ? "true" : "false" : "unknown"); - success = false; - } - if (value.HasMember("audioVolumeOffset") && value["audioVolumeOffset"].IsFloat()) { - audioVolumeOffset = value["audioVolumeOffset"].GetFloat(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does audioVolumeOffset exist '%s' and is it a float '%s'", - soundName.data(), - value.HasMember("audioVolumeOffset") ? "true" : "false", value.HasMember("audioVolumeOffset") ? value["audioVolumeOffset"].IsFloat() ? "true" : "false" : "unknown"); - success = false; - } - if (!(value.HasMember("filepath") && value["filepath"].IsString())) { - getLogger().error("ERROR: important members missing skipping sound.\nWhile Parsing: '%s', does filepath exist: '%s' is it a string: '%s'", - soundName.data(), - value.HasMember("filepath") ? "true" : "false", value.HasMember("filepath") ? value["filepath"].IsString() ? "true" : "false" : "unknown"); - return false; - } - filepath = value["filepath"].GetString(); - return success; - } - - bool TryParseSound(bool& active, std::string& filepath, ConfigValue& parent, std::string_view soundName) - { - if (!parent.HasMember(soundName.data()) || !parent[soundName.data()].IsObject()) { - getLogger().error("ERROR: Parsing, %s, parent HasMember bool: %d, Member IsObject bool: %d", soundName.data(), parent.HasMember(soundName.data()), parent[soundName.data()].IsObject()); - return false; - } - ConfigValue value = static_cast(parent[soundName.data()].GetObject()); - bool success = true; - if (value.HasMember("activated") && value["activated"].IsBool()) { - active = value["activated"].GetBool(); - } - else { - getLogger().warning("WARNING: Member missing.\nWhile Parsing %s, does activated exist '%s' and is it a bool '%s'", - soundName.data(), - value.HasMember("activated") ? "true" : "false", value.HasMember("activated") ? value["activated"].IsBool() ? "true" : "false" : "unknown"); - success = false; - } - if (!(value.HasMember("filepath") && value["filepath"].IsString())) { - getLogger().error("ERROR: important members missing skipping sound.\nWhile Parsing: '%s', does filepath exist: '%s' is it a string: '%s'", - soundName.data(), - value.HasMember("filepath") ? "true" : "false", value.HasMember("filepath") ? value["filepath"].IsString() ? "true" : "false" : "unknown"); - return false; - } - filepath = value["filepath"].GetString(); - return success; - } - - - void SaveConfig() - { - getLogger().debug("Save config run"); - getConfig().config.RemoveAllMembers(); - getConfig().config.SetObject(); - auto& allocator = getConfig().config.GetAllocator(); - - ConfigValue soundsValue(rapidjson::kObjectType); - AddChildSound(soundsValue, "HitSound", Config.hitSound_Active, Config.hitSound_filepath , Config.hitSound_beatOffSet, Config.hitSound_audioVolumeOffset, allocator); - AddChildSound(soundsValue, "BadHitSound", Config.badHitSound_Active, Config.badHitSound_filepath, Config.badHitSound_audioVolumeOffset, allocator); - AddChildSound(soundsValue, "NoteMissedSound", Config.noteMissedSound_Active, Config.noteMissedSound_filepath, Config.noteMissedSound_audioVolumeOffset, allocator); - AddChildSound(soundsValue, "MenuMusic", Config.menuMusic_Active, Config.menuMusic_filepath, allocator); - AddChildSound(soundsValue, "MenuClick", Config.menuClick_Active, Config.menuClick_filepath, allocator); - AddChildSound(soundsValue, "Firework", Config.firework_Active, Config.firework_filepath, allocator); - AddChildSound(soundsValue, "LevelCleared", Config.levelCleared_Active, Config.levelCleared_filepath, allocator); - AddChildSound(soundsValue, "LevelFailed", Config.levelFailed_Active, Config.levelFailed_filepath, Config.levelFailed_audioVolumeOffset, allocator); - AddChildSound(soundsValue, "LobbyMusic", Config.lobbyAmbience_Active, Config.lobbyAmbience_filepath, allocator); - getConfig().config.AddMember(CONFIG_VERSION, soundsValue, allocator); - getConfig().Write(); - LegacyConfig = false; - } - - bool LoadConfig() - { - getConfig().Load(); - - bool parseError = false; - getLogger().debug("PreCheck: parseError currentValue: %d will be returned as: %d", parseError, !parseError); - if (getConfig().config.HasMember(CONFIG_VERSION) && getConfig().config[CONFIG_VERSION].IsObject()) - { - ConfigValue soundsValue = static_cast(getConfig().config[CONFIG_VERSION].GetObject()); - parseError |= !TryParseSound(Config.hitSound_Active, Config.hitSound_filepath, Config.hitSound_beatOffSet, Config.hitSound_audioVolumeOffset, soundsValue, "HitSound"); - parseError |= !TryParseSound(Config.badHitSound_Active, Config.badHitSound_filepath, Config.badHitSound_audioVolumeOffset, soundsValue, "BadHitSound"); - parseError |= !TryParseSound(Config.noteMissedSound_Active, Config.noteMissedSound_filepath, Config.noteMissedSound_audioVolumeOffset, soundsValue, "NoteMissedSound"); - parseError |= !TryParseSound(Config.menuMusic_Active, Config.menuMusic_filepath, soundsValue, "MenuMusic"); - parseError |= !TryParseSound(Config.menuClick_Active, Config.menuClick_filepath, soundsValue, "MenuClick"); - parseError |= !TryParseSound(Config.firework_Active, Config.firework_filepath, soundsValue, "Firework"); - parseError |= !TryParseSound(Config.levelCleared_Active, Config.levelCleared_filepath, soundsValue, "LevelCleared"); - parseError |= !TryParseSound(Config.levelFailed_Active, Config.levelFailed_filepath, Config.levelFailed_audioVolumeOffset, soundsValue, "LevelFailed"); - parseError |= !TryParseSound(Config.lobbyAmbience_Active, Config.lobbyAmbience_filepath, soundsValue, "LobbyMusic"); - getLogger().debug("PostCheck: parseError currentValue: %d will be returned as: %d", parseError, !parseError); - getLogger().debug("Config Loaded OK"); - return !parseError; - } - else if (getConfig().config.HasMember(CONFIG_VERSION_PRE_1_20) && getConfig().config[CONFIG_VERSION_PRE_1_20].IsObject()) - { - ConfigValue soundsValue = static_cast(getConfig().config[CONFIG_VERSION_PRE_1_20].GetObject()); - parseError |= !Legacy::TryParseSound(Config.hitSound_Active, Config.hitSound_filepath, Config.hitSound_beatOffSet, soundsValue, "HitSound"); - parseError |= !TryParseSound(Config.badHitSound_Active, Config.badHitSound_filepath, soundsValue, "BadHitSound"); - parseError |= !TryParseSound(Config.menuMusic_Active, Config.menuMusic_filepath, soundsValue, "MenuMusic"); - parseError |= !TryParseSound(Config.menuClick_Active, Config.menuClick_filepath, soundsValue, "MenuClick"); - parseError |= !TryParseSound(Config.firework_Active, Config.firework_filepath, soundsValue, "Firework"); - parseError |= !TryParseSound(Config.levelCleared_Active, Config.levelCleared_filepath, soundsValue, "LevelCleared"); - parseError |= !TryParseSound(Config.levelFailed_Active, Config.levelFailed_filepath, soundsValue, "LevelFailed"); - parseError |= !TryParseSound(Config.lobbyAmbience_Active, Config.lobbyAmbience_filepath, soundsValue, "LobbyMusic"); - } - else if (getConfig().config.HasMember(CONFIG_VERSION_LEGACY) && getConfig().config[CONFIG_VERSION_LEGACY].IsObject()) { - ConfigValue soundsValue = static_cast(getConfig().config[CONFIG_VERSION_LEGACY].GetObject()); - parseError |= !TryParseSound(Config.hitSound_Active, Config.hitSound_filepath, soundsValue, "HitSound"); - parseError |= !TryParseSound(Config.badHitSound_Active, Config.badHitSound_filepath, soundsValue, "BadHitSound"); - parseError |= !TryParseSound(Config.menuMusic_Active, Config.menuMusic_filepath, soundsValue, "MenuMusic"); - parseError |= !TryParseSound(Config.menuClick_Active, Config.menuClick_filepath, soundsValue, "MenuClick"); - parseError |= !TryParseSound(Config.firework_Active, Config.firework_filepath, soundsValue, "Firework"); - parseError |= !TryParseSound(Config.levelCleared_Active, Config.levelCleared_filepath, soundsValue, "LevelCleared"); - LegacyConfig = true; - } - else if (getConfig().config.HasMember(CONFIG_VERSION_PRE_R) && getConfig().config[CONFIG_VERSION_PRE_R].IsObject()) { - ConfigValue soundsValue = static_cast(getConfig().config[CONFIG_VERSION_PRE_R].GetObject()); - parseError |= !TryParseSound(Config.hitSound_Active, Config.hitSound_filepath, soundsValue, "HitSound"); - parseError |= !TryParseSound(Config.badHitSound_Active, Config.badHitSound_filepath, soundsValue, "BadHitSound"); - parseError |= !TryParseSound(Config.menuMusic_Active, Config.menuMusic_filepath, soundsValue, "MenuMusic"); - parseError |= !TryParseSound(Config.menuClick_Active, Config.menuClick_filepath, soundsValue, "MenuClick"); - parseError |= !TryParseSound(Config.firework_Active, Config.firework_filepath, soundsValue, "Firework"); - parseError |= !TryParseSound(Config.levelCleared_Active, Config.levelCleared_filepath, soundsValue, "LevelCleared"); - parseError |= !TryParseSound(Config.lobbyAmbience_Active, Config.lobbyAmbience_filepath, soundsValue, "LobbyMusic"); - LegacyConfig = true; - } - else { - getLogger().debug("Config Mismatch"); - return false; - } - if (!parseError) { - getLogger().debug("Config Loaded OK"); - } - else { - getLogger().debug("Config Loaded with errors"); - } - getLogger().debug("PostCheck: parseError currentValue: %d will be returned as: %d", parseError, !parseError); - return !parseError; - } -} \ No newline at end of file From 62eb2c09f6f4c9f7eca165356d6fc2f1dc6f5dea Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:47:48 +0200 Subject: [PATCH 16/55] RJM config --- include/Config.hpp | 113 +++++++++++++++++++++++++++++++++++++++++++++ src/Config.cpp | 5 ++ 2 files changed, 118 insertions(+) create mode 100644 include/Config.hpp create mode 100644 src/Config.cpp diff --git a/include/Config.hpp b/include/Config.hpp new file mode 100644 index 0000000..4e21248 --- /dev/null +++ b/include/Config.hpp @@ -0,0 +1,113 @@ +#include "scotland2/shared/loader.hpp" +#include "rapidjson-macros\shared\macros.hpp" + +#define SOUND_PATH_FORMAT "/sdcard/ModData/{}/Mods/QuestSounds/" +// #define CONFIG_VERSION "SoundsConfig_v3" +// #define CONFIG_VERSION_PRE_1_20 "SoundsConfig_v2" +// #define CONFIG_VERSION_PRE_R "SoundsConfig_v1" +// #define CONFIG_VERSION_LEGACY "Sounds" + +#define SOUND_VALUE(name, folder) VALUE_DEFAULT(Sound, name, Sound(soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg")) + +// define an automatically serialized / deserialized instance variable with a custom name in the json file and a default value +#pragma region NAMED_VALUE_CUSTOM(type, name, default, jsonName) +#define NAMED_VALUE_CUSTOM(type, name, def, jsonName) \ +type name = def; \ +class _JSONValueAdder_##name { \ + _JSONValueAdder_##name() { \ + serializers().emplace_back([](const SelfType* self, rapidjson::Value& jsonObject, rapidjson::Document::AllocatorType& allocator) { \ + rapidjson_macros_auto::Serialize(self->name, jsonName, jsonObject, allocator); \ + }); \ + deserializers().emplace_back([](SelfType* self, rapidjson::Value& jsonValue) { \ + rapidjson_macros_auto::Deserialize(self->name, jsonName, self->def, jsonValue); \ + }); \ + } \ + friend class rapidjson_macros_types::ConstructorRunner<_JSONValueAdder_##name>; \ + static inline rapidjson_macros_types::ConstructorRunner<_JSONValueAdder_##name> _##name##_JSONValueAdderInstance; \ +}; +#pragma endregion + +namespace QuestSounds { + static const std::string soundPath = fmt::format(SOUND_PATH_FORMAT, modloader::get_application_id().c_str()); + + DECLARE_JSON_CLASS(Sound, + NAMED_VALUE_DEFAULT(bool, Active, true, "activated"); + std::string FolderPath; + std::string DefaultFilePath; + NAMED_VALUE_CUSTOM(std::string, FilePath, DefaultFilePath, "filepath"); + NAMED_VALUE_OPTIONAL(float, VolumeOffset, "audioVolumeOffset"); + NAMED_VALUE_OPTIONAL(float, BeatOffset, "beatOffSet"); + Sound(std::string folderPath, std::string defaultFilePath) : FolderPath(folderPath), DefaultFilePath(defaultFilePath) {} + ) + + DECLARE_JSON_CLASS( + Sounds, + SOUND_VALUE(HitSound, "HitSounds"); + SOUND_VALUE(BadHitSound, "BadHitSounds"); + SOUND_VALUE(NoteMissedSound, "NoteMissedSounds"); + SOUND_VALUE(MenuMusic, "MenuMusic"); + SOUND_VALUE(MenuClick, "MenuClicks"); + SOUND_VALUE(Firework, "Fireworks"); + SOUND_VALUE(LevelCleared, "LevelCleared"); + SOUND_VALUE(LevelFailed, "LevelFailed"); + SOUND_VALUE(LobbyMusic, "LobbyMusic"); + ) + + DECLARE_JSON_CLASS( + SoundsConfig, + NAMED_VALUE(Sounds, Sounds, NAME_OPTS("SoundsConfig_v3", "SoundsConfig_v2", "SoundsConfig_v1", "Sounds")); + ) + extern SoundsConfig Config; +} + + + +// #define CONFIG_SOUND(name, folderpath, active, ...) {name, SoundConfig(name, folderpath, active, __VA_ARGS__)} + +// namespace QuestSounds { +// struct SoundConfig { +// SoundConfig() = default; +// SoundConfig(std::string name, std::string folderpath, bool active, std::optional volumeOffset = std::nullopt, std::optional beatOffset = std::nullopt) : FolderPath(folderpath), FilePath(folderpath + name + ".ogg"), Active(active), VolumeOffset(volumeOffset), BeatOffset(beatOffset) {} + +// bool Active = true; +// std::string FilePath; +// std::string FolderPath; +// std::optional VolumeOffset; +// std::optional BeatOffset; +// }; + +// static const std::string soundPath = fmt::format(SOUND_PATH_FORMAT, modloader::get_application_id().c_str()); + +// struct Config { +// std::map Sounds = { +// CONFIG_SOUND("MenuMusic", soundPath + "MenuMusic/", true), +// CONFIG_SOUND("HitSound", soundPath + "HitSounds/", true, 0, 0.185f), +// CONFIG_SOUND("BadHitSound", soundPath + "BadHitSounds/", true), +// CONFIG_SOUND("NoteMissedSound", soundPath + "NoteMissedSounds/", true), +// CONFIG_SOUND("MenuClickSound", soundPath + "MenuClicks/", true), +// CONFIG_SOUND("FireworkSound", soundPath + "Fireworks/", true), +// CONFIG_SOUND("LevelClearedSound", soundPath + "LevelCleared/", true), +// CONFIG_SOUND("LevelFailedSound", soundPath + "LevelFailed/", true), +// CONFIG_SOUND("LobbyAmbience", soundPath + "LobbyMusic/", true) +// }; +// // SoundConfig menuMusic = SoundConfig("MenuMusic", soundPath + "MenuMusic/", true, 0, 0); +// // SoundConfig hitSound = SoundConfig("HitSound", soundPath + "HitSounds/", true, 0, 0); +// // SoundConfig badHitSound = SoundConfig("BadHitSound", soundPath + "BadHitSounds/", true, 0, 0); +// // SoundConfig noteMissedSound = SoundConfig("NoteMissedSound", soundPath + "NoteMissedSounds/", true, 0, 0); +// // SoundConfig menuClickSound = SoundConfig("MenuClickSound", soundPath + "MenuClicks/", true, 0, 0); +// // SoundConfig fireworkSound = SoundConfig("FireworkSound", soundPath + "Fireworks/", true, 0, 0); +// // SoundConfig levelClearedSound = SoundConfig("LevelClearedSound", soundPath + "LevelCleared/", true, 0, 0); +// // SoundConfig levelFailedSound = SoundConfig("LevelFailedSound", soundPath + "LevelFailed/", true, 0, 0); +// // SoundConfig lobbyAmbience = SoundConfig("LobbyAmbience", soundPath + "LobbyMusic/", true, 0, 0); +// bool LegacyConfig = false; +// }; + +// extern Config config; +// } + + + + +#undef SOUND_PATH_FORMAT +#undef SOUND_VALUE +// #undef CONFIG_SOUND \ No newline at end of file diff --git a/src/Config.cpp b/src/Config.cpp new file mode 100644 index 0000000..56ae25f --- /dev/null +++ b/src/Config.cpp @@ -0,0 +1,5 @@ +#include "Config.hpp" +// TODO: Check if I need this cpp file at all +namespace QuestSounds { + SoundsConfig Config; +} \ No newline at end of file From 4cdd8631eb199a9c08c6393b5171d3ba06a3cb0d Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:48:01 +0200 Subject: [PATCH 17/55] Add RJM dependency --- qpm.json | 5 +++++ qpm.shared.json | 37 +++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/qpm.json b/qpm.json index 1aca5a5..7b08e90 100644 --- a/qpm.json +++ b/qpm.json @@ -55,6 +55,11 @@ "id": "paper", "versionRange": "^3.6.4", "additionalData": {} + }, + { + "id": "rapidjson-macros", + "versionRange": "^1.2.1", + "additionalData": {} } ] } \ No newline at end of file diff --git a/qpm.shared.json b/qpm.shared.json index dccb89a..2f32a79 100644 --- a/qpm.shared.json +++ b/qpm.shared.json @@ -56,6 +56,11 @@ "id": "paper", "versionRange": "^3.6.4", "additionalData": {} + }, + { + "id": "rapidjson-macros", + "versionRange": "^1.2.1", + "additionalData": {} } ] }, @@ -80,6 +85,18 @@ }, "version": "3.6.4" }, + { + "dependency": { + "id": "rapidjson-macros", + "versionRange": "=1.2.1", + "additionalData": { + "headersOnly": true, + "branchName": "version/v1_2_1", + "cmake": true + } + }, + "version": "1.2.1" + }, { "dependency": { "id": "bsml", @@ -95,17 +112,6 @@ }, "version": "0.4.43" }, - { - "dependency": { - "id": "libil2cpp", - "versionRange": "=0.3.2", - "additionalData": { - "headersOnly": true, - "cmake": false - } - }, - "version": "0.3.2" - }, { "dependency": { "id": "config-utils", @@ -142,15 +148,14 @@ }, { "dependency": { - "id": "rapidjson-macros", - "versionRange": "=1.2.1", + "id": "libil2cpp", + "versionRange": "=0.3.2", "additionalData": { "headersOnly": true, - "branchName": "version/v1_2_1", - "cmake": true + "cmake": false } }, - "version": "1.2.1" + "version": "0.3.2" }, { "dependency": { From b31ed8538dcf6062edbcb2866cc7bf7015cfd83e Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:48:20 +0200 Subject: [PATCH 18/55] Fix buildQMOD not finding sounds --- buildQMOD.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildQMOD.ps1 b/buildQMOD.ps1 index a3ea972..f63058d 100644 --- a/buildQMOD.ps1 +++ b/buildQMOD.ps1 @@ -66,7 +66,7 @@ $qmod = $qmodName + ".qmod" # Move-Item $qmod $zip -Force # } -qpm qmod zip -i ./build/ -i ./extern/libs/ $qmod +qpm qmod zip -i ./build/ -i ./extern/libs/ -i ./Examples/ $qmod # Compress-Archive -Path $filelist -DestinationPath $zip -Update # Move-Item $zip $qmod -Force From cc6ae624a18dc764d734b668ead3f5c76030261c Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:48:34 +0200 Subject: [PATCH 19/55] Bump mod template to 1.37.0 --- mod.template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.template.json b/mod.template.json index 3a51953..224aaad 100644 --- a/mod.template.json +++ b/mod.template.json @@ -5,7 +5,7 @@ "author": "Rugtveit, EnderdracheLP", "version": "${version}", "packageId": "com.beatgames.beatsaber", - "packageVersion": "1.28.0_4124311467", + "packageVersion": "1.37.0_9064817954", "description": "Allows users to change their sfx sounds and in-game music easily!", "coverImage": "Cover.jpg", "dependencies": [], From ac9d1381699d4cd215d1c29128e59addb0f29893 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 21:49:52 +0200 Subject: [PATCH 20/55] Fixup sound loading, code cleanup, fixing logging --- include/AudioClips.hpp | 6 +- include/ObjectInstances.hpp | 2 + include/Utils/AsyncAudiocliploader.hpp | 18 +- include/main.hpp | 2 +- src/Utils/AsyncAudiocliploader.cpp | 141 +++++++----- src/main.cpp | 283 +++++++++++++------------ 6 files changed, 244 insertions(+), 208 deletions(-) diff --git a/include/AudioClips.hpp b/include/AudioClips.hpp index 1a65175..50300aa 100644 --- a/include/AudioClips.hpp +++ b/include/AudioClips.hpp @@ -1,11 +1,11 @@ #pragma once //#include "main.hpp" //#include "audiocliploader.hpp" -#include "Utils/AsyncAudiocliploader.hpp" +#include "Utils/AsyncAudioClipLoader.hpp" namespace QuestSounds::AudioClips { //extern audioClipLoader::loader - extern AsyncAudioClipLoader::loader hitSoundLoader, // hitSound + extern QuestSounds::Utils::AsyncAudioClipLoader hitSoundLoader, // hitSound badHitSoundLoader, // badHitSound noteMissedSoundLoader, menuMusicLoader, // menuMusic @@ -22,5 +22,5 @@ namespace QuestSounds::AudioClips { extern Array * origMenuClickArr; extern void loadAudioClips(); - extern Array* createAudioClipArray(AsyncAudioClipLoader::loader clipLoader, bool GetOriginalClip = false); + extern Array* createAudioClipArray(QuestSounds::Utils::AsyncAudioClipLoader clipLoader, bool GetOriginalClip = false); } diff --git a/include/ObjectInstances.hpp b/include/ObjectInstances.hpp index 19cce87..36db22f 100644 --- a/include/ObjectInstances.hpp +++ b/include/ObjectInstances.hpp @@ -4,6 +4,8 @@ #include "GlobalNamespace/SongPreviewPlayer.hpp" +// TODO: See if I can get rid of this header also possibly just forward delcare SongPreviewPlayer to make this more tidy + namespace QuestSounds::ObjectInstances { extern GlobalNamespace::SongPreviewPlayer* SPP; } \ No newline at end of file diff --git a/include/Utils/AsyncAudiocliploader.hpp b/include/Utils/AsyncAudiocliploader.hpp index f2249cd..9fec135 100644 --- a/include/Utils/AsyncAudiocliploader.hpp +++ b/include/Utils/AsyncAudiocliploader.hpp @@ -12,16 +12,15 @@ #include "UnityEngine/Networking/UnityWebRequestMultimedia.hpp" #include "UnityEngine/Networking/UnityWebRequest.hpp" -//#include "custom-types/shared/coroutine.hpp" +#include "custom-types/shared/coroutine.hpp" -namespace AsyncAudioClipLoader +namespace QuestSounds::Utils { - // TODO: CustomTypes/Zenject or just a cpp class? - class loader : public Il2CppObject + // TODO: Cleanup this class + class AsyncAudioClipLoader { public: - //static Logger logger; std::string filePath; int audioType = 14; UnityEngine::AudioSource* audioSource; @@ -32,11 +31,14 @@ namespace AsyncAudioClipLoader UnityEngine::AudioClip* get_OriginalClip(); //Audioclip UnityEngine::AudioSource* OriginalAudioSource = nullptr; private: + custom_types::Helpers::Coroutine LoadAudioClip(); + StringW loadPath; + // custom_types::Helpers::Coroutine loadCoroutine; UnityEngine::GameObject* audioClipGO; - static void audioClipCompleted(loader* obj, Il2CppObject* asyncOp); - StringW path; + void audioClipCompleted(); + // StringW path; bool UsesUWR = false; - System::Threading::Tasks::Task_1* audioClipTask; + System::Threading::Tasks::Task_1<::UnityW>* audioClipTask; UnityEngine::Networking::UnityWebRequestAsyncOperation* audioClipAsync; UnityEngine::Networking::UnityWebRequest* audioClipRequest; diff --git a/include/main.hpp b/include/main.hpp index 75e98f9..07025f4 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -19,6 +19,6 @@ // Define these functions here so that we can easily read configuration and log information from other files Configuration& getConfig(); -Paper::ConstLoggerContext<9UL>& getLogger(); +Paper::ConstLoggerContext<12UL>& getLogger(); #define QS_EXPORT extern "C" __attribute__((visibility("default"))) diff --git a/src/Utils/AsyncAudiocliploader.cpp b/src/Utils/AsyncAudiocliploader.cpp index a84c670..2a48c61 100644 --- a/src/Utils/AsyncAudiocliploader.cpp +++ b/src/Utils/AsyncAudiocliploader.cpp @@ -1,6 +1,7 @@ -#include "QSoundsConfig.hpp" -#include "Utils/AsyncAudiocliploader.hpp" +// #include "QSoundsConfig.hpp" +#include "Utils/AsyncAudioClipLoader.hpp" #include "main.hpp" +#include "Config.hpp" #include "ObjectInstances.hpp" #include @@ -8,6 +9,10 @@ #include +#include "custom-types/shared/delegate.hpp" +#include "bsml/shared/BSML/MainThreadScheduler.hpp" +#include "bsml/shared/BSML/SharedCoroutineStarter.hpp" + #include "UnityEngine/Networking/DownloadHandlerAudioClip.hpp" #include "UnityEngine/Networking/UnityWebRequestMultimedia.hpp" using namespace UnityEngine::Networking; @@ -18,6 +23,7 @@ using namespace UnityEngine::Networking; #include "System/Action_1.hpp" using namespace System; +#include "UnityEngine/AudioType.hpp" #include "UnityEngine/AsyncOperation.hpp" #include "UnityEngine/GameObject.hpp" using namespace UnityEngine; @@ -25,19 +31,19 @@ using namespace UnityEngine; int getAudioType(std::string path) { if (path.ends_with(".ogg")) { getLogger().debug("File is OGGVORBIS"); - return 0xE; + return (int)UnityEngine::AudioType::OGGVORBIS; } else if (path.ends_with(".mp3") || path.ends_with(".mp2")) { getLogger().debug("File is MPEG"); - return 0xD; + return (int)UnityEngine::AudioType::MPEG; } else if (path.ends_with(".wav")) { getLogger().debug("File is WAV"); - return 0x14; + return (int)UnityEngine::AudioType::WAV; } else if (path.ends_with(".aiff") || path.ends_with(".aif")) { getLogger().debug("File is AIFF"); - return 2; + return (int)UnityEngine::AudioType::AIFF; } return 0; } @@ -45,14 +51,13 @@ int getAudioType(std::string path) { System::Threading::Tasks::Task_1* audioClipTask; //bool NeedReload = false; -bool AsyncAudioClipLoader::loader::load() +bool QuestSounds::Utils::AsyncAudioClipLoader::load() { loaded = false; //Stage 0 bool fileError; getLogger().info("Starting Stage 0"); - getLogger().info("FilePath to check is %s", filePath.c_str()); - StringW filePathStr; + getLogger().info("FilePath to check is {}", filePath.c_str()); if (filePath.starts_with("https://") || filePath.starts_with("http://")) { getLogger().info("Filepath is URL, skipping file checks and try loading it"); fileError = true; @@ -60,85 +65,109 @@ bool AsyncAudioClipLoader::loader::load() else { // Checks if the given File in the config exists and fileError = fileexists(filePath); - getLogger().info("File error is %d", fileError); + getLogger().info("File error is {}", fileError); if (!fileError) { - getLogger().error("File %s not found", filePath.c_str()); + getLogger().error("File {} not found", filePath.c_str()); getLogger().error("Stage 0 Failed"); return false; } - else { getLogger().info("Stage 0 Done with %s", filePath.c_str()); } + else { getLogger().info("Stage 0 Done with {}", filePath.c_str()); } } //Stage 1 - if (!(filePath == QSoundsConfig::Config.hitSound_filepath) && filePath.ends_with(".ogg")) { - getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath %s", filePath.c_str()); + if (!(filePath == QuestSounds::Config.Sounds.HitSound.FilePath) && filePath.ends_with(".ogg")) { + getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); UsesUWR = false; - filePathStr = filePath; - audioClipTask = GlobalNamespace::MediaAsyncLoader::New_ctor()->LoadAudioClipFromFilePathAsync(filePathStr); - ////Stage 2 - auto actionMAL = il2cpp_utils::MakeDelegate*>(classof(System::Action_1*), this, audioClipCompleted); - reinterpret_cast(audioClipTask)->ContinueWith(actionMAL); + loadPath = filePath; + if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) il2cpp_functions::Class_Init(classof(GlobalNamespace::MediaAsyncLoader*)); + // if (!mediaAsyncLoader) mediaAsyncLoader = ::il2cpp_utils::NewSpecific<::GlobalNamespace::MediaAsyncLoader*, il2cpp_utils::CreationType::Manual>(); + audioClipTask = GlobalNamespace::MediaAsyncLoader::New_ctor()->LoadAudioClipFromFilePathAsync(loadPath); + + audioClipTask->GetAwaiter().OnCompleted(custom_types::MakeDelegate(std::function([this]() + { + audioClipCompleted(); + }))); } else { - getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath %s", filePath.c_str()); + getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath {}", filePath.c_str()); UsesUWR = true; if (filePath.starts_with("https://") || filePath.starts_with("http://")) { - filePathStr = filePath; + loadPath = filePath; } else { - filePathStr = "file:///" + filePath; + // EscapeURL but also replaces spaces with %20 since the UnityWebRequest replaces spaces with + which causes unitys curl call to fail + loadPath = "file:///" + UnityEngine::Networking::UnityWebRequest::EscapeURL(std::regex_replace(filePath, std::regex(" "), "%20")); } audioType = getAudioType(filePath); - auto actionUWRM = il2cpp_utils::MakeDelegate*>(classof(System::Action_1*), this, audioClipCompleted); - - audioClipRequest = UnityEngine::Networking::UnityWebRequestMultimedia::GetAudioClip(filePathStr, audioType); - audioClipAsync = audioClipRequest->SendWebRequest(); - audioClipAsync->set_allowSceneActivation(false); - - if (!audioClipRequest->get_isHttpError() || !audioClipRequest->get_isNetworkError()) { - //Stage 2 - audioClipAsync->add_completed(actionUWRM); - } + BSML::SharedCoroutineStarter::get_instance()->StartCoroutine(custom_types::Helpers::CoroutineHelper::New(LoadAudioClip())); } - getLogger().info("Stage 1 done with filepath %s", filePath.c_str()); + getLogger().info("Stage 1 done with filepath {}", filePath.c_str()); return true; } -void AsyncAudioClipLoader::loader::audioClipCompleted(loader* obj, Il2CppObject* asyncOp) +custom_types::Helpers::Coroutine QuestSounds::Utils::AsyncAudioClipLoader::LoadAudioClip() { - // Stage 1 + getLogger().info("Stage 1: Running UnityWebRequestMultimedia for LoadPath {}", loadPath); + audioClipRequest = UnityEngine::Networking::UnityWebRequestMultimedia::GetAudioClip(loadPath, audioType); + audioClipAsync = audioClipRequest->SendWebRequest(); + audioClipAsync->allowSceneActivation = false; + co_yield reinterpret_cast(audioClipAsync); + + if (audioClipRequest->GetError() != UnityEngine::Networking::UnityWebRequest::UnityWebRequestError::OK) { + getLogger().error("UnityWebRequestMultimedia for file '{}' failed with error {}", loadPath, (int)audioClipRequest->GetError()); + co_return; + } + else { + while (!audioClipRequest->isDone); + audioClipCompleted(); + } + co_return; +} + +void QuestSounds::Utils::AsyncAudioClipLoader::audioClipCompleted() +{ + // Stage 2 + getLogger().info("Starting Stage 2"); UnityEngine::AudioClip* temporaryClip = nullptr; - if (!obj->UsesUWR) { - temporaryClip = obj->audioClipTask->get_ResultOnSuccess(); - il2cpp_functions::GC_free(obj->audioClipTask); - obj->audioClipTask = nullptr; + if (!this->UsesUWR) { + getLogger().info("UsesUWR is false, getting result from audioClipTask"); + getLogger().debug("Is Task null? {}", fmt::ptr(audioClipTask)); + getLogger().debug("Task Status is {}", (int)audioClipTask->get_Status()); + temporaryClip = this->audioClipTask->get_ResultOnSuccess(); + // gc_free_specific(this->audioClipTask); + // this->audioClipTask = nullptr; + } + else if (this->UsesUWR && audioClipRequest->get_result() == UnityWebRequest::Result::Success){ + getLogger().info("UsesUWR is true, getting result from audioClipRequest"); + getLogger().debug("Is Request null? {}", fmt::ptr(audioClipRequest)); + temporaryClip = UnityEngine::Networking::DownloadHandlerAudioClip::GetContent(audioClipRequest); // TODO: This method takes too long } - else if (obj->UsesUWR) temporaryClip = UnityEngine::Networking::DownloadHandlerAudioClip::GetContent(obj->audioClipRequest); // TODO: This method takes too long if(temporaryClip != nullptr) { - if (!obj->audioClipGO) { - static auto goName = "AudioClipGO"; - obj->audioClipGO = GameObject::New_ctor(goName); - obj->audioSource = obj->audioClipGO->AddComponent(); - UnityEngine::Object::DontDestroyOnLoad(obj->audioClipGO); + getLogger().info("TemporaryClip is not nullptr setting it to AudioSource for filepath {}", filePath); + if (!this->audioClipGO) { + static ConstString goName = "AudioClipGO"; + audioClipGO = GameObject::New_ctor(goName); + audioSource = audioClipGO->AddComponent(); + UnityEngine::Object::DontDestroyOnLoad(audioClipGO); } - obj->audioSource->set_playOnAwake(false); - obj->audioSource->set_clip(temporaryClip); - obj->audioSource->set_volume(0.6f); - obj->loaded = true; + audioSource->set_playOnAwake(false); + audioSource->set_clip(temporaryClip); + audioSource->set_volume(0.6f); + loaded = true; getLogger().info("Stage 2 done with temporaryClip"); } else { - getLogger().error("Stage 2 failed with temporaryClip being nullptr %p Object FilePath: %s", temporaryClip, obj->filePath.c_str()); - if (!obj->UsesUWR) getLogger().error("Task Status was %d", (int)obj->audioClipTask->get_Status()); + getLogger().error("Stage 2 failed with temporaryClip being nullptr {} Object FilePath: {}", fmt::ptr(temporaryClip), filePath.c_str()); + if (!UsesUWR) getLogger().error("Task Status was {}", (int)audioClipTask->get_Status()); return; } // Finished } -UnityEngine::AudioClip* AsyncAudioClipLoader::loader::getClip() +UnityEngine::AudioClip* QuestSounds::Utils::AsyncAudioClipLoader::getClip() { if(audioSource != nullptr && loaded) { @@ -146,12 +175,12 @@ UnityEngine::AudioClip* AsyncAudioClipLoader::loader::getClip() return audioSource->get_clip(); } else { - getLogger().debug("nullptr returned: is AudioSource null: %p, is loaded: %d", audioSource, loaded); + getLogger().debug("nullptr returned: is AudioSource null: {}, is loaded: {}", fmt::ptr(audioSource), loaded); return nullptr; } } -void AsyncAudioClipLoader::loader::set_OriginalClip(AudioClip* OriginalAudioClip) +void QuestSounds::Utils::AsyncAudioClipLoader::set_OriginalClip(AudioClip* OriginalAudioClip) { // Stage 1 if (OriginalAudioClip != nullptr) @@ -167,7 +196,7 @@ void AsyncAudioClipLoader::loader::set_OriginalClip(AudioClip* OriginalAudioClip // Finished } -UnityEngine::AudioClip* AsyncAudioClipLoader::loader::get_OriginalClip() +UnityEngine::AudioClip* QuestSounds::Utils::AsyncAudioClipLoader::get_OriginalClip() { if (OriginalAudioSource != nullptr) { @@ -176,7 +205,7 @@ UnityEngine::AudioClip* AsyncAudioClipLoader::loader::get_OriginalClip() } else { - getLogger().debug("nullptr returned: is OriginalAudioSource null: %p", OriginalAudioSource); + getLogger().debug("nullptr returned: is OriginalAudioSource null: {}", fmt::ptr(OriginalAudioSource)); return nullptr; } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 065363f..e9bbe01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include "main.hpp" -#include "Utils/AsyncAudiocliploader.hpp" -#include "QSoundsConfig.hpp" -using namespace QSoundsConfig; +#include "Utils/AsyncAudioClipLoader.hpp" +#include "Config.hpp" #include "AudioClips.hpp" using namespace QuestSounds::AudioClips; @@ -21,7 +20,6 @@ using namespace QuestSounds::AudioClips; #include "GlobalNamespace/FileHelpers.hpp" #include "GlobalNamespace/LevelCompletionResults.hpp" -#include "GlobalNamespace/SongPreviewPlayer_AudioSourceVolumeController.hpp" using namespace GlobalNamespace; #include "System/Action.hpp" @@ -35,19 +33,19 @@ using namespace UnityEngine::SceneManagement; // TODO BSML -#include "ViewControllers/MenuSdListViewController.hpp" -#include "ViewControllers/HitSdListViewController.hpp" -#include "ViewControllers/MenuClickSdListViewController.hpp" -#include "ViewControllers/BadHitSdListViewController.hpp" -#include "ViewControllers/FireworkSdListViewController.hpp" -#include "ViewControllers/LevelClearedSdListViewController.hpp" -#include "ViewControllers/LobbyMusicSdListViewController.hpp" -#include "ViewControllers/ConfigViewController.hpp" -#include "QSoundsFlowCoordinator.hpp" +// #include "ViewControllers/MenuSdListViewController.hpp" +// #include "ViewControllers/HitSdListViewController.hpp" +// #include "ViewControllers/MenuClickSdListViewController.hpp" +// #include "ViewControllers/BadHitSdListViewController.hpp" +// #include "ViewControllers/FireworkSdListViewController.hpp" +// #include "ViewControllers/LevelClearedSdListViewController.hpp" +// #include "ViewControllers/LobbyMusicSdListViewController.hpp" +// #include "ViewControllers/ConfigViewController.hpp" +// #include "QSoundsFlowCoordinator.hpp" using namespace QuestSounds; -#include "custom-types/shared/register.hpp" -using namespace custom_types; +// #include "custom-types/shared/register.hpp" +// using namespace custom_types; #define RAPIDJSON_HAS_STDSTRING 1 @@ -59,102 +57,100 @@ Configuration& getConfig() { } // TODO: Proper paper logging -Paper::ConstLoggerContext<9UL>& getLogger() { +Paper::ConstLoggerContext<12UL>& getLogger() { static auto fastContext = Paper::Logger::WithContext(); return fastContext; } void makeFolder() { - if (!direxists(MenuMusicPath.c_str())) + if (!direxists(Config.Sounds.MenuMusic.FolderPath.c_str())) { - int makePath = mkpath(MenuMusicPath.c_str()); + int makePath = mkpath(Config.Sounds.MenuMusic.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make MenuMusic Folder path!"); } } - if (!direxists(HitSoundPath.c_str())) + if (!direxists(Config.Sounds.HitSound.FolderPath.c_str())) { - int makePath = mkpath(HitSoundPath.c_str()); + int makePath = mkpath(Config.Sounds.HitSound.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make HitSound Folder path!"); } } - if (!direxists(BadHitSoundPath.c_str())) + if (!direxists(Config.Sounds.BadHitSound.FolderPath.c_str())) { - int makePath = mkpath(BadHitSoundPath.c_str()); + int makePath = mkpath(Config.Sounds.BadHitSound.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make BadHitSound Folder path!"); } } - if (!direxists(NoteMissedSoundPath.c_str())) + if (!direxists(Config.Sounds.NoteMissedSound.FolderPath.c_str())) { - int makePath = mkpath(NoteMissedSoundPath.c_str()); + int makePath = mkpath(Config.Sounds.NoteMissedSound.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make NoteMissedSound Folder path!"); } } - if (!direxists(MenuClickPath.c_str())) + if (!direxists(Config.Sounds.MenuClick.FolderPath.c_str())) { - int makePath = mkpath(MenuClickPath.c_str()); + int makePath = mkpath(Config.Sounds.MenuClick.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make MenuClick Folder path!"); } } - if (!direxists(FireworkSoundPath.c_str())) + if (!direxists(Config.Sounds.Firework.FolderPath.c_str())) { - int makePath = mkpath(FireworkSoundPath.c_str()); + int makePath = mkpath(Config.Sounds.Firework.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make FireworkSound Folder path!"); } } - if (!direxists(LevelClearedPath.c_str())) + if (!direxists(Config.Sounds.LevelCleared.FolderPath.c_str())) { - int makePath = mkpath(LevelClearedPath.c_str()); + int makePath = mkpath(Config.Sounds.LevelCleared.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make LevelCleared Folder path!"); } } - if (!direxists(LevelFailedPath.c_str())) + if (!direxists(Config.Sounds.LevelFailed.FolderPath.c_str())) { - int makePath = mkpath(LevelFailedPath.c_str()); + int makePath = mkpath(Config.Sounds.LevelFailed.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make LevelFailed Folder path!"); } } -#ifndef BS__1_13_2 - if (!direxists(LobbyMusicPath.c_str())) + if (!direxists(Config.Sounds.LobbyMusic.FolderPath.c_str())) { - int makePath = mkpath(LobbyMusicPath.c_str()); + int makePath = mkpath(Config.Sounds.LobbyMusic.FolderPath.c_str()); if (makePath == -1) { getLogger().error("Failed to make LobbyMusic Folder path!"); } } -#endif } namespace QuestSounds::AudioClips { /*audioClipLoader::loader*/ -AsyncAudioClipLoader::loader hitSoundLoader, // hitSound +QuestSounds::Utils::AsyncAudioClipLoader hitSoundLoader, // hitSound badHitSoundLoader, // badHitSound noteMissedSoundLoader, menuMusicLoader, // menuMusic @@ -173,28 +169,28 @@ Array* origMenuClickArr; void loadAudioClips() { - hitSoundLoader.filePath = Config.hitSound_filepath; - badHitSoundLoader.filePath = Config.badHitSound_filepath; - noteMissedSoundLoader.filePath = Config.noteMissedSound_filepath; - menuMusicLoader.filePath = Config.menuMusic_filepath; - menuClickLoader.filePath = Config.menuClick_filepath; - fireworkSoundLoader.filePath = Config.firework_filepath; - levelClearedLoader.filePath = Config.levelCleared_filepath; - levelFailedLoader.filePath = Config.levelFailed_filepath; - lobbyAmbienceLoader.filePath = Config.lobbyAmbience_filepath; // Added for LobbyMusic + hitSoundLoader.filePath = Config.Sounds.HitSound.FilePath; + badHitSoundLoader.filePath = Config.Sounds.BadHitSound.FilePath; + noteMissedSoundLoader.filePath = Config.Sounds.NoteMissedSound.FilePath; + menuMusicLoader.filePath = Config.Sounds.MenuMusic.FilePath; + menuClickLoader.filePath = Config.Sounds.MenuClick.FilePath; + fireworkSoundLoader.filePath = Config.Sounds.Firework.FilePath; + levelClearedLoader.filePath = Config.Sounds.LevelCleared.FilePath; + levelFailedLoader.filePath = Config.Sounds.LevelFailed.FilePath; + lobbyAmbienceLoader.filePath = Config.Sounds.LobbyMusic.FilePath; // Added for LobbyMusic menuMusicLoader.load(); menuClickLoader.load(); - if (Config.hitSound_Active) hitSoundLoader.load(); - if (Config.badHitSound_Active) badHitSoundLoader.load(); - if (Config.noteMissedSound_Active) noteMissedSoundLoader.load(); - if (Config.firework_Active) fireworkSoundLoader.load(); - if (Config.levelCleared_Active) levelClearedLoader.load(); - if (Config.levelFailed_Active) levelFailedLoader.load(); - if (Config.lobbyAmbience_Active) lobbyAmbienceLoader.load(); // Added for LobbyMusic + if (Config.Sounds.HitSound.Active) hitSoundLoader.load(); + if (Config.Sounds.BadHitSound.Active) badHitSoundLoader.load(); + if (Config.Sounds.NoteMissedSound.Active) noteMissedSoundLoader.load(); + if (Config.Sounds.Firework.Active) fireworkSoundLoader.load(); + if (Config.Sounds.LevelCleared.Active) levelClearedLoader.load(); + if (Config.Sounds.LevelFailed.Active) levelFailedLoader.load(); + if (Config.Sounds.LobbyMusic.Active) lobbyAmbienceLoader.load(); // Added for LobbyMusic } // Creates an Array, of AudioClips - Array* createAudioClipArray(AsyncAudioClipLoader::loader clipLoader, bool GetOriginalClip) + Array* createAudioClipArray(QuestSounds::Utils::AsyncAudioClipLoader clipLoader, bool GetOriginalClip) { UnityEngine::AudioClip* tempClip; if (!GetOriginalClip) tempClip = clipLoader.getClip(); @@ -208,40 +204,40 @@ Array* origMenuClickArr; MAKE_HOOK_MATCH(ResultsViewController_DidActivate, &ResultsViewController::DidActivate, void, ResultsViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { if (firstActivation && addedToHierarchy && !levelClearedLoader.OriginalAudioSource) { - levelClearedLoader.set_OriginalClip(self->levelClearedAudioClip); + levelClearedLoader.set_OriginalClip(self->_levelClearedAudioClip); } - if (self->levelCompletionResults->levelEndStateType == LevelCompletionResults::LevelEndStateType::Failed) { - self->songPreviewPlayer->StopAllCoroutines(); - if (levelFailedLoader.loaded && addedToHierarchy && QSoundsConfig::Config.levelFailed_Active) { + if (self->_levelCompletionResults->levelEndStateType == LevelCompletionResults::LevelEndStateType::Failed) { + self->_songPreviewPlayer->StopAllCoroutines(); + if (levelFailedLoader.loaded && addedToHierarchy && Config.Sounds.LevelFailed.Active) { UnityEngine::AudioClip* FailedSound = levelFailedLoader.getClip(); float length = FailedSound->get_length(); - getLogger().debug("Duration of LevelFailed Sound: %f", length); + getLogger().debug("Duration of LevelFailed Sound: {}", length); if (length > 7.0f) { getLogger().info("Long LevelFailedSound"); - self->songPreviewPlayer->CrossfadeTo(FailedSound, -4.0f, 0.0f, length, nullptr); + self->_songPreviewPlayer->CrossfadeTo(FailedSound, -4.0f, 0.0f, length, nullptr); } else { getLogger().info("Short LevelFailedSound"); - self->songPreviewPlayer->FadeOut(0.1f); - self->songPreviewPlayer->fadeSpeed = self->songPreviewPlayer->fadeInSpeed; - getLogger().debug("volume: %f", self->songPreviewPlayer->volume); - getLogger().debug("AmbientVolume: %f", self->songPreviewPlayer->ambientVolumeScale); - getLogger().debug("Set Volume: %f", self->songPreviewPlayer->volume * self->songPreviewPlayer->ambientVolumeScale); - - levelFailedLoader.audioSource->set_volume(self->songPreviewPlayer->volume * self->songPreviewPlayer->ambientVolumeScale); - self->songPreviewPlayer->StartCoroutine(self->songPreviewPlayer->CrossFadeAfterDelayCoroutine(length - 1.2f)); + self->_songPreviewPlayer->FadeOut(0.1f); + self->_songPreviewPlayer->_fadeSpeed = self->_songPreviewPlayer->_fadeInSpeed; + getLogger().debug("volume: {}", self->_songPreviewPlayer->_volume); + getLogger().debug("AmbientVolume: {}", self->_songPreviewPlayer->_ambientVolumeScale); + getLogger().debug("Set Volume: {}", self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); + + levelFailedLoader.audioSource->set_volume(self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); + self->_songPreviewPlayer->StartCoroutine(self->_songPreviewPlayer->CrossFadeAfterDelayCoroutine(length - 1.2f)); levelFailedLoader.audioSource->Play(); } } } else { - if (levelClearedLoader.loaded && addedToHierarchy && QSoundsConfig::Config.levelCleared_Active) + if (levelClearedLoader.loaded && addedToHierarchy && Config.Sounds.LevelCleared.Active) { UnityEngine::AudioClip* audioClip = levelClearedLoader.getClip(); - self->levelClearedAudioClip = audioClip; + self->_levelClearedAudioClip = audioClip; } else { - self->levelClearedAudioClip = levelClearedLoader.get_OriginalClip(); + self->_levelClearedAudioClip = levelClearedLoader.get_OriginalClip(); } } ResultsViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); @@ -258,17 +254,19 @@ MAKE_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, getLogger().info("is it true: %i", menuMusicLoader.loaded); if (!menuMusicLoader.OriginalAudioSource) { - menuMusicLoader.set_OriginalClip(self->defaultAudioClip); + menuMusicLoader.set_OriginalClip(self->_defaultAudioClip); } - if (menuMusicLoader.loaded && QSoundsConfig::Config.menuMusic_Active) + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) { + getLogger().debug("Overriding MenuMusic Audio"); UnityEngine::AudioClip* audioClip = menuMusicLoader.getClip(); if (audioClip != nullptr) - self->defaultAudioClip = audioClip; + self->_defaultAudioClip = audioClip; } else { - self->defaultAudioClip = menuMusicLoader.get_OriginalClip(); + getLogger().debug("Loading MenuMusic Audio normally: isLoaded='{}' isActive='{}'", menuMusicLoader.loaded, Config.Sounds.MenuMusic.Active); + self->_defaultAudioClip = menuMusicLoader.get_OriginalClip(); } SongPreviewPlayer_OnEnable(self); } @@ -276,15 +274,15 @@ MAKE_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlowCoordinator::DidActivate, void, GameServerLobbyFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); - if (!lobbyAmbienceLoader.OriginalAudioSource) lobbyAmbienceLoader.set_OriginalClip(self->ambienceAudioClip); + if (!lobbyAmbienceLoader.OriginalAudioSource) lobbyAmbienceLoader.set_OriginalClip(self->_ambienceAudioClip); - if (lobbyAmbienceLoader.loaded && QSoundsConfig::Config.lobbyAmbience_Active) + if (lobbyAmbienceLoader.loaded && Config.Sounds.LobbyMusic.Active) { getLogger().debug("Overwriting LobbyAmbience Audio"); - self->ambienceAudioClip = lobbyAmbienceLoader.getClip(); + self->_ambienceAudioClip = lobbyAmbienceLoader.getClip(); } else { - self->ambienceAudioClip = lobbyAmbienceLoader.get_OriginalClip(); + self->_ambienceAudioClip = lobbyAmbienceLoader.get_OriginalClip(); } GameServerLobbyFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); } @@ -292,13 +290,13 @@ MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlow MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidDeactivate, &GameServerLobbyFlowCoordinator::DidDeactivate, void, GameServerLobbyFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) { getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); - if (menuMusicLoader.loaded && QSoundsConfig::Config.menuMusic_Active && removedFromHierarchy) + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) { getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); - self->ambienceAudioClip = menuMusicLoader.getClip(); + self->_ambienceAudioClip = menuMusicLoader.getClip(); } else { - self->ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); } GameServerLobbyFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); } @@ -306,13 +304,13 @@ MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidDeactivate, &GameServerLobbyFl MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidActivate, &MultiplayerModeSelectionFlowCoordinator::DidActivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidActivate"); - if (menuMusicLoader.loaded && QSoundsConfig::Config.menuMusic_Active) + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) { getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); - self->ambienceAudioClip = menuMusicLoader.getClip(); + self->_ambienceAudioClip = menuMusicLoader.getClip(); } else { - self->ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); } MultiplayerModeSelectionFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); // This has to be ran last, otherwise it will not work correctly } @@ -320,12 +318,12 @@ MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidActivate, &Multiplaye MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidDeactivate, &MultiplayerModeSelectionFlowCoordinator::DidDeactivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) { getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidDeactivate"); - if (menuMusicLoader.loaded && QSoundsConfig::Config.menuMusic_Active && removedFromHierarchy) + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) { - self->ambienceAudioClip = menuMusicLoader.getClip(); + self->_ambienceAudioClip = menuMusicLoader.getClip(); } else { - self->ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); } MultiplayerModeSelectionFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); @@ -338,33 +336,34 @@ MAKE_HOOK_MATCH(FileHelpers_GetEscapedURLForFilePath, &FileHelpers::GetEscapedUR #endif MAKE_HOOK_MATCH(NoteCutSoundEffectManager_Start, &NoteCutSoundEffectManager::Start, void, NoteCutSoundEffectManager* self) { - if(hitSoundLoader.loaded && QSoundsConfig::Config.hitSound_Active) + if(hitSoundLoader.loaded && Config.Sounds.HitSound.Active) { hitSoundArr = createAudioClipArray(hitSoundLoader); - self->longCutEffectsAudioClips = hitSoundArr; - self->shortCutEffectsAudioClips = hitSoundArr; + self->_longCutEffectsAudioClips = hitSoundArr; + self->_shortCutEffectsAudioClips = hitSoundArr; getLogger().debug("NoteCutSoundEffectManager_Start: Loaded hitSoundArray"); } else { getLogger().debug("NoteCutSoundEffectManager_Start: Loading normally"); } - getLogger().debug("audioSamplesBeatAlignOffset was: %f", self->audioSamplesBeatAlignOffset); - self->audioSamplesBeatAlignOffset = QSoundsConfig::Config.hitSound_beatOffSet; - getLogger().debug("audioSamplesBeatAlignOffset changed to: %f", self->audioSamplesBeatAlignOffset); + getLogger().debug("audioSamplesBeatAlignOffset was: {}", self->_audioSamplesBeatAlignOffset); + if (Config.Sounds.HitSound.BeatOffset.has_value()) + self->_audioSamplesBeatAlignOffset = Config.Sounds.HitSound.BeatOffset.value(); + getLogger().debug("audioSamplesBeatAlignOffset changed to: {}", self->_audioSamplesBeatAlignOffset); NoteCutSoundEffectManager_Start(self); - getLogger().debug("Beatalign offset is: %f", self->beatAlignOffset); + getLogger().debug("Beatalign offset is: {}", self->_beatAlignOffset); } MAKE_HOOK_MATCH(NoteCutSoundEffect_Awake, &NoteCutSoundEffect::Awake, void, NoteCutSoundEffect* self) { - if (hitSoundLoader.loaded && QSoundsConfig::Config.hitSound_Active) { - self->goodCutVolume += QSoundsConfig::Config.hitSound_audioVolumeOffset; + if (hitSoundLoader.loaded && Config.Sounds.HitSound.Active) { + self->_goodCutVolume += Config.Sounds.HitSound.VolumeOffset.value_or(0.0f); } - if(badHitSoundLoader.loaded && QSoundsConfig::Config.badHitSound_Active) + if(badHitSoundLoader.loaded && Config.Sounds.BadHitSound.Active) { badHitSoundArr = createAudioClipArray(badHitSoundLoader); - self->badCutSoundEffectAudioClips = badHitSoundArr; - self->badCutVolume += QSoundsConfig::Config.badHitSound_audioVolumeOffset; + self->_badCutSoundEffectAudioClips = badHitSoundArr; + self->_badCutVolume += Config.Sounds.BadHitSound.VolumeOffset.value_or(0.0f); } NoteCutSoundEffect_Awake(self); } @@ -372,59 +371,40 @@ MAKE_HOOK_MATCH(NoteCutSoundEffect_Awake, &NoteCutSoundEffect::Awake, void, Note MAKE_HOOK_MATCH(BeatmapObjectManager_HandleNoteWasMissed, &BeatmapObjectManager::HandleNoteControllerNoteWasMissed, void, BeatmapObjectManager* self, NoteController* noteController) { BeatmapObjectManager_HandleNoteWasMissed(self, noteController); if (noteMissedSoundLoader.loaded && - QSoundsConfig::Config.noteMissedSound_Active && + Config.Sounds.NoteMissedSound.Active && noteController->get_noteData()->get_scoringType() != NoteData::ScoringType::Ignore && noteController->get_noteData()->get_gameplayType() != NoteData::GameplayType::Bomb) { - //getLogger().debug("Playing note missed sound"); - noteMissedSoundLoader.audioSource->set_volume(0.5f + QSoundsConfig::Config.noteMissedSound_audioVolumeOffset); + noteMissedSoundLoader.audioSource->set_volume(0.5f + Config.Sounds.NoteMissedSound.VolumeOffset.value_or(0.0f)); noteMissedSoundLoader.audioSource->Play(); - //noteMissedSoundLoader.audioSource->PlayOneShot(noteMissedSoundLoader.audioSource->get_clip(), 1.0f + QSoundsConfig::Config.noteMissedSound_audioVolumeOffset); } } MAKE_HOOK_MATCH(BasicUIAudioManager_Start, &BasicUIAudioManager::Start, void, BasicUIAudioManager* self) { - if (!menuClickLoader.OriginalAudioSource) menuClickLoader.set_OriginalClip(self->clickSounds[0]); + if (!menuClickLoader.OriginalAudioSource) menuClickLoader.set_OriginalClip(self->_clickSounds[0]); - if(menuClickLoader.loaded && QSoundsConfig::Config.menuClick_Active) + if(menuClickLoader.loaded && Config.Sounds.MenuClick.Active) { menuClickArr = createAudioClipArray(menuClickLoader); - self->clickSounds = menuClickArr; + self->_clickSounds = menuClickArr; } BasicUIAudioManager_Start(self); } -//MAKE_HOOK_MATCH(FireworkItemController_Awake, &FireworkItemController::Awake, void, FireworkItemController* self) { -// if (!origFireworkSoundArr) origFireworkSoundArr = self->explosionClips; -// -// if(fireworkSoundLoader.loaded && QSoundsConfig::Config.firework_Active) -// { -// getLogger().debug("Setting custom Fireworks Sounds"); -// fireworkSoundArr = createAudioClipArray(fireworkSoundLoader); -// self->explosionClips = fireworkSoundArr; -// } -// else { -// getLogger().debug("Return default Fireworks Sounds"); -// self->explosionClips = origFireworkSoundArr; -// } -// FireworkItemController_Awake(self); -//} - // Replacing the function here, as replacing the AudioClips proves to be difficult MAKE_HOOK_MATCH(FireworkItemController_PlayExplosionSound, &FireworkItemController::PlayExplosionSound, void, FireworkItemController* self) { - if (fireworkSoundLoader.loaded && QSoundsConfig::Config.firework_Active) { - self->audioSource->set_clip(fireworkSoundLoader.getClip()); + if (fireworkSoundLoader.loaded && Config.Sounds.Firework.Active) { + self->_audioSource->set_clip(fireworkSoundLoader.getClip()); float pitch = 1.2f + (((float)rand()) / (float)RAND_MAX) * (0.8f - 1.2f); - self->audioSource->set_pitch(pitch); - self->audioSource->Play(); + self->_audioSource->set_pitch(pitch); + self->_audioSource->Play(); } else FireworkItemController_PlayExplosionSound(self); } MAKE_HOOK_MATCH(PauseMenuManager_MenuButtonPressed, &PauseMenuManager::MenuButtonPressed, void, PauseMenuManager* self) { if (noteMissedSoundLoader.loaded && - QSoundsConfig::Config.noteMissedSound_Active) { + Config.Sounds.NoteMissedSound.Active) { if (noteMissedSoundLoader.audioSource) noteMissedSoundLoader.audioSource->Stop(); - //noteMissedSoundLoader.audioSource->PlayOneShot(noteMissedSoundLoader.audioSource->get_clip(), 1.0f + QSoundsConfig::Config.noteMissedSound_audioVolumeOffset); } PauseMenuManager_MenuButtonPressed(self); } @@ -433,24 +413,34 @@ MAKE_HOOK_MATCH(SceneManager_Internal_ActiveSceneChanged, &SceneManager::Interna SceneManager_Internal_ActiveSceneChanged(previousActiveScene, newActiveScene); if (newActiveScene.IsValid()) { std::string sceneName = newActiveScene.get_name(); - getLogger().info("Scene found: %s", sceneName.data()); + getLogger().info("Scene found: {}", sceneName.data()); std::string questInit = "QuestInit"; - if(sceneName == questInit) QuestSounds::AudioClips::loadAudioClips(); + if(sceneName == questInit) { + try { + QuestSounds::AudioClips::loadAudioClips(); + } + catch (const std::exception& e) { + getLogger().error("Failed to load AudioClips: {}", e.what()); + } + } } } +std::string& GetConfigPath() { + static std::string configPath = Configuration::getConfigFilePath(modInfo); + return configPath; +} + QS_EXPORT void setup(CModInfo *info) { - *info = modInfo.to_c(); + info->id = MOD_ID; + info->version = VERSION; - info.id = MOD_ID; - info.version = VERSION; - modInfo = info; Paper::Logger::RegisterFileContextId(getLogger().tag); - getLogger().info("Modloader name: %s", Modloader::getInfo().name.c_str()); - getLogger().debug("Config Path is: %s", getConfig().getConfigFilePath(modInfo).c_str()); + getLogger().info("Modloader: {}", modloader::get_modloader_path().c_str()); + getLogger().debug("Config Path is: {}", getConfig().getConfigFilePath(modInfo).c_str()); getLogger().info("Loading Config"); getConfig(); getLogger().info("Completed setup!"); @@ -460,12 +450,25 @@ QS_EXPORT void late_load() { il2cpp_functions::Init(); - Logger& hkLog = getLogger(); + auto& hkLog = getLogger(); //custom_types::Register::RegisterType(); - custom_types::Register::AutoRegister(); + // custom_types::Register::AutoRegister(); - if(!LoadConfig()) SaveConfig(); + getLogger().info("Loading Config from file {}", GetConfigPath()); + + if(!fileexists(GetConfigPath())) { + if(!WriteToFile(GetConfigPath(), Config)) + getLogger().error("Failed to write config file!"); + } + + try { + ReadFromFile(GetConfigPath(), Config); + } catch(const std::exception& e) { + getLogger().error("Failed to read config: {}", e.what()); + } + + // if(!LoadConfig()) SaveConfig(); makeFolder(); getLogger().debug("Installing QuestSounds!"); INSTALL_HOOK(hkLog, SceneManager_Internal_ActiveSceneChanged); From d00f26112ff30d2a677b5ce47a077e727ddcfee5 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 22:29:25 +0200 Subject: [PATCH 21/55] Fix include path --- include/Config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Config.hpp b/include/Config.hpp index 4e21248..62aea20 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -1,5 +1,5 @@ #include "scotland2/shared/loader.hpp" -#include "rapidjson-macros\shared\macros.hpp" +#include "rapidjson-macros/shared/macros.hpp" #define SOUND_PATH_FORMAT "/sdcard/ModData/{}/Mods/QuestSounds/" // #define CONFIG_VERSION "SoundsConfig_v3" From 0bc58a7fe951fad127a5b73caf74d7f2449cb784 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 22:34:27 +0200 Subject: [PATCH 22/55] Temp rename because git doesn't see changed casing --- .../{AsyncAudiocliploader.hpp => AsyncAudioClipLoader_Temp.hpp} | 0 .../{AsyncAudiocliploader.cpp => AsyncAudioClipLoader_Temp.cpp} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename include/Utils/{AsyncAudiocliploader.hpp => AsyncAudioClipLoader_Temp.hpp} (100%) rename src/Utils/{AsyncAudiocliploader.cpp => AsyncAudioClipLoader_Temp.cpp} (100%) diff --git a/include/Utils/AsyncAudiocliploader.hpp b/include/Utils/AsyncAudioClipLoader_Temp.hpp similarity index 100% rename from include/Utils/AsyncAudiocliploader.hpp rename to include/Utils/AsyncAudioClipLoader_Temp.hpp diff --git a/src/Utils/AsyncAudiocliploader.cpp b/src/Utils/AsyncAudioClipLoader_Temp.cpp similarity index 100% rename from src/Utils/AsyncAudiocliploader.cpp rename to src/Utils/AsyncAudioClipLoader_Temp.cpp From 73f926cefa40b817af28afcdcf4063e884f19c64 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 22:35:01 +0200 Subject: [PATCH 23/55] Fix casing --- .../{AsyncAudioClipLoader_Temp.hpp => AsyncAudioClipLoader.hpp} | 0 .../{AsyncAudioClipLoader_Temp.cpp => AsyncAudioClipLoader.cpp} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename include/Utils/{AsyncAudioClipLoader_Temp.hpp => AsyncAudioClipLoader.hpp} (100%) rename src/Utils/{AsyncAudioClipLoader_Temp.cpp => AsyncAudioClipLoader.cpp} (100%) diff --git a/include/Utils/AsyncAudioClipLoader_Temp.hpp b/include/Utils/AsyncAudioClipLoader.hpp similarity index 100% rename from include/Utils/AsyncAudioClipLoader_Temp.hpp rename to include/Utils/AsyncAudioClipLoader.hpp diff --git a/src/Utils/AsyncAudioClipLoader_Temp.cpp b/src/Utils/AsyncAudioClipLoader.cpp similarity index 100% rename from src/Utils/AsyncAudioClipLoader_Temp.cpp rename to src/Utils/AsyncAudioClipLoader.cpp From 91e2448d1438e835d5db4d8bae5f1503f6e56223 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Fri, 19 Jul 2024 22:40:23 +0200 Subject: [PATCH 24/55] Fix build workflow qmod creation --- .github/workflows/BuildQSounds.yml | 2 +- .github/workflows/Release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/BuildQSounds.yml b/.github/workflows/BuildQSounds.yml index 8bce333..6f6613a 100644 --- a/.github/workflows/BuildQSounds.yml +++ b/.github/workflows/BuildQSounds.yml @@ -111,7 +111,7 @@ jobs: - name: Package QMOD run: | cd ${GITHUB_WORKSPACE} - ./QPM/qpm qmod zip -i ./build/ -i ./extern/libs/ ${module_id}_${version}.qmod + ./QPM/qpm qmod zip -i ./build/ -i ./extern/libs/ -i ./Examples/ ${module_id}_${version}.qmod - name: Upload non-debug artifact diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 85e3a58..12a9940 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -96,7 +96,7 @@ jobs: - name: Package QMOD run: | cd ${GITHUB_WORKSPACE} - ./QPM/qpm qmod zip -i ./build/ -i ./extern/libs/ ${module_id}_${version}.qmod + ./QPM/qpm qmod zip -i ./build/ -i ./extern/libs/ -i ./Examples/ ${module_id}_${version}.qmod - name: Release uses: softprops/action-gh-release@v1 From 44478e8767e7ebc2f1a221c2f2fcc203d62becd9 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sat, 20 Jul 2024 16:47:55 +0200 Subject: [PATCH 25/55] Small tweaks --- include/Utils/AsyncAudioClipLoader.hpp | 2 +- src/Utils/AsyncAudioClipLoader.cpp | 58 ++++++++++++-------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/include/Utils/AsyncAudioClipLoader.hpp b/include/Utils/AsyncAudioClipLoader.hpp index 9fec135..79165d0 100644 --- a/include/Utils/AsyncAudioClipLoader.hpp +++ b/include/Utils/AsyncAudioClipLoader.hpp @@ -35,7 +35,7 @@ namespace QuestSounds::Utils StringW loadPath; // custom_types::Helpers::Coroutine loadCoroutine; UnityEngine::GameObject* audioClipGO; - void audioClipCompleted(); + void audioClipCompleted(UnityEngine::AudioClip* audioClip); // StringW path; bool UsesUWR = false; System::Threading::Tasks::Task_1<::UnityW>* audioClipTask; diff --git a/src/Utils/AsyncAudioClipLoader.cpp b/src/Utils/AsyncAudioClipLoader.cpp index 2a48c61..b94e620 100644 --- a/src/Utils/AsyncAudioClipLoader.cpp +++ b/src/Utils/AsyncAudioClipLoader.cpp @@ -76,21 +76,26 @@ bool QuestSounds::Utils::AsyncAudioClipLoader::load() } //Stage 1 - if (!(filePath == QuestSounds::Config.Sounds.HitSound.FilePath) && filePath.ends_with(".ogg")) { + if (filePath.ends_with(".ogg") || filePath.ends_with(".wav")) { getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); UsesUWR = false; - loadPath = filePath; - if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) il2cpp_functions::Class_Init(classof(GlobalNamespace::MediaAsyncLoader*)); - // if (!mediaAsyncLoader) mediaAsyncLoader = ::il2cpp_utils::NewSpecific<::GlobalNamespace::MediaAsyncLoader*, il2cpp_utils::CreationType::Manual>(); + loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); + // Ensure MediaAsyncLoader is initialized + if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) { + getLogger().info("MediaAsyncLoader class not initialized, initializing it"); + il2cpp_functions::Class_Init(classof(GlobalNamespace::MediaAsyncLoader*)); + } + // We always create a new instance of MediaAsyncLoader to avoid audioclip loading issues audioClipTask = GlobalNamespace::MediaAsyncLoader::New_ctor()->LoadAudioClipFromFilePathAsync(loadPath); audioClipTask->GetAwaiter().OnCompleted(custom_types::MakeDelegate(std::function([this]() - { - audioClipCompleted(); + { + getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {} status is {}", filePath, (int)audioClipTask->get_Status()); + audioClipCompleted(audioClipTask->get_ResultOnSuccess()); }))); } else { - getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath {}", filePath.c_str()); + getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath {}", filePath); UsesUWR = true; if (filePath.starts_with("https://") || filePath.starts_with("http://")) { loadPath = filePath; @@ -121,48 +126,39 @@ custom_types::Helpers::Coroutine QuestSounds::Utils::AsyncAudioClipLoader::LoadA } else { while (!audioClipRequest->isDone); - audioClipCompleted(); + if (audioClipRequest->get_result() == UnityWebRequest::Result::Success) { + getLogger().info("UnityWebRequestMultimedia for file '{}' completed successfully", loadPath); + audioClipCompleted(UnityEngine::Networking::DownloadHandlerAudioClip::GetContent(audioClipRequest)); + } + else { + getLogger().error("UnityWebRequestMultimedia for file '{}' failed with result {}", loadPath, (int)audioClipRequest->get_result()); + } } co_return; } -void QuestSounds::Utils::AsyncAudioClipLoader::audioClipCompleted() +void QuestSounds::Utils::AsyncAudioClipLoader::audioClipCompleted(UnityEngine::AudioClip* audioClip) { // Stage 2 getLogger().info("Starting Stage 2"); - UnityEngine::AudioClip* temporaryClip = nullptr; - if (!this->UsesUWR) { - getLogger().info("UsesUWR is false, getting result from audioClipTask"); - getLogger().debug("Is Task null? {}", fmt::ptr(audioClipTask)); - getLogger().debug("Task Status is {}", (int)audioClipTask->get_Status()); - temporaryClip = this->audioClipTask->get_ResultOnSuccess(); - // gc_free_specific(this->audioClipTask); - // this->audioClipTask = nullptr; - } - else if (this->UsesUWR && audioClipRequest->get_result() == UnityWebRequest::Result::Success){ - getLogger().info("UsesUWR is true, getting result from audioClipRequest"); - getLogger().debug("Is Request null? {}", fmt::ptr(audioClipRequest)); - temporaryClip = UnityEngine::Networking::DownloadHandlerAudioClip::GetContent(audioClipRequest); // TODO: This method takes too long - } - if(temporaryClip != nullptr) + if(audioClip != nullptr) { - getLogger().info("TemporaryClip is not nullptr setting it to AudioSource for filepath {}", filePath); + getLogger().info("audioClip is not nullptr setting it to AudioSource for filepath {}", filePath); if (!this->audioClipGO) { - static ConstString goName = "AudioClipGO"; + static auto goName = ConstString("AudioClipGO"); audioClipGO = GameObject::New_ctor(goName); audioSource = audioClipGO->AddComponent(); UnityEngine::Object::DontDestroyOnLoad(audioClipGO); } audioSource->set_playOnAwake(false); - audioSource->set_clip(temporaryClip); + audioSource->set_clip(audioClip); audioSource->set_volume(0.6f); loaded = true; - getLogger().info("Stage 2 done with temporaryClip"); + getLogger().info("Stage 2 done with audioClip"); } else { - getLogger().error("Stage 2 failed with temporaryClip being nullptr {} Object FilePath: {}", fmt::ptr(temporaryClip), filePath.c_str()); - if (!UsesUWR) getLogger().error("Task Status was {}", (int)audioClipTask->get_Status()); + getLogger().error("Stage 2 failed with audioClip being nullptr {} Object FilePath: {}", fmt::ptr(audioClip), filePath); return; } // Finished } @@ -185,7 +181,7 @@ void QuestSounds::Utils::AsyncAudioClipLoader::set_OriginalClip(AudioClip* Origi // Stage 1 if (OriginalAudioClip != nullptr) { - static auto goName = "OrigAudioClipGO"; + static auto goName = ConstString("OrigAudioClipGO"); GameObject* audioClipGO = GameObject::New_ctor(goName); OriginalAudioSource = audioClipGO->AddComponent(); OriginalAudioSource->set_playOnAwake(false); From 29998889992d6f6d1ea747809d8f9325d477c319 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 17:31:00 +0200 Subject: [PATCH 26/55] Temp delete AsyncAudioClipLoader due to git windows having casing issues --- src/Utils/AsyncAudioClipLoader.cpp | 207 ----------------------------- 1 file changed, 207 deletions(-) delete mode 100644 src/Utils/AsyncAudioClipLoader.cpp diff --git a/src/Utils/AsyncAudioClipLoader.cpp b/src/Utils/AsyncAudioClipLoader.cpp deleted file mode 100644 index b94e620..0000000 --- a/src/Utils/AsyncAudioClipLoader.cpp +++ /dev/null @@ -1,207 +0,0 @@ -// #include "QSoundsConfig.hpp" -#include "Utils/AsyncAudioClipLoader.hpp" -#include "main.hpp" -#include "Config.hpp" -#include "ObjectInstances.hpp" - -#include -#include - -#include - -#include "custom-types/shared/delegate.hpp" -#include "bsml/shared/BSML/MainThreadScheduler.hpp" -#include "bsml/shared/BSML/SharedCoroutineStarter.hpp" - -#include "UnityEngine/Networking/DownloadHandlerAudioClip.hpp" -#include "UnityEngine/Networking/UnityWebRequestMultimedia.hpp" -using namespace UnityEngine::Networking; - -#include "System/Threading/Tasks/TaskStatus.hpp" -#include "System/Threading/Tasks/Task.hpp" -#include "System/Threading/Tasks/Task_1.hpp" -#include "System/Action_1.hpp" -using namespace System; - -#include "UnityEngine/AudioType.hpp" -#include "UnityEngine/AsyncOperation.hpp" -#include "UnityEngine/GameObject.hpp" -using namespace UnityEngine; - -int getAudioType(std::string path) { - if (path.ends_with(".ogg")) { - getLogger().debug("File is OGGVORBIS"); - return (int)UnityEngine::AudioType::OGGVORBIS; - } - else if (path.ends_with(".mp3") || path.ends_with(".mp2")) { - getLogger().debug("File is MPEG"); - return (int)UnityEngine::AudioType::MPEG; - } - else if (path.ends_with(".wav")) { - getLogger().debug("File is WAV"); - return (int)UnityEngine::AudioType::WAV; - } - else if (path.ends_with(".aiff") || path.ends_with(".aif")) { - getLogger().debug("File is AIFF"); - return (int)UnityEngine::AudioType::AIFF; - } - return 0; -} - -System::Threading::Tasks::Task_1* audioClipTask; -//bool NeedReload = false; - -bool QuestSounds::Utils::AsyncAudioClipLoader::load() -{ - loaded = false; - //Stage 0 - bool fileError; - getLogger().info("Starting Stage 0"); - getLogger().info("FilePath to check is {}", filePath.c_str()); - if (filePath.starts_with("https://") || filePath.starts_with("http://")) { - getLogger().info("Filepath is URL, skipping file checks and try loading it"); - fileError = true; - } - else { - // Checks if the given File in the config exists and - fileError = fileexists(filePath); - getLogger().info("File error is {}", fileError); - if (!fileError) - { - getLogger().error("File {} not found", filePath.c_str()); - getLogger().error("Stage 0 Failed"); - return false; - } - else { getLogger().info("Stage 0 Done with {}", filePath.c_str()); } - } - - //Stage 1 - if (filePath.ends_with(".ogg") || filePath.ends_with(".wav")) { - getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); - UsesUWR = false; - loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); - // Ensure MediaAsyncLoader is initialized - if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) { - getLogger().info("MediaAsyncLoader class not initialized, initializing it"); - il2cpp_functions::Class_Init(classof(GlobalNamespace::MediaAsyncLoader*)); - } - // We always create a new instance of MediaAsyncLoader to avoid audioclip loading issues - audioClipTask = GlobalNamespace::MediaAsyncLoader::New_ctor()->LoadAudioClipFromFilePathAsync(loadPath); - - audioClipTask->GetAwaiter().OnCompleted(custom_types::MakeDelegate(std::function([this]() - { - getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {} status is {}", filePath, (int)audioClipTask->get_Status()); - audioClipCompleted(audioClipTask->get_ResultOnSuccess()); - }))); - } - else { - getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath {}", filePath); - UsesUWR = true; - if (filePath.starts_with("https://") || filePath.starts_with("http://")) { - loadPath = filePath; - } - else { - // EscapeURL but also replaces spaces with %20 since the UnityWebRequest replaces spaces with + which causes unitys curl call to fail - loadPath = "file:///" + UnityEngine::Networking::UnityWebRequest::EscapeURL(std::regex_replace(filePath, std::regex(" "), "%20")); - } - audioType = getAudioType(filePath); - - BSML::SharedCoroutineStarter::get_instance()->StartCoroutine(custom_types::Helpers::CoroutineHelper::New(LoadAudioClip())); - } - getLogger().info("Stage 1 done with filepath {}", filePath.c_str()); - return true; -} - -custom_types::Helpers::Coroutine QuestSounds::Utils::AsyncAudioClipLoader::LoadAudioClip() -{ - getLogger().info("Stage 1: Running UnityWebRequestMultimedia for LoadPath {}", loadPath); - audioClipRequest = UnityEngine::Networking::UnityWebRequestMultimedia::GetAudioClip(loadPath, audioType); - audioClipAsync = audioClipRequest->SendWebRequest(); - audioClipAsync->allowSceneActivation = false; - co_yield reinterpret_cast(audioClipAsync); - - if (audioClipRequest->GetError() != UnityEngine::Networking::UnityWebRequest::UnityWebRequestError::OK) { - getLogger().error("UnityWebRequestMultimedia for file '{}' failed with error {}", loadPath, (int)audioClipRequest->GetError()); - co_return; - } - else { - while (!audioClipRequest->isDone); - if (audioClipRequest->get_result() == UnityWebRequest::Result::Success) { - getLogger().info("UnityWebRequestMultimedia for file '{}' completed successfully", loadPath); - audioClipCompleted(UnityEngine::Networking::DownloadHandlerAudioClip::GetContent(audioClipRequest)); - } - else { - getLogger().error("UnityWebRequestMultimedia for file '{}' failed with result {}", loadPath, (int)audioClipRequest->get_result()); - } - } - co_return; -} - -void QuestSounds::Utils::AsyncAudioClipLoader::audioClipCompleted(UnityEngine::AudioClip* audioClip) -{ - // Stage 2 - getLogger().info("Starting Stage 2"); - - if(audioClip != nullptr) - { - getLogger().info("audioClip is not nullptr setting it to AudioSource for filepath {}", filePath); - if (!this->audioClipGO) { - static auto goName = ConstString("AudioClipGO"); - audioClipGO = GameObject::New_ctor(goName); - audioSource = audioClipGO->AddComponent(); - UnityEngine::Object::DontDestroyOnLoad(audioClipGO); - } - audioSource->set_playOnAwake(false); - audioSource->set_clip(audioClip); - audioSource->set_volume(0.6f); - loaded = true; - getLogger().info("Stage 2 done with audioClip"); - } - else { - getLogger().error("Stage 2 failed with audioClip being nullptr {} Object FilePath: {}", fmt::ptr(audioClip), filePath); - return; - } // Finished -} - -UnityEngine::AudioClip* QuestSounds::Utils::AsyncAudioClipLoader::getClip() -{ - if(audioSource != nullptr && loaded) - { - getLogger().debug("AudioClip returned"); - return audioSource->get_clip(); - } else - { - getLogger().debug("nullptr returned: is AudioSource null: {}, is loaded: {}", fmt::ptr(audioSource), loaded); - return nullptr; - } -} - -void QuestSounds::Utils::AsyncAudioClipLoader::set_OriginalClip(AudioClip* OriginalAudioClip) -{ - // Stage 1 - if (OriginalAudioClip != nullptr) - { - static auto goName = ConstString("OrigAudioClipGO"); - GameObject* audioClipGO = GameObject::New_ctor(goName); - OriginalAudioSource = audioClipGO->AddComponent(); - OriginalAudioSource->set_playOnAwake(false); - OriginalAudioSource->set_clip(OriginalAudioClip); - UnityEngine::Object::DontDestroyOnLoad(audioClipGO); - getLogger().debug("Saved Original AudioClip"); - } - // Finished -} - -UnityEngine::AudioClip* QuestSounds::Utils::AsyncAudioClipLoader::get_OriginalClip() -{ - if (OriginalAudioSource != nullptr) - { - getLogger().debug("OrignalAudioClip returned"); - return OriginalAudioSource->get_clip(); - } - else - { - getLogger().debug("nullptr returned: is OriginalAudioSource null: {}", fmt::ptr(OriginalAudioSource)); - return nullptr; - } -} \ No newline at end of file From b9fa6372f747bb8dfb760fae4876f8325f5e02ee Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 17:32:48 +0200 Subject: [PATCH 27/55] Readd AsyncAudioClipLoader --- src/Utils/AsyncAudioClipLoader.cpp | 207 +++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 src/Utils/AsyncAudioClipLoader.cpp diff --git a/src/Utils/AsyncAudioClipLoader.cpp b/src/Utils/AsyncAudioClipLoader.cpp new file mode 100644 index 0000000..b94e620 --- /dev/null +++ b/src/Utils/AsyncAudioClipLoader.cpp @@ -0,0 +1,207 @@ +// #include "QSoundsConfig.hpp" +#include "Utils/AsyncAudioClipLoader.hpp" +#include "main.hpp" +#include "Config.hpp" +#include "ObjectInstances.hpp" + +#include +#include + +#include + +#include "custom-types/shared/delegate.hpp" +#include "bsml/shared/BSML/MainThreadScheduler.hpp" +#include "bsml/shared/BSML/SharedCoroutineStarter.hpp" + +#include "UnityEngine/Networking/DownloadHandlerAudioClip.hpp" +#include "UnityEngine/Networking/UnityWebRequestMultimedia.hpp" +using namespace UnityEngine::Networking; + +#include "System/Threading/Tasks/TaskStatus.hpp" +#include "System/Threading/Tasks/Task.hpp" +#include "System/Threading/Tasks/Task_1.hpp" +#include "System/Action_1.hpp" +using namespace System; + +#include "UnityEngine/AudioType.hpp" +#include "UnityEngine/AsyncOperation.hpp" +#include "UnityEngine/GameObject.hpp" +using namespace UnityEngine; + +int getAudioType(std::string path) { + if (path.ends_with(".ogg")) { + getLogger().debug("File is OGGVORBIS"); + return (int)UnityEngine::AudioType::OGGVORBIS; + } + else if (path.ends_with(".mp3") || path.ends_with(".mp2")) { + getLogger().debug("File is MPEG"); + return (int)UnityEngine::AudioType::MPEG; + } + else if (path.ends_with(".wav")) { + getLogger().debug("File is WAV"); + return (int)UnityEngine::AudioType::WAV; + } + else if (path.ends_with(".aiff") || path.ends_with(".aif")) { + getLogger().debug("File is AIFF"); + return (int)UnityEngine::AudioType::AIFF; + } + return 0; +} + +System::Threading::Tasks::Task_1* audioClipTask; +//bool NeedReload = false; + +bool QuestSounds::Utils::AsyncAudioClipLoader::load() +{ + loaded = false; + //Stage 0 + bool fileError; + getLogger().info("Starting Stage 0"); + getLogger().info("FilePath to check is {}", filePath.c_str()); + if (filePath.starts_with("https://") || filePath.starts_with("http://")) { + getLogger().info("Filepath is URL, skipping file checks and try loading it"); + fileError = true; + } + else { + // Checks if the given File in the config exists and + fileError = fileexists(filePath); + getLogger().info("File error is {}", fileError); + if (!fileError) + { + getLogger().error("File {} not found", filePath.c_str()); + getLogger().error("Stage 0 Failed"); + return false; + } + else { getLogger().info("Stage 0 Done with {}", filePath.c_str()); } + } + + //Stage 1 + if (filePath.ends_with(".ogg") || filePath.ends_with(".wav")) { + getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); + UsesUWR = false; + loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); + // Ensure MediaAsyncLoader is initialized + if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) { + getLogger().info("MediaAsyncLoader class not initialized, initializing it"); + il2cpp_functions::Class_Init(classof(GlobalNamespace::MediaAsyncLoader*)); + } + // We always create a new instance of MediaAsyncLoader to avoid audioclip loading issues + audioClipTask = GlobalNamespace::MediaAsyncLoader::New_ctor()->LoadAudioClipFromFilePathAsync(loadPath); + + audioClipTask->GetAwaiter().OnCompleted(custom_types::MakeDelegate(std::function([this]() + { + getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {} status is {}", filePath, (int)audioClipTask->get_Status()); + audioClipCompleted(audioClipTask->get_ResultOnSuccess()); + }))); + } + else { + getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath {}", filePath); + UsesUWR = true; + if (filePath.starts_with("https://") || filePath.starts_with("http://")) { + loadPath = filePath; + } + else { + // EscapeURL but also replaces spaces with %20 since the UnityWebRequest replaces spaces with + which causes unitys curl call to fail + loadPath = "file:///" + UnityEngine::Networking::UnityWebRequest::EscapeURL(std::regex_replace(filePath, std::regex(" "), "%20")); + } + audioType = getAudioType(filePath); + + BSML::SharedCoroutineStarter::get_instance()->StartCoroutine(custom_types::Helpers::CoroutineHelper::New(LoadAudioClip())); + } + getLogger().info("Stage 1 done with filepath {}", filePath.c_str()); + return true; +} + +custom_types::Helpers::Coroutine QuestSounds::Utils::AsyncAudioClipLoader::LoadAudioClip() +{ + getLogger().info("Stage 1: Running UnityWebRequestMultimedia for LoadPath {}", loadPath); + audioClipRequest = UnityEngine::Networking::UnityWebRequestMultimedia::GetAudioClip(loadPath, audioType); + audioClipAsync = audioClipRequest->SendWebRequest(); + audioClipAsync->allowSceneActivation = false; + co_yield reinterpret_cast(audioClipAsync); + + if (audioClipRequest->GetError() != UnityEngine::Networking::UnityWebRequest::UnityWebRequestError::OK) { + getLogger().error("UnityWebRequestMultimedia for file '{}' failed with error {}", loadPath, (int)audioClipRequest->GetError()); + co_return; + } + else { + while (!audioClipRequest->isDone); + if (audioClipRequest->get_result() == UnityWebRequest::Result::Success) { + getLogger().info("UnityWebRequestMultimedia for file '{}' completed successfully", loadPath); + audioClipCompleted(UnityEngine::Networking::DownloadHandlerAudioClip::GetContent(audioClipRequest)); + } + else { + getLogger().error("UnityWebRequestMultimedia for file '{}' failed with result {}", loadPath, (int)audioClipRequest->get_result()); + } + } + co_return; +} + +void QuestSounds::Utils::AsyncAudioClipLoader::audioClipCompleted(UnityEngine::AudioClip* audioClip) +{ + // Stage 2 + getLogger().info("Starting Stage 2"); + + if(audioClip != nullptr) + { + getLogger().info("audioClip is not nullptr setting it to AudioSource for filepath {}", filePath); + if (!this->audioClipGO) { + static auto goName = ConstString("AudioClipGO"); + audioClipGO = GameObject::New_ctor(goName); + audioSource = audioClipGO->AddComponent(); + UnityEngine::Object::DontDestroyOnLoad(audioClipGO); + } + audioSource->set_playOnAwake(false); + audioSource->set_clip(audioClip); + audioSource->set_volume(0.6f); + loaded = true; + getLogger().info("Stage 2 done with audioClip"); + } + else { + getLogger().error("Stage 2 failed with audioClip being nullptr {} Object FilePath: {}", fmt::ptr(audioClip), filePath); + return; + } // Finished +} + +UnityEngine::AudioClip* QuestSounds::Utils::AsyncAudioClipLoader::getClip() +{ + if(audioSource != nullptr && loaded) + { + getLogger().debug("AudioClip returned"); + return audioSource->get_clip(); + } else + { + getLogger().debug("nullptr returned: is AudioSource null: {}, is loaded: {}", fmt::ptr(audioSource), loaded); + return nullptr; + } +} + +void QuestSounds::Utils::AsyncAudioClipLoader::set_OriginalClip(AudioClip* OriginalAudioClip) +{ + // Stage 1 + if (OriginalAudioClip != nullptr) + { + static auto goName = ConstString("OrigAudioClipGO"); + GameObject* audioClipGO = GameObject::New_ctor(goName); + OriginalAudioSource = audioClipGO->AddComponent(); + OriginalAudioSource->set_playOnAwake(false); + OriginalAudioSource->set_clip(OriginalAudioClip); + UnityEngine::Object::DontDestroyOnLoad(audioClipGO); + getLogger().debug("Saved Original AudioClip"); + } + // Finished +} + +UnityEngine::AudioClip* QuestSounds::Utils::AsyncAudioClipLoader::get_OriginalClip() +{ + if (OriginalAudioSource != nullptr) + { + getLogger().debug("OrignalAudioClip returned"); + return OriginalAudioSource->get_clip(); + } + else + { + getLogger().debug("nullptr returned: is OriginalAudioSource null: {}", fmt::ptr(OriginalAudioSource)); + return nullptr; + } +} \ No newline at end of file From 3f4905705ae4f6631d4aef79969e1f07c587f529 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 17:39:09 +0200 Subject: [PATCH 28/55] Reimplement fix for HitSounds not playing more than once When HitSounds are loaded using MediaAsyncLoader they for some reason only play once and then stop working. Also I hate git for windows for not being able to commit with the right filename when tring to only stage a block within a file instead of the whole file --- src/Utils/AsyncAudioClipLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/AsyncAudioClipLoader.cpp b/src/Utils/AsyncAudioClipLoader.cpp index b94e620..dd9cd8d 100644 --- a/src/Utils/AsyncAudioClipLoader.cpp +++ b/src/Utils/AsyncAudioClipLoader.cpp @@ -76,7 +76,7 @@ bool QuestSounds::Utils::AsyncAudioClipLoader::load() } //Stage 1 - if (filePath.ends_with(".ogg") || filePath.ends_with(".wav")) { + if ((filePath.ends_with(".ogg") || filePath.ends_with(".wav")) && filePath != QuestSounds::Config.Sounds.HitSound.FilePath) { getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); UsesUWR = false; loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); From 0e4ace7b29df134708aecdc574c78132683d251e Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 17:43:49 +0200 Subject: [PATCH 29/55] Use ArrayW --- include/AudioClips.hpp | 12 +- src/main.cpp | 982 ++++++++++++++++++++--------------------- 2 files changed, 492 insertions(+), 502 deletions(-) diff --git a/include/AudioClips.hpp b/include/AudioClips.hpp index 50300aa..ab86842 100644 --- a/include/AudioClips.hpp +++ b/include/AudioClips.hpp @@ -14,13 +14,13 @@ namespace QuestSounds::AudioClips { levelClearedLoader, levelFailedLoader, lobbyAmbienceLoader; // Added for LobbyMusic - extern Array * hitSoundArr, // hitSoundArray - * badHitSoundArr, // badHitSoundArray - * menuClickArr, - * fireworkSoundArr; + extern ::ArrayW<::UnityW<::UnityEngine::AudioClip>> hitSoundArr, // hitSoundArray + badHitSoundArr, // badHitSoundArray + menuClickArr, + fireworkSoundArr; - extern Array * origMenuClickArr; + extern ::ArrayW<::UnityW<::UnityEngine::AudioClip>> origMenuClickArr; extern void loadAudioClips(); - extern Array* createAudioClipArray(QuestSounds::Utils::AsyncAudioClipLoader clipLoader, bool GetOriginalClip = false); + extern ::ArrayW<::UnityW<::UnityEngine::AudioClip>> createAudioClipArray(QuestSounds::Utils::AsyncAudioClipLoader clipLoader, bool GetOriginalClip = false); } diff --git a/src/main.cpp b/src/main.cpp index e9bbe01..9f87166 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,496 +1,486 @@ -#include "main.hpp" -#include "Utils/AsyncAudioClipLoader.hpp" -#include "Config.hpp" -#include "AudioClips.hpp" -using namespace QuestSounds::AudioClips; - -#include "GlobalNamespace/ResultsViewController.hpp" -#include "GlobalNamespace/SongPreviewPlayer.hpp" -#include "GlobalNamespace/NoteCutSoundEffectManager.hpp" -#include "GlobalNamespace/NoteCutSoundEffect.hpp" -#include "GlobalNamespace/NoteController.hpp" -#include "GlobalNamespace/NoteData.hpp" -#include "GlobalNamespace/BasicUIAudioManager.hpp" -#include "GlobalNamespace/FireworkItemController.hpp" -#include "GlobalNamespace/GameServerLobbyFlowCoordinator.hpp" -#include "GlobalNamespace/MultiplayerModeSelectionFlowCoordinator.hpp" -#include "GlobalNamespace/BeatmapObjectManager.hpp" -#include "GlobalNamespace/PauseMenuManager.hpp" - -#include "GlobalNamespace/FileHelpers.hpp" - -#include "GlobalNamespace/LevelCompletionResults.hpp" -using namespace GlobalNamespace; - -#include "System/Action.hpp" - -#include "UnityEngine/SceneManagement/Scene.hpp" -#include "UnityEngine/SceneManagement/SceneManager.hpp" -#include "UnityEngine/MonoBehaviour.hpp" -#include "UnityEngine/WaitForSeconds.hpp" -#include "UnityEngine/Time.hpp" -using namespace UnityEngine::SceneManagement; - -// TODO BSML - -// #include "ViewControllers/MenuSdListViewController.hpp" -// #include "ViewControllers/HitSdListViewController.hpp" -// #include "ViewControllers/MenuClickSdListViewController.hpp" -// #include "ViewControllers/BadHitSdListViewController.hpp" -// #include "ViewControllers/FireworkSdListViewController.hpp" -// #include "ViewControllers/LevelClearedSdListViewController.hpp" -// #include "ViewControllers/LobbyMusicSdListViewController.hpp" -// #include "ViewControllers/ConfigViewController.hpp" -// #include "QSoundsFlowCoordinator.hpp" -using namespace QuestSounds; - -// #include "custom-types/shared/register.hpp" -// using namespace custom_types; - -#define RAPIDJSON_HAS_STDSTRING 1 - -inline modloader::ModInfo modInfo = {MOD_ID, VERSION, 0}; // Stores the ID and version of our mod, and is sent to the modloader upon startup - -Configuration& getConfig() { - static Configuration config(modInfo); - return config; -} - -// TODO: Proper paper logging -Paper::ConstLoggerContext<12UL>& getLogger() { - static auto fastContext = Paper::Logger::WithContext(); - return fastContext; -} - -void makeFolder() -{ - if (!direxists(Config.Sounds.MenuMusic.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.MenuMusic.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make MenuMusic Folder path!"); - } - } - - if (!direxists(Config.Sounds.HitSound.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.HitSound.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make HitSound Folder path!"); - } - } - - if (!direxists(Config.Sounds.BadHitSound.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.BadHitSound.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make BadHitSound Folder path!"); - } - } - - if (!direxists(Config.Sounds.NoteMissedSound.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.NoteMissedSound.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make NoteMissedSound Folder path!"); - } - } - - if (!direxists(Config.Sounds.MenuClick.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.MenuClick.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make MenuClick Folder path!"); - } - } - - if (!direxists(Config.Sounds.Firework.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.Firework.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make FireworkSound Folder path!"); - } - } - - if (!direxists(Config.Sounds.LevelCleared.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.LevelCleared.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make LevelCleared Folder path!"); - } - } - - if (!direxists(Config.Sounds.LevelFailed.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.LevelFailed.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make LevelFailed Folder path!"); - } - } - - if (!direxists(Config.Sounds.LobbyMusic.FolderPath.c_str())) - { - int makePath = mkpath(Config.Sounds.LobbyMusic.FolderPath.c_str()); - if (makePath == -1) - { - getLogger().error("Failed to make LobbyMusic Folder path!"); - } - } -} - - - -namespace QuestSounds::AudioClips { -/*audioClipLoader::loader*/ -QuestSounds::Utils::AsyncAudioClipLoader hitSoundLoader, // hitSound - badHitSoundLoader, // badHitSound - noteMissedSoundLoader, - menuMusicLoader, // menuMusic - menuClickLoader, - fireworkSoundLoader, - levelClearedLoader, - levelFailedLoader, // For LevelFailed sound - lobbyAmbienceLoader; // Added for LobbyMusic -Array * hitSoundArr, // hitSoundArray - * badHitSoundArr, // badHitSoundArray - * menuClickArr, - * fireworkSoundArr; - - -Array* origMenuClickArr; - - void loadAudioClips() - { - hitSoundLoader.filePath = Config.Sounds.HitSound.FilePath; - badHitSoundLoader.filePath = Config.Sounds.BadHitSound.FilePath; - noteMissedSoundLoader.filePath = Config.Sounds.NoteMissedSound.FilePath; - menuMusicLoader.filePath = Config.Sounds.MenuMusic.FilePath; - menuClickLoader.filePath = Config.Sounds.MenuClick.FilePath; - fireworkSoundLoader.filePath = Config.Sounds.Firework.FilePath; - levelClearedLoader.filePath = Config.Sounds.LevelCleared.FilePath; - levelFailedLoader.filePath = Config.Sounds.LevelFailed.FilePath; - lobbyAmbienceLoader.filePath = Config.Sounds.LobbyMusic.FilePath; // Added for LobbyMusic - - menuMusicLoader.load(); - menuClickLoader.load(); - if (Config.Sounds.HitSound.Active) hitSoundLoader.load(); - if (Config.Sounds.BadHitSound.Active) badHitSoundLoader.load(); - if (Config.Sounds.NoteMissedSound.Active) noteMissedSoundLoader.load(); - if (Config.Sounds.Firework.Active) fireworkSoundLoader.load(); - if (Config.Sounds.LevelCleared.Active) levelClearedLoader.load(); - if (Config.Sounds.LevelFailed.Active) levelFailedLoader.load(); - if (Config.Sounds.LobbyMusic.Active) lobbyAmbienceLoader.load(); // Added for LobbyMusic - } - // Creates an Array, of AudioClips - Array* createAudioClipArray(QuestSounds::Utils::AsyncAudioClipLoader clipLoader, bool GetOriginalClip) - { - UnityEngine::AudioClip* tempClip; - if (!GetOriginalClip) tempClip = clipLoader.getClip(); - else tempClip = clipLoader.get_OriginalClip(); - auto* temporaryArray = Array::New(tempClip); - //temporaryArray->values[0] = tempClip; - return temporaryArray; - //return ArrayW({ tempClip }); - } -} - -MAKE_HOOK_MATCH(ResultsViewController_DidActivate, &ResultsViewController::DidActivate, void, ResultsViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { - if (firstActivation && addedToHierarchy && !levelClearedLoader.OriginalAudioSource) { - levelClearedLoader.set_OriginalClip(self->_levelClearedAudioClip); - } - if (self->_levelCompletionResults->levelEndStateType == LevelCompletionResults::LevelEndStateType::Failed) { - self->_songPreviewPlayer->StopAllCoroutines(); - if (levelFailedLoader.loaded && addedToHierarchy && Config.Sounds.LevelFailed.Active) { - UnityEngine::AudioClip* FailedSound = levelFailedLoader.getClip(); - float length = FailedSound->get_length(); - getLogger().debug("Duration of LevelFailed Sound: {}", length); - if (length > 7.0f) { - getLogger().info("Long LevelFailedSound"); - self->_songPreviewPlayer->CrossfadeTo(FailedSound, -4.0f, 0.0f, length, nullptr); - } - else { - getLogger().info("Short LevelFailedSound"); - self->_songPreviewPlayer->FadeOut(0.1f); - self->_songPreviewPlayer->_fadeSpeed = self->_songPreviewPlayer->_fadeInSpeed; - getLogger().debug("volume: {}", self->_songPreviewPlayer->_volume); - getLogger().debug("AmbientVolume: {}", self->_songPreviewPlayer->_ambientVolumeScale); - getLogger().debug("Set Volume: {}", self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); - - levelFailedLoader.audioSource->set_volume(self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); - self->_songPreviewPlayer->StartCoroutine(self->_songPreviewPlayer->CrossFadeAfterDelayCoroutine(length - 1.2f)); - levelFailedLoader.audioSource->Play(); - } - } - } - else { - if (levelClearedLoader.loaded && addedToHierarchy && Config.Sounds.LevelCleared.Active) - { - UnityEngine::AudioClip* audioClip = levelClearedLoader.getClip(); - self->_levelClearedAudioClip = audioClip; - } - else { - self->_levelClearedAudioClip = levelClearedLoader.get_OriginalClip(); - } - } - ResultsViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); -} - -MAKE_HOOK_MATCH(ResultsViewController_RestartButtonPressed, &ResultsViewController::RestartButtonPressed, void, ResultsViewController* self) { - if (levelFailedLoader.loaded && levelFailedLoader.audioSource->get_isPlaying()) { - levelFailedLoader.audioSource->Stop(); - } - ResultsViewController_RestartButtonPressed(self); -} - -MAKE_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, SongPreviewPlayer* self) { - getLogger().info("is it true: %i", menuMusicLoader.loaded); - - if (!menuMusicLoader.OriginalAudioSource) { - menuMusicLoader.set_OriginalClip(self->_defaultAudioClip); - } - - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) - { - getLogger().debug("Overriding MenuMusic Audio"); - UnityEngine::AudioClip* audioClip = menuMusicLoader.getClip(); - if (audioClip != nullptr) - self->_defaultAudioClip = audioClip; - } - else { - getLogger().debug("Loading MenuMusic Audio normally: isLoaded='{}' isActive='{}'", menuMusicLoader.loaded, Config.Sounds.MenuMusic.Active); - self->_defaultAudioClip = menuMusicLoader.get_OriginalClip(); - } - SongPreviewPlayer_OnEnable(self); -} - -MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlowCoordinator::DidActivate, void, GameServerLobbyFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) -{ - getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); - if (!lobbyAmbienceLoader.OriginalAudioSource) lobbyAmbienceLoader.set_OriginalClip(self->_ambienceAudioClip); - - if (lobbyAmbienceLoader.loaded && Config.Sounds.LobbyMusic.Active) - { - getLogger().debug("Overwriting LobbyAmbience Audio"); - self->_ambienceAudioClip = lobbyAmbienceLoader.getClip(); - } - else { - self->_ambienceAudioClip = lobbyAmbienceLoader.get_OriginalClip(); - } - GameServerLobbyFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); -} - -MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidDeactivate, &GameServerLobbyFlowCoordinator::DidDeactivate, void, GameServerLobbyFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) -{ - getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) - { - getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); - self->_ambienceAudioClip = menuMusicLoader.getClip(); - } - else { - self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); - } - GameServerLobbyFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); -} - -MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidActivate, &MultiplayerModeSelectionFlowCoordinator::DidActivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) -{ - getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidActivate"); - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) - { - getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); - self->_ambienceAudioClip = menuMusicLoader.getClip(); - } - else { - self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); - } - MultiplayerModeSelectionFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); // This has to be ran last, otherwise it will not work correctly -} - -MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidDeactivate, &MultiplayerModeSelectionFlowCoordinator::DidDeactivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) -{ - getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidDeactivate"); - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) - { - self->_ambienceAudioClip = menuMusicLoader.getClip(); - } - else { - self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); - } - - MultiplayerModeSelectionFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); -} - -#ifdef DEBUG -MAKE_HOOK_MATCH(FileHelpers_GetEscapedURLForFilePath, &FileHelpers::GetEscapedURLForFilePath, StringW, StringW filePath) { - return StringW("file://" + filePath); -} -#endif - -MAKE_HOOK_MATCH(NoteCutSoundEffectManager_Start, &NoteCutSoundEffectManager::Start, void, NoteCutSoundEffectManager* self) { - if(hitSoundLoader.loaded && Config.Sounds.HitSound.Active) - { - hitSoundArr = createAudioClipArray(hitSoundLoader); - self->_longCutEffectsAudioClips = hitSoundArr; - self->_shortCutEffectsAudioClips = hitSoundArr; - getLogger().debug("NoteCutSoundEffectManager_Start: Loaded hitSoundArray"); - } - else { - getLogger().debug("NoteCutSoundEffectManager_Start: Loading normally"); - } - getLogger().debug("audioSamplesBeatAlignOffset was: {}", self->_audioSamplesBeatAlignOffset); - if (Config.Sounds.HitSound.BeatOffset.has_value()) - self->_audioSamplesBeatAlignOffset = Config.Sounds.HitSound.BeatOffset.value(); - getLogger().debug("audioSamplesBeatAlignOffset changed to: {}", self->_audioSamplesBeatAlignOffset); - NoteCutSoundEffectManager_Start(self); - getLogger().debug("Beatalign offset is: {}", self->_beatAlignOffset); -} - -MAKE_HOOK_MATCH(NoteCutSoundEffect_Awake, &NoteCutSoundEffect::Awake, void, NoteCutSoundEffect* self) { - if (hitSoundLoader.loaded && Config.Sounds.HitSound.Active) { - self->_goodCutVolume += Config.Sounds.HitSound.VolumeOffset.value_or(0.0f); - } - - if(badHitSoundLoader.loaded && Config.Sounds.BadHitSound.Active) - { - badHitSoundArr = createAudioClipArray(badHitSoundLoader); - self->_badCutSoundEffectAudioClips = badHitSoundArr; - self->_badCutVolume += Config.Sounds.BadHitSound.VolumeOffset.value_or(0.0f); - } - NoteCutSoundEffect_Awake(self); -} - -MAKE_HOOK_MATCH(BeatmapObjectManager_HandleNoteWasMissed, &BeatmapObjectManager::HandleNoteControllerNoteWasMissed, void, BeatmapObjectManager* self, NoteController* noteController) { - BeatmapObjectManager_HandleNoteWasMissed(self, noteController); - if (noteMissedSoundLoader.loaded && - Config.Sounds.NoteMissedSound.Active && - noteController->get_noteData()->get_scoringType() != NoteData::ScoringType::Ignore && - noteController->get_noteData()->get_gameplayType() != NoteData::GameplayType::Bomb) { - noteMissedSoundLoader.audioSource->set_volume(0.5f + Config.Sounds.NoteMissedSound.VolumeOffset.value_or(0.0f)); - noteMissedSoundLoader.audioSource->Play(); - } -} - -MAKE_HOOK_MATCH(BasicUIAudioManager_Start, &BasicUIAudioManager::Start, void, BasicUIAudioManager* self) { - if (!menuClickLoader.OriginalAudioSource) menuClickLoader.set_OriginalClip(self->_clickSounds[0]); - - if(menuClickLoader.loaded && Config.Sounds.MenuClick.Active) - { - menuClickArr = createAudioClipArray(menuClickLoader); - self->_clickSounds = menuClickArr; - } - BasicUIAudioManager_Start(self); -} - -// Replacing the function here, as replacing the AudioClips proves to be difficult -MAKE_HOOK_MATCH(FireworkItemController_PlayExplosionSound, &FireworkItemController::PlayExplosionSound, void, FireworkItemController* self) { - if (fireworkSoundLoader.loaded && Config.Sounds.Firework.Active) { - self->_audioSource->set_clip(fireworkSoundLoader.getClip()); - float pitch = 1.2f + (((float)rand()) / (float)RAND_MAX) * (0.8f - 1.2f); - self->_audioSource->set_pitch(pitch); - self->_audioSource->Play(); - } - else FireworkItemController_PlayExplosionSound(self); -} - -MAKE_HOOK_MATCH(PauseMenuManager_MenuButtonPressed, &PauseMenuManager::MenuButtonPressed, void, PauseMenuManager* self) { - if (noteMissedSoundLoader.loaded && - Config.Sounds.NoteMissedSound.Active) { - if (noteMissedSoundLoader.audioSource) noteMissedSoundLoader.audioSource->Stop(); - } - PauseMenuManager_MenuButtonPressed(self); -} - -MAKE_HOOK_MATCH(SceneManager_Internal_ActiveSceneChanged, &SceneManager::Internal_ActiveSceneChanged, void, Scene previousActiveScene, Scene newActiveScene) { - SceneManager_Internal_ActiveSceneChanged(previousActiveScene, newActiveScene); - if (newActiveScene.IsValid()) { - std::string sceneName = newActiveScene.get_name(); - getLogger().info("Scene found: {}", sceneName.data()); - - std::string questInit = "QuestInit"; - if(sceneName == questInit) { - try { - QuestSounds::AudioClips::loadAudioClips(); - } - catch (const std::exception& e) { - getLogger().error("Failed to load AudioClips: {}", e.what()); - } - } - } -} - -std::string& GetConfigPath() { - static std::string configPath = Configuration::getConfigFilePath(modInfo); - return configPath; -} - -QS_EXPORT void setup(CModInfo *info) { - info->id = MOD_ID; - info->version = VERSION; - - - Paper::Logger::RegisterFileContextId(getLogger().tag); - - getLogger().info("Modloader: {}", modloader::get_modloader_path().c_str()); - getLogger().debug("Config Path is: {}", getConfig().getConfigFilePath(modInfo).c_str()); - getLogger().info("Loading Config"); - getConfig(); - getLogger().info("Completed setup!"); -} - -QS_EXPORT void late_load() -{ - il2cpp_functions::Init(); - - auto& hkLog = getLogger(); - - //custom_types::Register::RegisterType(); - // custom_types::Register::AutoRegister(); - - getLogger().info("Loading Config from file {}", GetConfigPath()); - - if(!fileexists(GetConfigPath())) { - if(!WriteToFile(GetConfigPath(), Config)) - getLogger().error("Failed to write config file!"); - } - - try { - ReadFromFile(GetConfigPath(), Config); - } catch(const std::exception& e) { - getLogger().error("Failed to read config: {}", e.what()); - } - - // if(!LoadConfig()) SaveConfig(); - makeFolder(); - getLogger().debug("Installing QuestSounds!"); - INSTALL_HOOK(hkLog, SceneManager_Internal_ActiveSceneChanged); - INSTALL_HOOK(hkLog, PauseMenuManager_MenuButtonPressed); - INSTALL_HOOK(hkLog, SongPreviewPlayer_OnEnable); - INSTALL_HOOK(hkLog, NoteCutSoundEffectManager_Start); - INSTALL_HOOK(hkLog, NoteCutSoundEffect_Awake); - INSTALL_HOOK(hkLog, BeatmapObjectManager_HandleNoteWasMissed); - INSTALL_HOOK(hkLog, BasicUIAudioManager_Start); - INSTALL_HOOK(hkLog, ResultsViewController_DidActivate); - INSTALL_HOOK(hkLog, ResultsViewController_RestartButtonPressed); - INSTALL_HOOK(hkLog, FireworkItemController_PlayExplosionSound) - INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music - INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music - INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music - INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music - // #ifdef DEBUG - // auto ModList = Modloader::getMods(); - // if (ModList.find("SongLoader") == ModList.end()) { - // getLogger().info("SongLoader missing, installing FilePath check"); - // INSTALL_HOOK(hkLog, FileHelpers_GetEscapedURLForFilePath); - // } - // #endif - getLogger().debug("Installed QuestSounds!"); -} +#include "main.hpp" +#include "Utils/AsyncAudioClipLoader.hpp" +#include "Config.hpp" +#include "AudioClips.hpp" +using namespace QuestSounds::AudioClips; + +#include "GlobalNamespace/ResultsViewController.hpp" +#include "GlobalNamespace/SongPreviewPlayer.hpp" +#include "GlobalNamespace/NoteCutSoundEffectManager.hpp" +#include "GlobalNamespace/NoteCutSoundEffect.hpp" +#include "GlobalNamespace/NoteController.hpp" +#include "GlobalNamespace/NoteData.hpp" +#include "GlobalNamespace/BasicUIAudioManager.hpp" +#include "GlobalNamespace/FireworkItemController.hpp" +#include "GlobalNamespace/GameServerLobbyFlowCoordinator.hpp" +#include "GlobalNamespace/MultiplayerModeSelectionFlowCoordinator.hpp" +#include "GlobalNamespace/BeatmapObjectManager.hpp" +#include "GlobalNamespace/PauseMenuManager.hpp" + +#include "GlobalNamespace/FileHelpers.hpp" + +#include "GlobalNamespace/LevelCompletionResults.hpp" +using namespace GlobalNamespace; + +#include "System/Action.hpp" + +#include "UnityEngine/SceneManagement/Scene.hpp" +#include "UnityEngine/SceneManagement/SceneManager.hpp" +#include "UnityEngine/MonoBehaviour.hpp" +#include "UnityEngine/WaitForSeconds.hpp" +#include "UnityEngine/Time.hpp" +using namespace UnityEngine::SceneManagement; + +// TODO BSML + +// #include "ViewControllers/MenuSdListViewController.hpp" +// #include "ViewControllers/HitSdListViewController.hpp" +// #include "ViewControllers/MenuClickSdListViewController.hpp" +// #include "ViewControllers/BadHitSdListViewController.hpp" +// #include "ViewControllers/FireworkSdListViewController.hpp" +// #include "ViewControllers/LevelClearedSdListViewController.hpp" +// #include "ViewControllers/LobbyMusicSdListViewController.hpp" +// #include "ViewControllers/ConfigViewController.hpp" +// #include "QSoundsFlowCoordinator.hpp" +using namespace QuestSounds; + +// #include "custom-types/shared/register.hpp" +// using namespace custom_types; + +#define RAPIDJSON_HAS_STDSTRING 1 + +inline modloader::ModInfo modInfo = {MOD_ID, VERSION, 0}; + +// TODO: Proper paper logging +Paper::ConstLoggerContext<12UL>& getLogger() { + static auto fastContext = Paper::Logger::WithContext(); + return fastContext; +} + +void makeFolder() +{ + if (!direxists(Config.Sounds.MenuMusic.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.MenuMusic.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make MenuMusic Folder path!"); + } + } + + if (!direxists(Config.Sounds.HitSound.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.HitSound.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make HitSound Folder path!"); + } + } + + if (!direxists(Config.Sounds.BadHitSound.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.BadHitSound.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make BadHitSound Folder path!"); + } + } + + if (!direxists(Config.Sounds.NoteMissedSound.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.NoteMissedSound.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make NoteMissedSound Folder path!"); + } + } + + if (!direxists(Config.Sounds.MenuClick.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.MenuClick.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make MenuClick Folder path!"); + } + } + + if (!direxists(Config.Sounds.Firework.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.Firework.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make FireworkSound Folder path!"); + } + } + + if (!direxists(Config.Sounds.LevelCleared.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.LevelCleared.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make LevelCleared Folder path!"); + } + } + + if (!direxists(Config.Sounds.LevelFailed.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.LevelFailed.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make LevelFailed Folder path!"); + } + } + + if (!direxists(Config.Sounds.LobbyMusic.FolderPath.c_str())) + { + int makePath = mkpath(Config.Sounds.LobbyMusic.FolderPath.c_str()); + if (makePath == -1) + { + getLogger().error("Failed to make LobbyMusic Folder path!"); + } + } +} + + + +namespace QuestSounds::AudioClips { +/*audioClipLoader::loader*/ +QuestSounds::Utils::AsyncAudioClipLoader hitSoundLoader, // hitSound + badHitSoundLoader, // badHitSound + noteMissedSoundLoader, + menuMusicLoader, // menuMusic + menuClickLoader, + fireworkSoundLoader, + levelClearedLoader, + levelFailedLoader, // For LevelFailed sound + lobbyAmbienceLoader; // Added for LobbyMusic +::ArrayW<::UnityW<::UnityEngine::AudioClip>> hitSoundArr, // hitSoundArray + badHitSoundArr, // badHitSoundArray + menuClickArr, + fireworkSoundArr; + + +::ArrayW<::UnityW<::UnityEngine::AudioClip>> origMenuClickArr; + + void loadAudioClips() + { + hitSoundLoader.filePath = Config.Sounds.HitSound.FilePath; + badHitSoundLoader.filePath = Config.Sounds.BadHitSound.FilePath; + noteMissedSoundLoader.filePath = Config.Sounds.NoteMissedSound.FilePath; + menuMusicLoader.filePath = Config.Sounds.MenuMusic.FilePath; + menuClickLoader.filePath = Config.Sounds.MenuClick.FilePath; + fireworkSoundLoader.filePath = Config.Sounds.Firework.FilePath; + levelClearedLoader.filePath = Config.Sounds.LevelCleared.FilePath; + levelFailedLoader.filePath = Config.Sounds.LevelFailed.FilePath; + lobbyAmbienceLoader.filePath = Config.Sounds.LobbyMusic.FilePath; // Added for LobbyMusic + + menuMusicLoader.load(); + menuClickLoader.load(); + if (Config.Sounds.HitSound.Active) hitSoundLoader.load(); + if (Config.Sounds.BadHitSound.Active) badHitSoundLoader.load(); + if (Config.Sounds.NoteMissedSound.Active) noteMissedSoundLoader.load(); + if (Config.Sounds.Firework.Active) fireworkSoundLoader.load(); + if (Config.Sounds.LevelCleared.Active) levelClearedLoader.load(); + if (Config.Sounds.LevelFailed.Active) levelFailedLoader.load(); + if (Config.Sounds.LobbyMusic.Active) lobbyAmbienceLoader.load(); // Added for LobbyMusic + } + // Creates an Array, of AudioClips + ::ArrayW<::UnityW<::UnityEngine::AudioClip>> createAudioClipArray(QuestSounds::Utils::AsyncAudioClipLoader clipLoader, bool GetOriginalClip) + { + UnityEngine::AudioClip* tempClip; + if (!GetOriginalClip) tempClip = clipLoader.getClip(); + else tempClip = clipLoader.get_OriginalClip(); + auto temporaryArray = ArrayW<::UnityW>({UnityW(tempClip)}); + return temporaryArray; + } +} + +MAKE_HOOK_MATCH(ResultsViewController_DidActivate, &ResultsViewController::DidActivate, void, ResultsViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { + if (firstActivation && addedToHierarchy && !levelClearedLoader.OriginalAudioSource) { + levelClearedLoader.set_OriginalClip(self->_levelClearedAudioClip); + } + if (self->_levelCompletionResults->levelEndStateType == LevelCompletionResults::LevelEndStateType::Failed) { + self->_songPreviewPlayer->StopAllCoroutines(); + if (levelFailedLoader.loaded && addedToHierarchy && Config.Sounds.LevelFailed.Active) { + UnityEngine::AudioClip* FailedSound = levelFailedLoader.getClip(); + float length = FailedSound->get_length(); + getLogger().debug("Duration of LevelFailed Sound: {}", length); + if (length > 7.0f) { + getLogger().info("Long LevelFailedSound"); + self->_songPreviewPlayer->CrossfadeTo(FailedSound, -4.0f, 0.0f, length, nullptr); + } + else { + getLogger().info("Short LevelFailedSound"); + self->_songPreviewPlayer->FadeOut(0.1f); + self->_songPreviewPlayer->_fadeSpeed = self->_songPreviewPlayer->_fadeInSpeed; + getLogger().debug("volume: {}", self->_songPreviewPlayer->_volume); + getLogger().debug("AmbientVolume: {}", self->_songPreviewPlayer->_ambientVolumeScale); + getLogger().debug("Set Volume: {}", self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); + + levelFailedLoader.audioSource->set_volume(self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); + self->_songPreviewPlayer->StartCoroutine(self->_songPreviewPlayer->CrossFadeAfterDelayCoroutine(length - 1.2f)); + levelFailedLoader.audioSource->Play(); + } + } + } + else { + if (levelClearedLoader.loaded && addedToHierarchy && Config.Sounds.LevelCleared.Active) + { + UnityEngine::AudioClip* audioClip = levelClearedLoader.getClip(); + self->_levelClearedAudioClip = audioClip; + } + else { + self->_levelClearedAudioClip = levelClearedLoader.get_OriginalClip(); + } + } + ResultsViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); +} + +MAKE_HOOK_MATCH(ResultsViewController_RestartButtonPressed, &ResultsViewController::RestartButtonPressed, void, ResultsViewController* self) { + if (levelFailedLoader.loaded && levelFailedLoader.audioSource->get_isPlaying()) { + levelFailedLoader.audioSource->Stop(); + } + ResultsViewController_RestartButtonPressed(self); +} + +MAKE_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, SongPreviewPlayer* self) { + getLogger().info("is it true: %i", menuMusicLoader.loaded); + + if (!menuMusicLoader.OriginalAudioSource) { + menuMusicLoader.set_OriginalClip(self->_defaultAudioClip); + } + + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) + { + getLogger().debug("Overriding MenuMusic Audio"); + UnityEngine::AudioClip* audioClip = menuMusicLoader.getClip(); + if (audioClip != nullptr) + self->_defaultAudioClip = audioClip; + } + else { + getLogger().debug("Loading MenuMusic Audio normally: isLoaded='{}' isActive='{}'", menuMusicLoader.loaded, Config.Sounds.MenuMusic.Active); + self->_defaultAudioClip = menuMusicLoader.get_OriginalClip(); + } + SongPreviewPlayer_OnEnable(self); +} + +MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlowCoordinator::DidActivate, void, GameServerLobbyFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) +{ + getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); + if (!lobbyAmbienceLoader.OriginalAudioSource) lobbyAmbienceLoader.set_OriginalClip(self->_ambienceAudioClip); + + if (lobbyAmbienceLoader.loaded && Config.Sounds.LobbyMusic.Active) + { + getLogger().debug("Overwriting LobbyAmbience Audio"); + self->_ambienceAudioClip = lobbyAmbienceLoader.getClip(); + } + else { + self->_ambienceAudioClip = lobbyAmbienceLoader.get_OriginalClip(); + } + GameServerLobbyFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); +} + +MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidDeactivate, &GameServerLobbyFlowCoordinator::DidDeactivate, void, GameServerLobbyFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) +{ + getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) + { + getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); + self->_ambienceAudioClip = menuMusicLoader.getClip(); + } + else { + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + } + GameServerLobbyFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); +} + +MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidActivate, &MultiplayerModeSelectionFlowCoordinator::DidActivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) +{ + getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidActivate"); + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) + { + getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); + self->_ambienceAudioClip = menuMusicLoader.getClip(); + } + else { + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + } + MultiplayerModeSelectionFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); // This has to be ran last, otherwise it will not work correctly +} + +MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidDeactivate, &MultiplayerModeSelectionFlowCoordinator::DidDeactivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) +{ + getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidDeactivate"); + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) + { + self->_ambienceAudioClip = menuMusicLoader.getClip(); + } + else { + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + } + + MultiplayerModeSelectionFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); +} + +#ifdef DEBUG +MAKE_HOOK_MATCH(FileHelpers_GetEscapedURLForFilePath, &FileHelpers::GetEscapedURLForFilePath, StringW, StringW filePath) { + return StringW("file://" + filePath); +} +#endif + +MAKE_HOOK_MATCH(NoteCutSoundEffectManager_Start, &NoteCutSoundEffectManager::Start, void, NoteCutSoundEffectManager* self) { + if(hitSoundLoader.loaded && Config.Sounds.HitSound.Active) + { + hitSoundArr = createAudioClipArray(hitSoundLoader); + self->_longCutEffectsAudioClips = hitSoundArr; + self->_shortCutEffectsAudioClips = hitSoundArr; + getLogger().debug("NoteCutSoundEffectManager_Start: Loaded hitSoundArray"); + } + else { + getLogger().debug("NoteCutSoundEffectManager_Start: Loading normally"); + } + getLogger().debug("audioSamplesBeatAlignOffset was: {}", self->_audioSamplesBeatAlignOffset); + if (Config.Sounds.HitSound.BeatOffset.has_value()) + self->_audioSamplesBeatAlignOffset = Config.Sounds.HitSound.BeatOffset.value(); + getLogger().debug("audioSamplesBeatAlignOffset changed to: {}", self->_audioSamplesBeatAlignOffset); + NoteCutSoundEffectManager_Start(self); + getLogger().debug("Beatalign offset is: {}", self->_beatAlignOffset); +} + +MAKE_HOOK_MATCH(NoteCutSoundEffect_Awake, &NoteCutSoundEffect::Awake, void, NoteCutSoundEffect* self) { + if (hitSoundLoader.loaded && Config.Sounds.HitSound.Active) { + self->_goodCutVolume += Config.Sounds.HitSound.VolumeOffset.value_or(0.0f); + } + + if(badHitSoundLoader.loaded && Config.Sounds.BadHitSound.Active) + { + badHitSoundArr = createAudioClipArray(badHitSoundLoader); + self->_badCutSoundEffectAudioClips = badHitSoundArr; + self->_badCutVolume += Config.Sounds.BadHitSound.VolumeOffset.value_or(0.0f); + } + NoteCutSoundEffect_Awake(self); +} + +MAKE_HOOK_MATCH(BeatmapObjectManager_HandleNoteWasMissed, &BeatmapObjectManager::HandleNoteControllerNoteWasMissed, void, BeatmapObjectManager* self, NoteController* noteController) { + BeatmapObjectManager_HandleNoteWasMissed(self, noteController); + if (noteMissedSoundLoader.loaded && + Config.Sounds.NoteMissedSound.Active && + noteController->get_noteData()->get_scoringType() != NoteData::ScoringType::Ignore && + noteController->get_noteData()->get_gameplayType() != NoteData::GameplayType::Bomb) { + noteMissedSoundLoader.audioSource->set_volume(0.5f + Config.Sounds.NoteMissedSound.VolumeOffset.value_or(0.0f)); + noteMissedSoundLoader.audioSource->Play(); + } +} + +MAKE_HOOK_MATCH(BasicUIAudioManager_Start, &BasicUIAudioManager::Start, void, BasicUIAudioManager* self) { + if (!menuClickLoader.OriginalAudioSource) menuClickLoader.set_OriginalClip(self->_clickSounds[0]); + + if(menuClickLoader.loaded && Config.Sounds.MenuClick.Active) + { + menuClickArr = createAudioClipArray(menuClickLoader); + self->_clickSounds = menuClickArr; + } + BasicUIAudioManager_Start(self); +} + +// Replacing the function here, as replacing the AudioClips proves to be difficult +MAKE_HOOK_MATCH(FireworkItemController_PlayExplosionSound, &FireworkItemController::PlayExplosionSound, void, FireworkItemController* self) { + if (fireworkSoundLoader.loaded && Config.Sounds.Firework.Active) { + self->_audioSource->set_clip(fireworkSoundLoader.getClip()); + float pitch = 1.2f + (((float)rand()) / (float)RAND_MAX) * (0.8f - 1.2f); + self->_audioSource->set_pitch(pitch); + self->_audioSource->Play(); + } + else FireworkItemController_PlayExplosionSound(self); +} + +MAKE_HOOK_MATCH(PauseMenuManager_MenuButtonPressed, &PauseMenuManager::MenuButtonPressed, void, PauseMenuManager* self) { + if (noteMissedSoundLoader.loaded && + Config.Sounds.NoteMissedSound.Active) { + if (noteMissedSoundLoader.audioSource) noteMissedSoundLoader.audioSource->Stop(); + } + PauseMenuManager_MenuButtonPressed(self); +} + +MAKE_HOOK_MATCH(SceneManager_Internal_ActiveSceneChanged, &SceneManager::Internal_ActiveSceneChanged, void, Scene previousActiveScene, Scene newActiveScene) { + SceneManager_Internal_ActiveSceneChanged(previousActiveScene, newActiveScene); + if (newActiveScene.IsValid()) { + std::string sceneName = newActiveScene.get_name(); + getLogger().info("Scene found: {}", sceneName.data()); + + std::string questInit = "QuestInit"; + if(sceneName == questInit) { + try { + QuestSounds::AudioClips::loadAudioClips(); + } + catch (const std::exception& e) { + getLogger().error("Failed to load AudioClips: {}", e.what()); + } + } + } +} + +std::string& GetConfigPath() { + static std::string configPath = Configuration::getConfigFilePath(modInfo); + return configPath; +} + +QS_EXPORT void setup(CModInfo *info) { + info->id = MOD_ID; + info->version = VERSION; + + + Paper::Logger::RegisterFileContextId(getLogger().tag); + + getLogger().info("Modloader: {}", modloader::get_modloader_path().c_str()); + + auto& configPath = GetConfigPath(); + getLogger().debug("Config Path is: {}", configPath); + + getLogger().info("Loading Config from file {}", configPath); + if(!fileexists(configPath)) { + getLogger().info("Config file not found, creating default config"); + if(!WriteToFile(configPath, Config, true)) + getLogger().error("Failed to write config file!"); + } + + try { + ReadFromFile(configPath, Config); + } catch(const std::exception& e) { + getLogger().error("Failed to read config: {}", e.what()); + } + + getLogger().info("Completed setup!"); +} + +QS_EXPORT void late_load() +{ + il2cpp_functions::Init(); + + auto& hkLog = getLogger(); + + makeFolder(); + getLogger().debug("Installing QuestSounds!"); + INSTALL_HOOK(hkLog, SceneManager_Internal_ActiveSceneChanged); + INSTALL_HOOK(hkLog, PauseMenuManager_MenuButtonPressed); + INSTALL_HOOK(hkLog, SongPreviewPlayer_OnEnable); + INSTALL_HOOK(hkLog, NoteCutSoundEffectManager_Start); + INSTALL_HOOK(hkLog, NoteCutSoundEffect_Awake); + INSTALL_HOOK(hkLog, BeatmapObjectManager_HandleNoteWasMissed); + INSTALL_HOOK(hkLog, BasicUIAudioManager_Start); + INSTALL_HOOK(hkLog, ResultsViewController_DidActivate); + INSTALL_HOOK(hkLog, ResultsViewController_RestartButtonPressed); + INSTALL_HOOK(hkLog, FireworkItemController_PlayExplosionSound) + INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music + INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music + INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music + INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music + // #ifdef DEBUG + // auto ModList = Modloader::getMods(); + // if (ModList.find("SongLoader") == ModList.end()) { + // getLogger().info("SongLoader missing, installing FilePath check"); + // INSTALL_HOOK(hkLog, FileHelpers_GetEscapedURLForFilePath); + // } + // #endif + getLogger().debug("Installed QuestSounds!"); +} From 44372586f511d6902635aa1f7027ad12db08ecb2 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 22:12:13 +0200 Subject: [PATCH 30/55] Config, add missing initial values for some sounds --- include/Config.hpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/Config.hpp b/include/Config.hpp index 62aea20..d1efae3 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -1,3 +1,5 @@ +#pragma once + #include "scotland2/shared/loader.hpp" #include "rapidjson-macros/shared/macros.hpp" @@ -7,7 +9,8 @@ // #define CONFIG_VERSION_PRE_R "SoundsConfig_v1" // #define CONFIG_VERSION_LEGACY "Sounds" -#define SOUND_VALUE(name, folder) VALUE_DEFAULT(Sound, name, Sound(soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg")) +#define SOUND_VALUE(name, folder, ...) VALUE_DEFAULT(Sound, name, Sound(soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg", __VA_ARGS__)) +#define SOUND_VALUE_SIMPLE(name, folder) VALUE_DEFAULT(Sound, name, Sound(soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg")) // define an automatically serialized / deserialized instance variable with a custom name in the json file and a default value #pragma region NAMED_VALUE_CUSTOM(type, name, default, jsonName) @@ -31,26 +34,26 @@ namespace QuestSounds { static const std::string soundPath = fmt::format(SOUND_PATH_FORMAT, modloader::get_application_id().c_str()); DECLARE_JSON_CLASS(Sound, - NAMED_VALUE_DEFAULT(bool, Active, true, "activated"); std::string FolderPath; std::string DefaultFilePath; + NAMED_VALUE_DEFAULT(bool, Active, true, "activated"); NAMED_VALUE_CUSTOM(std::string, FilePath, DefaultFilePath, "filepath"); NAMED_VALUE_OPTIONAL(float, VolumeOffset, "audioVolumeOffset"); NAMED_VALUE_OPTIONAL(float, BeatOffset, "beatOffSet"); - Sound(std::string folderPath, std::string defaultFilePath) : FolderPath(folderPath), DefaultFilePath(defaultFilePath) {} + Sound(std::string folderPath, std::string defaultFilePath, std::optional volumeOffset = std::nullopt, std::optional beatOffset = std::nullopt) : FolderPath(folderPath), DefaultFilePath(defaultFilePath), VolumeOffset(volumeOffset), BeatOffset(beatOffset) {} ) DECLARE_JSON_CLASS( Sounds, - SOUND_VALUE(HitSound, "HitSounds"); - SOUND_VALUE(BadHitSound, "BadHitSounds"); - SOUND_VALUE(NoteMissedSound, "NoteMissedSounds"); - SOUND_VALUE(MenuMusic, "MenuMusic"); - SOUND_VALUE(MenuClick, "MenuClicks"); - SOUND_VALUE(Firework, "Fireworks"); - SOUND_VALUE(LevelCleared, "LevelCleared"); - SOUND_VALUE(LevelFailed, "LevelFailed"); - SOUND_VALUE(LobbyMusic, "LobbyMusic"); + SOUND_VALUE(HitSound, "HitSounds", 0, 0.185f); + SOUND_VALUE(BadHitSound, "BadHitSounds", 0); + SOUND_VALUE(NoteMissedSound, "NoteMissedSounds", 0); + SOUND_VALUE_SIMPLE(MenuMusic, "MenuMusic"); + SOUND_VALUE_SIMPLE(MenuClick, "MenuClicks"); + SOUND_VALUE_SIMPLE(Firework, "Fireworks"); + SOUND_VALUE_SIMPLE(LevelCleared, "LevelCleared"); + SOUND_VALUE(LevelFailed, "LevelFailed", 0); + SOUND_VALUE_SIMPLE(LobbyMusic, "LobbyMusic"); ) DECLARE_JSON_CLASS( @@ -107,7 +110,8 @@ namespace QuestSounds { - +#undef NAMED_VALUE_CUSTOM #undef SOUND_PATH_FORMAT +#undef SOUND_VALUE_SIMPLE #undef SOUND_VALUE // #undef CONFIG_SOUND \ No newline at end of file From f97cc2174ee5cc9ec64fd8c66db1e57385c2ac22 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 22:14:24 +0200 Subject: [PATCH 31/55] Move logger to own include, fix audio loader --- include/logging.hpp | 6 ++++++ include/main.hpp | 7 ------- src/Utils/AsyncAudioClipLoader.cpp | 6 ++++-- src/main.cpp | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 include/logging.hpp diff --git a/include/logging.hpp b/include/logging.hpp new file mode 100644 index 0000000..4ae506f --- /dev/null +++ b/include/logging.hpp @@ -0,0 +1,6 @@ +// Logging +#include "paper/shared/logger.hpp" + +Paper::ConstLoggerContext<12UL>& getLogger(); + +// TODO: Proper paper logging macros \ No newline at end of file diff --git a/include/main.hpp b/include/main.hpp index 07025f4..48ee5b2 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -1,8 +1,5 @@ #pragma once -// Logging -#include "paper/shared/logger.hpp" - // Include the modloader header, which allows us to tell the modloader which mod this is, and the version etc. #include "scotland2/shared/loader.hpp" @@ -17,8 +14,4 @@ #include "System/Collections/IEnumerator.hpp" #include "custom-types/shared/coroutine.hpp" -// Define these functions here so that we can easily read configuration and log information from other files -Configuration& getConfig(); -Paper::ConstLoggerContext<12UL>& getLogger(); - #define QS_EXPORT extern "C" __attribute__((visibility("default"))) diff --git a/src/Utils/AsyncAudioClipLoader.cpp b/src/Utils/AsyncAudioClipLoader.cpp index dd9cd8d..4104b9f 100644 --- a/src/Utils/AsyncAudioClipLoader.cpp +++ b/src/Utils/AsyncAudioClipLoader.cpp @@ -1,6 +1,7 @@ // #include "QSoundsConfig.hpp" #include "Utils/AsyncAudioClipLoader.hpp" #include "main.hpp" +#include "logging.hpp" #include "Config.hpp" #include "ObjectInstances.hpp" @@ -79,7 +80,8 @@ bool QuestSounds::Utils::AsyncAudioClipLoader::load() if ((filePath.ends_with(".ogg") || filePath.ends_with(".wav")) && filePath != QuestSounds::Config.Sounds.HitSound.FilePath) { getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); UsesUWR = false; - loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); + // loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); + loadPath = filePath; // Ensure MediaAsyncLoader is initialized if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) { getLogger().info("MediaAsyncLoader class not initialized, initializing it"); @@ -91,7 +93,7 @@ bool QuestSounds::Utils::AsyncAudioClipLoader::load() audioClipTask->GetAwaiter().OnCompleted(custom_types::MakeDelegate(std::function([this]() { getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {} status is {}", filePath, (int)audioClipTask->get_Status()); - audioClipCompleted(audioClipTask->get_ResultOnSuccess()); + audioClipCompleted(audioClipTask->get_Result()); }))); } else { diff --git a/src/main.cpp b/src/main.cpp index 9f87166..5bbea6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "main.hpp" +#include "logging.hpp" #include "Utils/AsyncAudioClipLoader.hpp" #include "Config.hpp" #include "AudioClips.hpp" From be322b605f35d7dfea45daaeaec74d0a94c727de Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 22:16:13 +0200 Subject: [PATCH 32/55] WIP: Initial basic UI implementation POC --- CMakeLists.txt | 9 ++- assets/SoundSettingsViewController.bsml | 21 ++++++ include/UI/QuestSoundsFlowCoordinator.hpp | 23 ++++++ include/UI/SoundSettingsViewController.hpp | 31 ++++++++ include/assets.hpp | 4 ++ qpm.json | 5 ++ qpm.shared.json | 52 ++++++++++---- src/UI/QuestSoundsFlowCoordinator.cpp | 38 ++++++++++ src/UI/SoundSettingsViewController.cpp | 82 ++++++++++++++++++++++ src/main.cpp | 6 ++ 10 files changed, 251 insertions(+), 20 deletions(-) create mode 100644 assets/SoundSettingsViewController.bsml create mode 100644 include/UI/QuestSoundsFlowCoordinator.hpp create mode 100644 include/UI/SoundSettingsViewController.hpp create mode 100644 include/assets.hpp create mode 100644 src/UI/QuestSoundsFlowCoordinator.cpp create mode 100644 src/UI/SoundSettingsViewController.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 01384c0..9515873 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) cmake_minimum_required(VERSION 3.21) project(${COMPILE_ID}) +include(${EXTERN_DIR}/includes/kaleb/shared/cmake/assets.cmake) # c++ standard set(CMAKE_CXX_STANDARD 20) @@ -41,10 +42,6 @@ add_library( ${c_file_list} ) -target_include_directories(${COMPILE_ID} PRIVATE .) - -target_include_directories(${COMPILE_ID} PRIVATE extern/includes/questui_components) - # add src dir as include dir target_include_directories(${COMPILE_ID} PRIVATE ${SOURCE_DIR}) # add include dir as include dir @@ -54,7 +51,9 @@ target_include_directories(${COMPILE_ID} PUBLIC ${SHARED_DIR}) # codegen includes target_include_directories(${COMPILE_ID} PRIVATE ${EXTERN_DIR}/includes/${CODEGEN_ID}/include) -target_link_libraries(${COMPILE_ID} PRIVATE -llog) +# Kaleb include assets +add_assets(${COMPILE_ID}-assets STATIC ${CMAKE_CURRENT_LIST_DIR}/assets ${INCLUDE_DIR}/assets.hpp) +target_link_libraries(${COMPILE_ID} PRIVATE -llog -lz ${COMPILE_ID}-assets) # add extern stuff like libs and other includes include(extern.cmake) diff --git a/assets/SoundSettingsViewController.bsml b/assets/SoundSettingsViewController.bsml new file mode 100644 index 0000000..e1aa5cb --- /dev/null +++ b/assets/SoundSettingsViewController.bsml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/include/UI/QuestSoundsFlowCoordinator.hpp b/include/UI/QuestSoundsFlowCoordinator.hpp new file mode 100644 index 0000000..7f4700d --- /dev/null +++ b/include/UI/QuestSoundsFlowCoordinator.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "custom-types/shared/macros.hpp" +#include "bsml/shared/macros.hpp" + +#include "HMUI/FlowCoordinator.hpp" + +#include "UI/SoundSettingsViewController.hpp" + +#include "GlobalNamespace/MainFlowCoordinator.hpp" + +#include "Zenject/IInitializable.hpp" + +DECLARE_CLASS_CODEGEN(QuestSounds::UI, QuestSoundsFlowCoordinator, HMUI::FlowCoordinator, + + DECLARE_INSTANCE_FIELD(QuestSounds::UI::SoundSettingsViewController*, soundSettingsViewController); + + DECLARE_INSTANCE_METHOD(void, Awake); + DECLARE_OVERRIDE_METHOD_MATCH(void, DidActivate, &HMUI::FlowCoordinator::DidActivate, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); + DECLARE_OVERRIDE_METHOD_MATCH(void, DidDeactivate, &HMUI::FlowCoordinator::DidDeactivate, bool removedFromHierarchy, bool screenSystemDisabling); + DECLARE_OVERRIDE_METHOD_MATCH(void, BackButtonWasPressed, &HMUI::FlowCoordinator::BackButtonWasPressed, HMUI::ViewController* topViewController); + DECLARE_DEFAULT_CTOR(); +) \ No newline at end of file diff --git a/include/UI/SoundSettingsViewController.hpp b/include/UI/SoundSettingsViewController.hpp new file mode 100644 index 0000000..9878c05 --- /dev/null +++ b/include/UI/SoundSettingsViewController.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "custom-types/shared/macros.hpp" +#include "bsml/shared/macros.hpp" +#include "bsml/shared/BSML/Components/Settings/IncrementSetting.hpp" +#include "bsml/shared/BSML/Components/Settings/SliderSetting.hpp" + +#include "Config.hpp" + +#include "HMUI/ViewController.hpp" + +DECLARE_CLASS_CODEGEN(QuestSounds::UI, SoundSettingsViewController, HMUI::ViewController, + std::string Name; + QuestSounds::Sound* Sound; + + DECLARE_BSML_PROPERTY(bool, Active); + DECLARE_BSML_PROPERTY(float, VolumeOffset); + DECLARE_BSML_PROPERTY(float, BeatOffset); + + DECLARE_INSTANCE_FIELD(BSML::SliderSetting*, SoundVolumeOffset); + DECLARE_INSTANCE_FIELD(BSML::SliderSetting*, SoundBeatOffset); + + DECLARE_INSTANCE_FIELD(bool, showSoundVolumeOffset); + DECLARE_INSTANCE_FIELD(bool, showSoundBeatOffset); + + DECLARE_OVERRIDE_METHOD_MATCH(void, DidActivate, &HMUI::ViewController::DidActivate, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); + DECLARE_OVERRIDE_METHOD_MATCH(void, DidDeactivate, &HMUI::ViewController::DidDeactivate, bool removedFromHierarchy, bool screenSystemDisabling); + +public: + void Setup(std::string name, QuestSounds::Sound* sound); +) \ No newline at end of file diff --git a/include/assets.hpp b/include/assets.hpp new file mode 100644 index 0000000..c277377 --- /dev/null +++ b/include/assets.hpp @@ -0,0 +1,4 @@ +#pragma once +#include "kaleb/shared/kaleb.hpp" + +DECLARE_FILE(_binary_SoundSettingsViewController_bsml, Assets, SoundSettingsViewController_bsml); diff --git a/qpm.json b/qpm.json index 7b08e90..e6a61c4 100644 --- a/qpm.json +++ b/qpm.json @@ -60,6 +60,11 @@ "id": "rapidjson-macros", "versionRange": "^1.2.1", "additionalData": {} + }, + { + "id": "kaleb", + "versionRange": "^0.1.9", + "additionalData": {} } ] } \ No newline at end of file diff --git a/qpm.shared.json b/qpm.shared.json index 2f32a79..3cfa3cb 100644 --- a/qpm.shared.json +++ b/qpm.shared.json @@ -61,6 +61,11 @@ "id": "rapidjson-macros", "versionRange": "^1.2.1", "additionalData": {} + }, + { + "id": "kaleb", + "versionRange": "^0.1.9", + "additionalData": {} } ] }, @@ -157,6 +162,23 @@ }, "version": "0.3.2" }, + { + "dependency": { + "id": "kaleb", + "versionRange": "=0.1.9", + "additionalData": { + "headersOnly": true, + "branchName": "version/v0_1_9", + "compileOptions": { + "cppFlags": [ + "-DKALEB_VERSION=\"0.1.9\"" + ] + }, + "cmake": false + } + }, + "version": "0.1.9" + }, { "dependency": { "id": "bs-cordl", @@ -206,6 +228,21 @@ }, "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": { "id": "fmt", @@ -224,21 +261,6 @@ } }, "version": "10.0.0" - }, - { - "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" } ] } \ No newline at end of file diff --git a/src/UI/QuestSoundsFlowCoordinator.cpp b/src/UI/QuestSoundsFlowCoordinator.cpp new file mode 100644 index 0000000..130ff76 --- /dev/null +++ b/src/UI/QuestSoundsFlowCoordinator.cpp @@ -0,0 +1,38 @@ +#include "UI/QuestSoundsFlowCoordinator.hpp" +#include "Config.hpp" +#include "logging.hpp" + +#include "bsml/shared/Helpers/creation.hpp" + +DEFINE_TYPE(QuestSounds::UI, QuestSoundsFlowCoordinator); + +namespace QuestSounds::UI { + void QuestSoundsFlowCoordinator::Awake() { + getLogger().info("Awake"); + if (!soundSettingsViewController) { + getLogger().info("Awake ViewController null, Creating SoundSettingsViewController"); + soundSettingsViewController = BSML::Helpers::CreateViewController(); + // TODO: Implement iteration through all sounds in the Config and switching between them + // Testing using HitSounds for now + soundSettingsViewController->Setup("HitSound", &QuestSounds::Config.Sounds.HitSound); + } + } + + void QuestSoundsFlowCoordinator::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { + getLogger().info("DidActivate"); + if (firstActivation) { + ProvideInitialViewControllers(soundSettingsViewController, nullptr, nullptr, nullptr, nullptr); + } + SetTitle("QuestSounds", HMUI::ViewController::AnimationType::In); + showBackButton = true; + } + + void QuestSoundsFlowCoordinator::DidDeactivate(bool removedFromHierarchy, bool screenSystemDisabling) { + getLogger().info("DidDeactivate"); + } + + void QuestSoundsFlowCoordinator::BackButtonWasPressed(HMUI::ViewController* topViewController) { + getLogger().info("BackButtonWasPressed"); + _parentFlowCoordinator->DismissFlowCoordinator(this, HMUI::ViewController::AnimationDirection::Horizontal, nullptr, false); + } +} \ No newline at end of file diff --git a/src/UI/SoundSettingsViewController.cpp b/src/UI/SoundSettingsViewController.cpp new file mode 100644 index 0000000..02a80bb --- /dev/null +++ b/src/UI/SoundSettingsViewController.cpp @@ -0,0 +1,82 @@ +#include "UI/SoundSettingsViewController.hpp" +#include "UI/QuestSoundsFlowCoordinator.hpp" +#include "logging.hpp" +#include "assets.hpp" + +#include "bsml/shared/BSML.hpp" + +DEFINE_TYPE(QuestSounds::UI, SoundSettingsViewController); + +namespace QuestSounds::UI { + void SoundSettingsViewController::DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { + if (firstActivation) { + getLogger().info("DidActivate firstActivation"); + BSML::parse_and_construct(Assets::SoundSettingsViewController_bsml, get_transform(), this); + } + if (SoundVolumeOffset) { + getLogger().info("DidActivate SoundVolumeOffset"); + SoundVolumeOffset->gameObject->SetActive(showSoundVolumeOffset); + SoundVolumeOffset->set_Value(Sound->VolumeOffset.value()); + } + if (SoundBeatOffset) { + getLogger().info("DidActivate SoundBeatOffset"); + SoundBeatOffset->gameObject->SetActive(showSoundBeatOffset); + SoundBeatOffset->set_Value(Sound->BeatOffset.value()); + } + getLogger().info("DidActivate"); + } + + void SoundSettingsViewController::DidDeactivate(bool removedFromHierarchy, bool screenSystemDisabling) { + getLogger().info("DidDeactivate"); + } + + void SoundSettingsViewController::Setup(std::string name, QuestSounds::Sound* sound) { + getLogger().info("Setup for sound: '{}' cfg values: active='{}', filepath='{}' FolderPath='{}'", name, sound->Active, sound->FilePath, sound->FolderPath); + Name = name; + Sound = sound; + + showSoundVolumeOffset = sound->VolumeOffset.has_value(); + showSoundBeatOffset = sound->BeatOffset.has_value(); + + if (SoundVolumeOffset && showSoundVolumeOffset) { + SoundVolumeOffset->set_Value(sound->VolumeOffset.value()); + } + + if (SoundBeatOffset && showSoundBeatOffset) { + SoundBeatOffset->set_Value(sound->BeatOffset.has_value()); + } + } + + void SoundSettingsViewController::set_Active(bool value) { + getLogger().info("Setting Active for sound: '{}' to '{}'", Name, value); + _Active = value; + Sound->Active = value; + } + + bool SoundSettingsViewController::get_Active() { + getLogger().info("Getting Active for sound: '{}' as '{}'", Name, Sound->Active); + return Sound->Active; + } + + void SoundSettingsViewController::set_VolumeOffset(float value) { + getLogger().info("Setting VolumeOffset for sound: '{}' to '{}'", Name, value); + _VolumeOffset = value; + Sound->VolumeOffset = value; + } + + float SoundSettingsViewController::get_VolumeOffset() { + getLogger().info("Getting VolumeOffset for sound: '{}' as '{}'", Name, Sound->VolumeOffset.value_or(0)); + return Sound->VolumeOffset.value_or(0); + } + + void SoundSettingsViewController::set_BeatOffset(float value) { + getLogger().info("Setting BeatOffset for sound: '{}' to '{}'", Name, value); + _BeatOffset = value; + Sound->BeatOffset = value; + } + + float SoundSettingsViewController::get_BeatOffset() { + getLogger().info("Getting BeatOffset for sound: '{}' as '{}'", Name, Sound->BeatOffset.value_or(0.185f)); + return Sound->BeatOffset.value_or(0.185f); + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5bbea6d..fe4b65f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "main.hpp" #include "logging.hpp" #include "Utils/AsyncAudioClipLoader.hpp" +#include "UI/QuestSoundsFlowCoordinator.hpp" #include "Config.hpp" #include "AudioClips.hpp" using namespace QuestSounds::AudioClips; @@ -32,6 +33,8 @@ using namespace GlobalNamespace; #include "UnityEngine/Time.hpp" using namespace UnityEngine::SceneManagement; +#include "bsml/shared/BSML.hpp" + // TODO BSML // #include "ViewControllers/MenuSdListViewController.hpp" @@ -457,6 +460,9 @@ QS_EXPORT void setup(CModInfo *info) { QS_EXPORT void late_load() { il2cpp_functions::Init(); + BSML::Init(); + custom_types::Register::AutoRegister(); + BSML::Register::RegisterMainMenu("QuestSounds", "Let's you customize sounds and music"); auto& hkLog = getLogger(); From e3c6ac0fc7877ca3da7fd55f5889f51fbac12360 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 22:19:31 +0200 Subject: [PATCH 33/55] Cleanup CMakeList --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9515873..975d67b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ # include some defines automatically made by qpm include(qpm_defines.cmake) -# override mod id -# set(MOD_ID "QuestSounds") # Enable link time optimization # In my experience, this can be highly unstable but it nets a huge size optimization and likely performance From e362fcf67242c4382c30cf56a4ccd1d3acbb8230 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Sun, 21 Jul 2024 22:25:22 +0200 Subject: [PATCH 34/55] Cleanup unused variables --- include/Utils/AsyncAudioClipLoader.hpp | 3 --- src/Utils/AsyncAudioClipLoader.cpp | 3 --- 2 files changed, 6 deletions(-) diff --git a/include/Utils/AsyncAudioClipLoader.hpp b/include/Utils/AsyncAudioClipLoader.hpp index 79165d0..34d48e0 100644 --- a/include/Utils/AsyncAudioClipLoader.hpp +++ b/include/Utils/AsyncAudioClipLoader.hpp @@ -33,11 +33,8 @@ namespace QuestSounds::Utils private: custom_types::Helpers::Coroutine LoadAudioClip(); StringW loadPath; - // custom_types::Helpers::Coroutine loadCoroutine; UnityEngine::GameObject* audioClipGO; void audioClipCompleted(UnityEngine::AudioClip* audioClip); - // StringW path; - bool UsesUWR = false; System::Threading::Tasks::Task_1<::UnityW>* audioClipTask; UnityEngine::Networking::UnityWebRequestAsyncOperation* audioClipAsync; diff --git a/src/Utils/AsyncAudioClipLoader.cpp b/src/Utils/AsyncAudioClipLoader.cpp index 4104b9f..d185e4f 100644 --- a/src/Utils/AsyncAudioClipLoader.cpp +++ b/src/Utils/AsyncAudioClipLoader.cpp @@ -79,8 +79,6 @@ bool QuestSounds::Utils::AsyncAudioClipLoader::load() //Stage 1 if ((filePath.ends_with(".ogg") || filePath.ends_with(".wav")) && filePath != QuestSounds::Config.Sounds.HitSound.FilePath) { getLogger().info("Stage 1: Running MediaAsyncLoader for FilePath {}", filePath.c_str()); - UsesUWR = false; - // loadPath = std::regex_replace(filePath, std::regex(" "), "%20"); loadPath = filePath; // Ensure MediaAsyncLoader is initialized if (!classof(GlobalNamespace::MediaAsyncLoader*)->initialized) { @@ -98,7 +96,6 @@ bool QuestSounds::Utils::AsyncAudioClipLoader::load() } else { getLogger().info("Stage 1: Running UnityWebRequestMultimedia for FilePath {}", filePath); - UsesUWR = true; if (filePath.starts_with("https://") || filePath.starts_with("http://")) { loadPath = filePath; } From 54c278f6c84f923fec37d22c1ceddcc04adbda0e Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Mon, 22 Jul 2024 22:09:28 +0200 Subject: [PATCH 35/55] Cleanup remove includes --- include/AudioClips.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/AudioClips.hpp b/include/AudioClips.hpp index ab86842..7ba6b18 100644 --- a/include/AudioClips.hpp +++ b/include/AudioClips.hpp @@ -1,10 +1,9 @@ #pragma once -//#include "main.hpp" -//#include "audiocliploader.hpp" + #include "Utils/AsyncAudioClipLoader.hpp" namespace QuestSounds::AudioClips { - //extern audioClipLoader::loader + extern QuestSounds::Utils::AsyncAudioClipLoader hitSoundLoader, // hitSound badHitSoundLoader, // badHitSound noteMissedSoundLoader, @@ -14,6 +13,7 @@ namespace QuestSounds::AudioClips { levelClearedLoader, levelFailedLoader, lobbyAmbienceLoader; // Added for LobbyMusic + extern ::ArrayW<::UnityW<::UnityEngine::AudioClip>> hitSoundArr, // hitSoundArray badHitSoundArr, // badHitSoundArray menuClickArr, From 949bbfa14937f877a9f29c69994809f07e35a93e Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Mon, 22 Jul 2024 22:12:10 +0200 Subject: [PATCH 36/55] Move export func to separate header --- include/_config.h | 7 +++++++ include/main.hpp | 7 ++----- src/main.cpp | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 include/_config.h diff --git a/include/_config.h b/include/_config.h new file mode 100644 index 0000000..97c5fec --- /dev/null +++ b/include/_config.h @@ -0,0 +1,7 @@ +#define QS_EXPORT __attribute__((visibility("default"))) + +#ifdef __cplusplus +#define QS_EXPORT_FUNC extern "C" QS_EXPORT +#else +#define QS_EXPORT_FUNC QS_EXPORT +#endif \ No newline at end of file diff --git a/include/main.hpp b/include/main.hpp index 48ee5b2..d0cfed1 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -1,5 +1,7 @@ #pragma once +// TODO: Cleanup this file + // Include the modloader header, which allows us to tell the modloader which mod this is, and the version etc. #include "scotland2/shared/loader.hpp" @@ -10,8 +12,3 @@ #include "beatsaber-hook/shared/utils/il2cpp-functions.hpp" #include "beatsaber-hook/shared/config/config-utils.hpp" #include "beatsaber-hook/shared/utils/hooking.hpp" - -#include "System/Collections/IEnumerator.hpp" -#include "custom-types/shared/coroutine.hpp" - -#define QS_EXPORT extern "C" __attribute__((visibility("default"))) diff --git a/src/main.cpp b/src/main.cpp index fe4b65f..df3c94e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "main.hpp" +#include "_config.h" #include "logging.hpp" #include "Utils/AsyncAudioClipLoader.hpp" #include "UI/QuestSoundsFlowCoordinator.hpp" From 27fe05ae4a5694ba78e0610a9543e79eea4277e5 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Mon, 22 Jul 2024 22:17:41 +0200 Subject: [PATCH 37/55] Add ClipLoader to Setup function --- include/UI/SoundSettingsViewController.hpp | 5 ++++- src/UI/QuestSoundsFlowCoordinator.cpp | 5 +++-- src/UI/SoundSettingsViewController.cpp | 13 ++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/UI/SoundSettingsViewController.hpp b/include/UI/SoundSettingsViewController.hpp index 9878c05..e8627a4 100644 --- a/include/UI/SoundSettingsViewController.hpp +++ b/include/UI/SoundSettingsViewController.hpp @@ -6,16 +6,19 @@ #include "bsml/shared/BSML/Components/Settings/SliderSetting.hpp" #include "Config.hpp" +#include "Utils/AsyncAudioClipLoader.hpp" #include "HMUI/ViewController.hpp" DECLARE_CLASS_CODEGEN(QuestSounds::UI, SoundSettingsViewController, HMUI::ViewController, std::string Name; QuestSounds::Sound* Sound; + QuestSounds::Utils::AsyncAudioClipLoader* Loader; DECLARE_BSML_PROPERTY(bool, Active); DECLARE_BSML_PROPERTY(float, VolumeOffset); DECLARE_BSML_PROPERTY(float, BeatOffset); + DECLARE_BSML_PROPERTY(bool, HasSoundFiles); DECLARE_INSTANCE_FIELD(BSML::SliderSetting*, SoundVolumeOffset); DECLARE_INSTANCE_FIELD(BSML::SliderSetting*, SoundBeatOffset); @@ -27,5 +30,5 @@ DECLARE_CLASS_CODEGEN(QuestSounds::UI, SoundSettingsViewController, HMUI::ViewCo DECLARE_OVERRIDE_METHOD_MATCH(void, DidDeactivate, &HMUI::ViewController::DidDeactivate, bool removedFromHierarchy, bool screenSystemDisabling); public: - void Setup(std::string name, QuestSounds::Sound* sound); + void Setup(std::string name, QuestSounds::Sound* sound, QuestSounds::Utils::AsyncAudioClipLoader* loader); ) \ No newline at end of file diff --git a/src/UI/QuestSoundsFlowCoordinator.cpp b/src/UI/QuestSoundsFlowCoordinator.cpp index 130ff76..ca9a716 100644 --- a/src/UI/QuestSoundsFlowCoordinator.cpp +++ b/src/UI/QuestSoundsFlowCoordinator.cpp @@ -1,6 +1,7 @@ #include "UI/QuestSoundsFlowCoordinator.hpp" #include "Config.hpp" #include "logging.hpp" +#include "AudioClips.hpp" #include "bsml/shared/Helpers/creation.hpp" @@ -12,9 +13,9 @@ namespace QuestSounds::UI { if (!soundSettingsViewController) { getLogger().info("Awake ViewController null, Creating SoundSettingsViewController"); soundSettingsViewController = BSML::Helpers::CreateViewController(); - // TODO: Implement iteration through all sounds in the Config and switching between them + // TODO: Implement iteration through all sounds in the Config and switching between them also possible use some sort of safeptr for the config and loader // Testing using HitSounds for now - soundSettingsViewController->Setup("HitSound", &QuestSounds::Config.Sounds.HitSound); + soundSettingsViewController->Setup("HitSound", &QuestSounds::Config.Sounds.HitSound, &QuestSounds::AudioClips::hitSoundLoader); } } diff --git a/src/UI/SoundSettingsViewController.cpp b/src/UI/SoundSettingsViewController.cpp index 02a80bb..91c9137 100644 --- a/src/UI/SoundSettingsViewController.cpp +++ b/src/UI/SoundSettingsViewController.cpp @@ -30,10 +30,11 @@ namespace QuestSounds::UI { getLogger().info("DidDeactivate"); } - void SoundSettingsViewController::Setup(std::string name, QuestSounds::Sound* sound) { + void SoundSettingsViewController::Setup(std::string name, QuestSounds::Sound* sound, QuestSounds::Utils::AsyncAudioClipLoader* loader) { getLogger().info("Setup for sound: '{}' cfg values: active='{}', filepath='{}' FolderPath='{}'", name, sound->Active, sound->FilePath, sound->FolderPath); Name = name; Sound = sound; + Loader = loader; showSoundVolumeOffset = sound->VolumeOffset.has_value(); showSoundBeatOffset = sound->BeatOffset.has_value(); @@ -79,4 +80,14 @@ namespace QuestSounds::UI { getLogger().info("Getting BeatOffset for sound: '{}' as '{}'", Name, Sound->BeatOffset.value_or(0.185f)); return Sound->BeatOffset.value_or(0.185f); } + + void SoundSettingsViewController::set_HasSoundFiles(bool value) { + getLogger().info("Setting HasSoundFiles for sound: '{}' to '{}'", Name, value); + _HasSoundFiles = value; + } + + bool SoundSettingsViewController::get_HasSoundFiles() { + getLogger().info("Getting HasSoundFiles for sound: '{}' as '{}'", Name, _HasSoundFiles); + return _HasSoundFiles; + } } \ No newline at end of file From 15f8f33c01c361d7550348534e044c72b35e0c6f Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Mon, 22 Jul 2024 22:18:14 +0200 Subject: [PATCH 38/55] Add name to config class, might need that --- include/Config.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/Config.hpp b/include/Config.hpp index d1efae3..6f1d961 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -9,8 +9,8 @@ // #define CONFIG_VERSION_PRE_R "SoundsConfig_v1" // #define CONFIG_VERSION_LEGACY "Sounds" -#define SOUND_VALUE(name, folder, ...) VALUE_DEFAULT(Sound, name, Sound(soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg", __VA_ARGS__)) -#define SOUND_VALUE_SIMPLE(name, folder) VALUE_DEFAULT(Sound, name, Sound(soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg")) +#define SOUND_VALUE(name, folder, ...) VALUE_DEFAULT(Sound, name, Sound(#name, soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg", __VA_ARGS__)) +#define SOUND_VALUE_SIMPLE(name, folder) VALUE_DEFAULT(Sound, name, Sound(#name, soundPath + folder + "/", soundPath + folder + "/" + #name + ".ogg")) // define an automatically serialized / deserialized instance variable with a custom name in the json file and a default value #pragma region NAMED_VALUE_CUSTOM(type, name, default, jsonName) @@ -34,13 +34,14 @@ namespace QuestSounds { static const std::string soundPath = fmt::format(SOUND_PATH_FORMAT, modloader::get_application_id().c_str()); DECLARE_JSON_CLASS(Sound, + std::string Name; std::string FolderPath; std::string DefaultFilePath; NAMED_VALUE_DEFAULT(bool, Active, true, "activated"); NAMED_VALUE_CUSTOM(std::string, FilePath, DefaultFilePath, "filepath"); NAMED_VALUE_OPTIONAL(float, VolumeOffset, "audioVolumeOffset"); NAMED_VALUE_OPTIONAL(float, BeatOffset, "beatOffSet"); - Sound(std::string folderPath, std::string defaultFilePath, std::optional volumeOffset = std::nullopt, std::optional beatOffset = std::nullopt) : FolderPath(folderPath), DefaultFilePath(defaultFilePath), VolumeOffset(volumeOffset), BeatOffset(beatOffset) {} + Sound(std::string name, std::string folderPath, std::string defaultFilePath, std::optional volumeOffset = std::nullopt, std::optional beatOffset = std::nullopt) : Name(name), FolderPath(folderPath), DefaultFilePath(defaultFilePath), VolumeOffset(volumeOffset), BeatOffset(beatOffset) {} ) DECLARE_JSON_CLASS( From c5e214426e6b38abf70248cfbbcda8c981d67528 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Mon, 22 Jul 2024 22:19:45 +0200 Subject: [PATCH 39/55] Split up hooks into separate cpp files --- include/hooking.hpp | 107 ++++++++++++ src/Hooks/BackgroundMusicHooks.cpp | 93 +++++++++++ src/Hooks/LevelResultSoundHooks.cpp | 77 +++++++++ src/Hooks/NoteSoundHook.cpp | 70 ++++++++ src/main.cpp | 248 ++-------------------------- 5 files changed, 364 insertions(+), 231 deletions(-) create mode 100644 include/hooking.hpp create mode 100644 src/Hooks/BackgroundMusicHooks.cpp create mode 100644 src/Hooks/LevelResultSoundHooks.cpp create mode 100644 src/Hooks/NoteSoundHook.cpp diff --git a/include/hooking.hpp b/include/hooking.hpp new file mode 100644 index 0000000..2bc1086 --- /dev/null +++ b/include/hooking.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include "beatsaber-hook/shared/utils/hooking.hpp" +#include "beatsaber-hook/shared/utils/logging.hpp" +#include + +namespace QuestSounds { + class Hooking { + private: + inline static std::vector installFuncs; + + public: + static void AddInstallFunc(void (*installFunc)()) { + installFuncs.push_back(installFunc); + } + + static inline void InstallHooks() { + for (auto& func : installFuncs) func(); + } + }; + + template + concept has_metadata = requires() { + { ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo() } -> std::same_as; + }; + + template + requires(has_metadata) + using Metadata = ::il2cpp_utils::il2cpp_type_check::MetadataGetter; + + /// @brief checks whether the function is match hookable, which requires the function to be at least 5 (5 * 4 = 20 bytes) instructions and not have an address of 0 (abstract/virtual funcs) + template + concept match_hookable = has_metadata && Metadata::size >= (0x5 * sizeof(int32_t)) && Metadata::addrs != 0x0; +} + +#define AUTO_INSTALL_PATCH(name_) \ + struct Auto_Patch_##name_ { \ + Auto_Patch_##name_() { \ + ::QuestSounds::Hooking::AddInstallFunc(Patch_##name_); \ + } \ + }; \ + static Auto_Patch_##name_ Auto_Patch_Instance_##name_ + +#define HOOK_AUTO_INSTALL_ORIG(name_) \ + struct Auto_Hook_##name_ { \ + static void Auto_Hook_##name_##_Install() { \ + static constexpr auto logger = Paper::ConstLoggerContext(MOD_ID "_Install_" #name_); \ + ::Hooking::InstallOrigHook(logger); \ + } \ + Auto_Hook_##name_() { ::QuestSounds::Hooking::AddInstallFunc(Auto_Hook_##name_##_Install); } \ + }; \ + static Auto_Hook_##name_ Auto_Hook_Instance_##name_ + +#define HOOK_AUTO_INSTALL(name_) \ + struct Auto_Hook_##name_ { \ + static void Auto_Hook_##name_##_Install() { \ + static constexpr auto logger = Paper::ConstLoggerContext(MOD_ID "_Install_" #name_); \ + ::Hooking::InstallHook(logger); \ + } \ + Auto_Hook_##name_() { ::QuestSounds::Hooking::AddInstallFunc(Auto_Hook_##name_##_Install); } \ + }; \ + static Auto_Hook_##name_ Auto_Hook_Instance_##name_ + +#define MAKE_AUTO_HOOK_MATCH(name_, mPtr, retval, ...) \ + struct Hook_##name_ \ + { \ + using funcType = retval (*)(__VA_ARGS__); \ + static_assert(QuestSounds::match_hookable); \ + static_assert(std::is_same_v::funcType>, "Hook method signature does not match!"); \ + constexpr static const char* name() { return #name_; } \ + static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo(); } \ + static funcType* trampoline() { return &name_; } \ + static inline retval (*name_)(__VA_ARGS__) = nullptr; \ + static funcType hook() { return &::Hooking::HookCatchWrapper<&hook_##name_, funcType>::wrapper; } \ + static retval hook_##name_(__VA_ARGS__); \ + }; \ + HOOK_AUTO_INSTALL(name_); \ + retval Hook_##name_::hook_##name_(__VA_ARGS__) + +#define MAKE_AUTO_HOOK_FIND_VERBOSE(name_, infoGet, retval, ...) \ + struct Hook_##name_ { \ + constexpr static const char* name() { return #name_; } \ + static const MethodInfo* getInfo() { return infoGet; } \ + using funcType = retval (*)(__VA_ARGS__); \ + static funcType* trampoline() { return &name_; } \ + static inline retval (*name_)(__VA_ARGS__) = nullptr; \ + static funcType hook() { return &::Hooking::HookCatchWrapper<&hook_##name_, funcType>::wrapper; } \ + static retval hook_##name_(__VA_ARGS__); \ + }; \ + HOOK_AUTO_INSTALL_ORIG(name_); \ + retval Hook_##name_::hook_##name_(__VA_ARGS__) + +#define MAKE_AUTO_HOOK_ORIG_MATCH(name_, mPtr, retval, ...) \ + struct Hook_##name_ \ + { \ + using funcType = retval (*)(__VA_ARGS__); \ + static_assert(QuestSounds::match_hookable); \ + static_assert(std::is_same_v::funcType>, "Hook method signature does not match!"); \ + constexpr static const char* name() { return #name_; } \ + static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo(); } \ + static funcType* trampoline() { return &name_; } \ + static inline retval (*name_)(__VA_ARGS__) = nullptr; \ + static funcType hook() { return &::Hooking::HookCatchWrapper<&hook_##name_, funcType>::wrapper; } \ + static retval hook_##name_(__VA_ARGS__); \ + }; \ + HOOK_AUTO_INSTALL_ORIG(name_); \ + retval Hook_##name_::hook_##name_(__VA_ARGS__) diff --git a/src/Hooks/BackgroundMusicHooks.cpp b/src/Hooks/BackgroundMusicHooks.cpp new file mode 100644 index 0000000..8bbb349 --- /dev/null +++ b/src/Hooks/BackgroundMusicHooks.cpp @@ -0,0 +1,93 @@ +#include "hooking.hpp" +#include "logging.hpp" +#include "Config.hpp" +using namespace QuestSounds; + +// TODO: I'd like to get rid of this header +#include "AudioClips.hpp" +using namespace QuestSounds::AudioClips; + +#include "GlobalNamespace/SongPreviewPlayer.hpp" +#include "GlobalNamespace/GameServerLobbyFlowCoordinator.hpp" +#include "GlobalNamespace/MultiplayerModeSelectionFlowCoordinator.hpp" +using namespace GlobalNamespace; + + +MAKE_AUTO_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, SongPreviewPlayer* self) { + getLogger().info("is it true: %i", menuMusicLoader.loaded); + + if (!menuMusicLoader.OriginalAudioSource) { + menuMusicLoader.set_OriginalClip(self->_defaultAudioClip); + } + + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) + { + getLogger().debug("Overriding MenuMusic Audio"); + UnityEngine::AudioClip* audioClip = menuMusicLoader.getClip(); + if (audioClip != nullptr) + self->_defaultAudioClip = audioClip; + } + else { + getLogger().debug("Loading MenuMusic Audio normally: isLoaded='{}' isActive='{}'", menuMusicLoader.loaded, Config.Sounds.MenuMusic.Active); + self->_defaultAudioClip = menuMusicLoader.get_OriginalClip(); + } + SongPreviewPlayer_OnEnable(self); +} + +MAKE_AUTO_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlowCoordinator::DidActivate, void, GameServerLobbyFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) +{ + getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); + if (!lobbyAmbienceLoader.OriginalAudioSource) lobbyAmbienceLoader.set_OriginalClip(self->_ambienceAudioClip); + + if (lobbyAmbienceLoader.loaded && Config.Sounds.LobbyMusic.Active) + { + getLogger().debug("Overwriting LobbyAmbience Audio"); + self->_ambienceAudioClip = lobbyAmbienceLoader.getClip(); + } + else { + self->_ambienceAudioClip = lobbyAmbienceLoader.get_OriginalClip(); + } + GameServerLobbyFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); +} + +MAKE_AUTO_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidDeactivate, &GameServerLobbyFlowCoordinator::DidDeactivate, void, GameServerLobbyFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) +{ + getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) + { + getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); + self->_ambienceAudioClip = menuMusicLoader.getClip(); + } + else { + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + } + GameServerLobbyFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); +} + +MAKE_AUTO_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidActivate, &MultiplayerModeSelectionFlowCoordinator::DidActivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) +{ + getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidActivate"); + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) + { + getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); + self->_ambienceAudioClip = menuMusicLoader.getClip(); + } + else { + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + } + MultiplayerModeSelectionFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); // This has to be ran last, otherwise it will not work correctly +} + +MAKE_AUTO_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidDeactivate, &MultiplayerModeSelectionFlowCoordinator::DidDeactivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) +{ + getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidDeactivate"); + if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) + { + self->_ambienceAudioClip = menuMusicLoader.getClip(); + } + else { + self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); + } + + MultiplayerModeSelectionFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); +} \ No newline at end of file diff --git a/src/Hooks/LevelResultSoundHooks.cpp b/src/Hooks/LevelResultSoundHooks.cpp new file mode 100644 index 0000000..3ca3a6c --- /dev/null +++ b/src/Hooks/LevelResultSoundHooks.cpp @@ -0,0 +1,77 @@ +#include "hooking.hpp" +#include "logging.hpp" +#include "Config.hpp" +using namespace QuestSounds; + +// TODO: I'd like to get rid of this header +#include "AudioClips.hpp" +using namespace QuestSounds::AudioClips; + +#include "GlobalNamespace/ResultsViewController.hpp" +#include "GlobalNamespace/LevelCompletionResults.hpp" +#include "GlobalNamespace/SongPreviewPlayer.hpp" +#include "GlobalNamespace/FireworkItemController.hpp" +using namespace GlobalNamespace; + +#pragma region LevelResultSound +MAKE_AUTO_HOOK_MATCH(ResultsViewController_DidActivate, &ResultsViewController::DidActivate, void, ResultsViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { + if (firstActivation && addedToHierarchy && !levelClearedLoader.OriginalAudioSource) { + levelClearedLoader.set_OriginalClip(self->_levelClearedAudioClip); + } + if (self->_levelCompletionResults->levelEndStateType == LevelCompletionResults::LevelEndStateType::Failed) { + self->_songPreviewPlayer->StopAllCoroutines(); + if (levelFailedLoader.loaded && addedToHierarchy && Config.Sounds.LevelFailed.Active) { + UnityEngine::AudioClip* FailedSound = levelFailedLoader.getClip(); + float length = FailedSound->get_length(); + getLogger().debug("Duration of LevelFailed Sound: {}", length); + if (length > 7.0f) { + getLogger().info("Long LevelFailedSound"); + self->_songPreviewPlayer->CrossfadeTo(FailedSound, -4.0f, 0.0f, length, nullptr); + } + else { + getLogger().info("Short LevelFailedSound"); + self->_songPreviewPlayer->FadeOut(0.1f); + self->_songPreviewPlayer->_fadeSpeed = self->_songPreviewPlayer->_fadeInSpeed; + getLogger().debug("volume: {}", self->_songPreviewPlayer->_volume); + getLogger().debug("AmbientVolume: {}", self->_songPreviewPlayer->_ambientVolumeScale); + getLogger().debug("Set Volume: {}", self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); + + levelFailedLoader.audioSource->set_volume(self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); + self->_songPreviewPlayer->StartCoroutine(self->_songPreviewPlayer->CrossFadeAfterDelayCoroutine(length - 1.2f)); + levelFailedLoader.audioSource->Play(); + } + } + } + else { + if (levelClearedLoader.loaded && addedToHierarchy && Config.Sounds.LevelCleared.Active) + { + UnityEngine::AudioClip* audioClip = levelClearedLoader.getClip(); + self->_levelClearedAudioClip = audioClip; + } + else { + self->_levelClearedAudioClip = levelClearedLoader.get_OriginalClip(); + } + } + ResultsViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); +} + +MAKE_AUTO_HOOK_MATCH(ResultsViewController_RestartButtonPressed, &ResultsViewController::RestartButtonPressed, void, ResultsViewController* self) { + if (levelFailedLoader.loaded && levelFailedLoader.audioSource->get_isPlaying()) { + levelFailedLoader.audioSource->Stop(); + } + ResultsViewController_RestartButtonPressed(self); +} +#pragma endregion + +#pragma region FireworkSound +// Replacing the function here, as replacing the AudioClips proves to be difficult +MAKE_AUTO_HOOK_MATCH(FireworkItemController_PlayExplosionSound, &FireworkItemController::PlayExplosionSound, void, FireworkItemController* self) { + if (fireworkSoundLoader.loaded && Config.Sounds.Firework.Active) { + self->_audioSource->set_clip(fireworkSoundLoader.getClip()); + float pitch = 1.2f + (((float)rand()) / (float)RAND_MAX) * (0.8f - 1.2f); + self->_audioSource->set_pitch(pitch); + self->_audioSource->Play(); + } + else FireworkItemController_PlayExplosionSound(self); +} +#pragma endregion \ No newline at end of file diff --git a/src/Hooks/NoteSoundHook.cpp b/src/Hooks/NoteSoundHook.cpp new file mode 100644 index 0000000..920b4b1 --- /dev/null +++ b/src/Hooks/NoteSoundHook.cpp @@ -0,0 +1,70 @@ +#include "hooking.hpp" +#include "logging.hpp" +#include "Config.hpp" +using namespace QuestSounds; + +// TODO: I'd like to get rid of this header +#include "AudioClips.hpp" +using namespace QuestSounds::AudioClips; + +#include "GlobalNamespace/NoteCutSoundEffectManager.hpp" +#include "GlobalNamespace/NoteCutSoundEffect.hpp" +#include "GlobalNamespace/BeatmapObjectManager.hpp" +#include "GlobalNamespace/NoteController.hpp" +#include "GlobalNamespace/NoteData.hpp" +#include "GlobalNamespace/PauseMenuManager.hpp" +using namespace GlobalNamespace; + + + +MAKE_AUTO_HOOK_MATCH(NoteCutSoundEffectManager_Start, &NoteCutSoundEffectManager::Start, void, NoteCutSoundEffectManager* self) { + if(hitSoundLoader.loaded && Config.Sounds.HitSound.Active) + { + hitSoundArr = createAudioClipArray(hitSoundLoader); + self->_longCutEffectsAudioClips = hitSoundArr; + self->_shortCutEffectsAudioClips = hitSoundArr; + getLogger().debug("NoteCutSoundEffectManager_Start: Loaded hitSoundArray"); + } + else { + getLogger().debug("NoteCutSoundEffectManager_Start: Loading normally"); + } + getLogger().debug("audioSamplesBeatAlignOffset was: {}", self->_audioSamplesBeatAlignOffset); + if (Config.Sounds.HitSound.BeatOffset.has_value()) + self->_audioSamplesBeatAlignOffset = Config.Sounds.HitSound.BeatOffset.value(); + getLogger().debug("audioSamplesBeatAlignOffset changed to: {}", self->_audioSamplesBeatAlignOffset); + NoteCutSoundEffectManager_Start(self); + getLogger().debug("Beatalign offset is: {}", self->_beatAlignOffset); +} + +MAKE_AUTO_HOOK_MATCH(NoteCutSoundEffect_Awake, &NoteCutSoundEffect::Awake, void, NoteCutSoundEffect* self) { + if (hitSoundLoader.loaded && Config.Sounds.HitSound.Active) { + self->_goodCutVolume += Config.Sounds.HitSound.VolumeOffset.value_or(0.0f); + } + + if(badHitSoundLoader.loaded && Config.Sounds.BadHitSound.Active) + { + badHitSoundArr = createAudioClipArray(badHitSoundLoader); + self->_badCutSoundEffectAudioClips = badHitSoundArr; + self->_badCutVolume += Config.Sounds.BadHitSound.VolumeOffset.value_or(0.0f); + } + NoteCutSoundEffect_Awake(self); +} + +MAKE_AUTO_HOOK_MATCH(BeatmapObjectManager_HandleNoteWasMissed, &BeatmapObjectManager::HandleNoteControllerNoteWasMissed, void, BeatmapObjectManager* self, NoteController* noteController) { + BeatmapObjectManager_HandleNoteWasMissed(self, noteController); + if (noteMissedSoundLoader.loaded && + Config.Sounds.NoteMissedSound.Active && + noteController->get_noteData()->get_scoringType() != NoteData::ScoringType::Ignore && + noteController->get_noteData()->get_gameplayType() != NoteData::GameplayType::Bomb) { + noteMissedSoundLoader.audioSource->set_volume(0.5f + Config.Sounds.NoteMissedSound.VolumeOffset.value_or(0.0f)); + noteMissedSoundLoader.audioSource->Play(); + } +} + +MAKE_AUTO_HOOK_MATCH(PauseMenuManager_MenuButtonPressed, &PauseMenuManager::MenuButtonPressed, void, PauseMenuManager* self) { + if (noteMissedSoundLoader.loaded && + Config.Sounds.NoteMissedSound.Active) { + if (noteMissedSoundLoader.audioSource) noteMissedSoundLoader.audioSource->Stop(); + } + PauseMenuManager_MenuButtonPressed(self); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index df3c94e..9cdf121 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,57 +1,31 @@ #include "main.hpp" #include "_config.h" +#include "hooking.hpp" #include "logging.hpp" #include "Utils/AsyncAudioClipLoader.hpp" -#include "UI/QuestSoundsFlowCoordinator.hpp" #include "Config.hpp" #include "AudioClips.hpp" using namespace QuestSounds::AudioClips; -#include "GlobalNamespace/ResultsViewController.hpp" #include "GlobalNamespace/SongPreviewPlayer.hpp" -#include "GlobalNamespace/NoteCutSoundEffectManager.hpp" -#include "GlobalNamespace/NoteCutSoundEffect.hpp" -#include "GlobalNamespace/NoteController.hpp" -#include "GlobalNamespace/NoteData.hpp" #include "GlobalNamespace/BasicUIAudioManager.hpp" -#include "GlobalNamespace/FireworkItemController.hpp" -#include "GlobalNamespace/GameServerLobbyFlowCoordinator.hpp" -#include "GlobalNamespace/MultiplayerModeSelectionFlowCoordinator.hpp" -#include "GlobalNamespace/BeatmapObjectManager.hpp" -#include "GlobalNamespace/PauseMenuManager.hpp" #include "GlobalNamespace/FileHelpers.hpp" - -#include "GlobalNamespace/LevelCompletionResults.hpp" using namespace GlobalNamespace; #include "System/Action.hpp" #include "UnityEngine/SceneManagement/Scene.hpp" #include "UnityEngine/SceneManagement/SceneManager.hpp" -#include "UnityEngine/MonoBehaviour.hpp" -#include "UnityEngine/WaitForSeconds.hpp" -#include "UnityEngine/Time.hpp" using namespace UnityEngine::SceneManagement; #include "bsml/shared/BSML.hpp" // TODO BSML -// #include "ViewControllers/MenuSdListViewController.hpp" -// #include "ViewControllers/HitSdListViewController.hpp" -// #include "ViewControllers/MenuClickSdListViewController.hpp" -// #include "ViewControllers/BadHitSdListViewController.hpp" -// #include "ViewControllers/FireworkSdListViewController.hpp" -// #include "ViewControllers/LevelClearedSdListViewController.hpp" -// #include "ViewControllers/LobbyMusicSdListViewController.hpp" -// #include "ViewControllers/ConfigViewController.hpp" -// #include "QSoundsFlowCoordinator.hpp" +#include "UI/QuestSoundsFlowCoordinator.hpp" using namespace QuestSounds; -// #include "custom-types/shared/register.hpp" -// using namespace custom_types; - #define RAPIDJSON_HAS_STDSTRING 1 inline modloader::ModInfo modInfo = {MOD_ID, VERSION, 0}; @@ -200,182 +174,12 @@ ::ArrayW<::UnityW<::UnityEngine::AudioClip>> origMenuClickArr; } } -MAKE_HOOK_MATCH(ResultsViewController_DidActivate, &ResultsViewController::DidActivate, void, ResultsViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { - if (firstActivation && addedToHierarchy && !levelClearedLoader.OriginalAudioSource) { - levelClearedLoader.set_OriginalClip(self->_levelClearedAudioClip); - } - if (self->_levelCompletionResults->levelEndStateType == LevelCompletionResults::LevelEndStateType::Failed) { - self->_songPreviewPlayer->StopAllCoroutines(); - if (levelFailedLoader.loaded && addedToHierarchy && Config.Sounds.LevelFailed.Active) { - UnityEngine::AudioClip* FailedSound = levelFailedLoader.getClip(); - float length = FailedSound->get_length(); - getLogger().debug("Duration of LevelFailed Sound: {}", length); - if (length > 7.0f) { - getLogger().info("Long LevelFailedSound"); - self->_songPreviewPlayer->CrossfadeTo(FailedSound, -4.0f, 0.0f, length, nullptr); - } - else { - getLogger().info("Short LevelFailedSound"); - self->_songPreviewPlayer->FadeOut(0.1f); - self->_songPreviewPlayer->_fadeSpeed = self->_songPreviewPlayer->_fadeInSpeed; - getLogger().debug("volume: {}", self->_songPreviewPlayer->_volume); - getLogger().debug("AmbientVolume: {}", self->_songPreviewPlayer->_ambientVolumeScale); - getLogger().debug("Set Volume: {}", self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); - - levelFailedLoader.audioSource->set_volume(self->_songPreviewPlayer->_volume * self->_songPreviewPlayer->_ambientVolumeScale); - self->_songPreviewPlayer->StartCoroutine(self->_songPreviewPlayer->CrossFadeAfterDelayCoroutine(length - 1.2f)); - levelFailedLoader.audioSource->Play(); - } - } - } - else { - if (levelClearedLoader.loaded && addedToHierarchy && Config.Sounds.LevelCleared.Active) - { - UnityEngine::AudioClip* audioClip = levelClearedLoader.getClip(); - self->_levelClearedAudioClip = audioClip; - } - else { - self->_levelClearedAudioClip = levelClearedLoader.get_OriginalClip(); - } - } - ResultsViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); -} - -MAKE_HOOK_MATCH(ResultsViewController_RestartButtonPressed, &ResultsViewController::RestartButtonPressed, void, ResultsViewController* self) { - if (levelFailedLoader.loaded && levelFailedLoader.audioSource->get_isPlaying()) { - levelFailedLoader.audioSource->Stop(); - } - ResultsViewController_RestartButtonPressed(self); -} - -MAKE_HOOK_MATCH(SongPreviewPlayer_OnEnable, &SongPreviewPlayer::OnEnable, void, SongPreviewPlayer* self) { - getLogger().info("is it true: %i", menuMusicLoader.loaded); - - if (!menuMusicLoader.OriginalAudioSource) { - menuMusicLoader.set_OriginalClip(self->_defaultAudioClip); - } - - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) - { - getLogger().debug("Overriding MenuMusic Audio"); - UnityEngine::AudioClip* audioClip = menuMusicLoader.getClip(); - if (audioClip != nullptr) - self->_defaultAudioClip = audioClip; - } - else { - getLogger().debug("Loading MenuMusic Audio normally: isLoaded='{}' isActive='{}'", menuMusicLoader.loaded, Config.Sounds.MenuMusic.Active); - self->_defaultAudioClip = menuMusicLoader.get_OriginalClip(); - } - SongPreviewPlayer_OnEnable(self); -} - -MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidActivate, &GameServerLobbyFlowCoordinator::DidActivate, void, GameServerLobbyFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) -{ - getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); - if (!lobbyAmbienceLoader.OriginalAudioSource) lobbyAmbienceLoader.set_OriginalClip(self->_ambienceAudioClip); - - if (lobbyAmbienceLoader.loaded && Config.Sounds.LobbyMusic.Active) - { - getLogger().debug("Overwriting LobbyAmbience Audio"); - self->_ambienceAudioClip = lobbyAmbienceLoader.getClip(); - } - else { - self->_ambienceAudioClip = lobbyAmbienceLoader.get_OriginalClip(); - } - GameServerLobbyFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); -} - -MAKE_HOOK_MATCH(GameServerLobbyFlowCoordinator_DidDeactivate, &GameServerLobbyFlowCoordinator::DidDeactivate, void, GameServerLobbyFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) -{ - getLogger().debug("GameServerLobbyFlowCoordinator_DidActivate"); - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) - { - getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); - self->_ambienceAudioClip = menuMusicLoader.getClip(); - } - else { - self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); - } - GameServerLobbyFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); -} - -MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidActivate, &MultiplayerModeSelectionFlowCoordinator::DidActivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) -{ - getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidActivate"); - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active) - { - getLogger().debug("Switching LobbyMusic to MenuMusic Audio"); - self->_ambienceAudioClip = menuMusicLoader.getClip(); - } - else { - self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); - } - MultiplayerModeSelectionFlowCoordinator_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); // This has to be ran last, otherwise it will not work correctly -} - -MAKE_HOOK_MATCH(MultiplayerModeSelectionFlowCoordinator_DidDeactivate, &MultiplayerModeSelectionFlowCoordinator::DidDeactivate, void, MultiplayerModeSelectionFlowCoordinator* self, bool removedFromHierarchy, bool screenSystemDisabling) -{ - getLogger().debug("MultiplayerModeSelectionFlowCoordinator_DidDeactivate"); - if (menuMusicLoader.loaded && Config.Sounds.MenuMusic.Active && removedFromHierarchy) - { - self->_ambienceAudioClip = menuMusicLoader.getClip(); - } - else { - self->_ambienceAudioClip = menuMusicLoader.get_OriginalClip(); - } - - MultiplayerModeSelectionFlowCoordinator_DidDeactivate(self, removedFromHierarchy, screenSystemDisabling); -} - #ifdef DEBUG MAKE_HOOK_MATCH(FileHelpers_GetEscapedURLForFilePath, &FileHelpers::GetEscapedURLForFilePath, StringW, StringW filePath) { return StringW("file://" + filePath); } #endif -MAKE_HOOK_MATCH(NoteCutSoundEffectManager_Start, &NoteCutSoundEffectManager::Start, void, NoteCutSoundEffectManager* self) { - if(hitSoundLoader.loaded && Config.Sounds.HitSound.Active) - { - hitSoundArr = createAudioClipArray(hitSoundLoader); - self->_longCutEffectsAudioClips = hitSoundArr; - self->_shortCutEffectsAudioClips = hitSoundArr; - getLogger().debug("NoteCutSoundEffectManager_Start: Loaded hitSoundArray"); - } - else { - getLogger().debug("NoteCutSoundEffectManager_Start: Loading normally"); - } - getLogger().debug("audioSamplesBeatAlignOffset was: {}", self->_audioSamplesBeatAlignOffset); - if (Config.Sounds.HitSound.BeatOffset.has_value()) - self->_audioSamplesBeatAlignOffset = Config.Sounds.HitSound.BeatOffset.value(); - getLogger().debug("audioSamplesBeatAlignOffset changed to: {}", self->_audioSamplesBeatAlignOffset); - NoteCutSoundEffectManager_Start(self); - getLogger().debug("Beatalign offset is: {}", self->_beatAlignOffset); -} - -MAKE_HOOK_MATCH(NoteCutSoundEffect_Awake, &NoteCutSoundEffect::Awake, void, NoteCutSoundEffect* self) { - if (hitSoundLoader.loaded && Config.Sounds.HitSound.Active) { - self->_goodCutVolume += Config.Sounds.HitSound.VolumeOffset.value_or(0.0f); - } - - if(badHitSoundLoader.loaded && Config.Sounds.BadHitSound.Active) - { - badHitSoundArr = createAudioClipArray(badHitSoundLoader); - self->_badCutSoundEffectAudioClips = badHitSoundArr; - self->_badCutVolume += Config.Sounds.BadHitSound.VolumeOffset.value_or(0.0f); - } - NoteCutSoundEffect_Awake(self); -} - -MAKE_HOOK_MATCH(BeatmapObjectManager_HandleNoteWasMissed, &BeatmapObjectManager::HandleNoteControllerNoteWasMissed, void, BeatmapObjectManager* self, NoteController* noteController) { - BeatmapObjectManager_HandleNoteWasMissed(self, noteController); - if (noteMissedSoundLoader.loaded && - Config.Sounds.NoteMissedSound.Active && - noteController->get_noteData()->get_scoringType() != NoteData::ScoringType::Ignore && - noteController->get_noteData()->get_gameplayType() != NoteData::GameplayType::Bomb) { - noteMissedSoundLoader.audioSource->set_volume(0.5f + Config.Sounds.NoteMissedSound.VolumeOffset.value_or(0.0f)); - noteMissedSoundLoader.audioSource->Play(); - } -} MAKE_HOOK_MATCH(BasicUIAudioManager_Start, &BasicUIAudioManager::Start, void, BasicUIAudioManager* self) { if (!menuClickLoader.OriginalAudioSource) menuClickLoader.set_OriginalClip(self->_clickSounds[0]); @@ -388,25 +192,6 @@ MAKE_HOOK_MATCH(BasicUIAudioManager_Start, &BasicUIAudioManager::Start, void, Ba BasicUIAudioManager_Start(self); } -// Replacing the function here, as replacing the AudioClips proves to be difficult -MAKE_HOOK_MATCH(FireworkItemController_PlayExplosionSound, &FireworkItemController::PlayExplosionSound, void, FireworkItemController* self) { - if (fireworkSoundLoader.loaded && Config.Sounds.Firework.Active) { - self->_audioSource->set_clip(fireworkSoundLoader.getClip()); - float pitch = 1.2f + (((float)rand()) / (float)RAND_MAX) * (0.8f - 1.2f); - self->_audioSource->set_pitch(pitch); - self->_audioSource->Play(); - } - else FireworkItemController_PlayExplosionSound(self); -} - -MAKE_HOOK_MATCH(PauseMenuManager_MenuButtonPressed, &PauseMenuManager::MenuButtonPressed, void, PauseMenuManager* self) { - if (noteMissedSoundLoader.loaded && - Config.Sounds.NoteMissedSound.Active) { - if (noteMissedSoundLoader.audioSource) noteMissedSoundLoader.audioSource->Stop(); - } - PauseMenuManager_MenuButtonPressed(self); -} - MAKE_HOOK_MATCH(SceneManager_Internal_ActiveSceneChanged, &SceneManager::Internal_ActiveSceneChanged, void, Scene previousActiveScene, Scene newActiveScene) { SceneManager_Internal_ActiveSceneChanged(previousActiveScene, newActiveScene); if (newActiveScene.IsValid()) { @@ -430,7 +215,7 @@ std::string& GetConfigPath() { return configPath; } -QS_EXPORT void setup(CModInfo *info) { +QS_EXPORT_FUNC void setup(CModInfo *info) { info->id = MOD_ID; info->version = VERSION; @@ -458,7 +243,7 @@ QS_EXPORT void setup(CModInfo *info) { getLogger().info("Completed setup!"); } -QS_EXPORT void late_load() +QS_EXPORT_FUNC void late_load() { il2cpp_functions::Init(); BSML::Init(); @@ -469,20 +254,21 @@ QS_EXPORT void late_load() makeFolder(); getLogger().debug("Installing QuestSounds!"); + QuestSounds::Hooking::InstallHooks(); INSTALL_HOOK(hkLog, SceneManager_Internal_ActiveSceneChanged); - INSTALL_HOOK(hkLog, PauseMenuManager_MenuButtonPressed); - INSTALL_HOOK(hkLog, SongPreviewPlayer_OnEnable); - INSTALL_HOOK(hkLog, NoteCutSoundEffectManager_Start); - INSTALL_HOOK(hkLog, NoteCutSoundEffect_Awake); - INSTALL_HOOK(hkLog, BeatmapObjectManager_HandleNoteWasMissed); + // INSTALL_HOOK(hkLog, PauseMenuManager_MenuButtonPressed); --> NoteSoundHooks.cpp + // INSTALL_HOOK(hkLog, SongPreviewPlayer_OnEnable); // --> BackgroundMusicHooks.cpp + // INSTALL_HOOK(hkLog, NoteCutSoundEffectManager_Start); --> NoteSoundHooks.cpp + // INSTALL_HOOK(hkLog, NoteCutSoundEffect_Awake); --> NoteSoundHooks.cpp + // INSTALL_HOOK(hkLog, BeatmapObjectManager_HandleNoteWasMissed); INSTALL_HOOK(hkLog, BasicUIAudioManager_Start); - INSTALL_HOOK(hkLog, ResultsViewController_DidActivate); - INSTALL_HOOK(hkLog, ResultsViewController_RestartButtonPressed); - INSTALL_HOOK(hkLog, FireworkItemController_PlayExplosionSound) - INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music - INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music - INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music - INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music + // INSTALL_HOOK(hkLog, ResultsViewController_DidActivate); --> LevelResultSoundHooks.cpp + // INSTALL_HOOK(hkLog, ResultsViewController_RestartButtonPressed); --> LevelResultSoundHooks.cpp + // INSTALL_HOOK(hkLog, FireworkItemController_PlayExplosionSound); --> LevelResultSoundHooks.cpp + // INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music --> BackgroundMusicHooks.cpp + // INSTALL_HOOK(hkLog, MultiplayerModeSelectionFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music --> BackgroundMusicHooks.cpp + // INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidActivate); // Added for switching out MP Lobby Music --> BackgroundMusicHooks.cpp + // INSTALL_HOOK(hkLog, GameServerLobbyFlowCoordinator_DidDeactivate); // Added for switching out MP Lobby Music --> BackgroundMusicHooks.cpp // #ifdef DEBUG // auto ModList = Modloader::getMods(); // if (ModList.find("SongLoader") == ModList.end()) { From 258d3955de30d422a9666655729b675cc4a9c449 Mon Sep 17 00:00:00 2001 From: EnderdracheLP Date: Tue, 23 Jul 2024 22:56:46 +0200 Subject: [PATCH 40/55] WIP UI: Add left side panel, with tabs, UI tweaks --- assets/ConfigMenuSelectionViewController.bsml | 24 +++++ assets/SoundSettingsViewController.bsml | 39 ++++---- .../UI/ConfigMenuSelectionViewController.hpp | 30 ++++++ include/UI/QuestSoundsFlowCoordinator.hpp | 5 + include/UI/SoundSettingsViewController.hpp | 13 +++ include/assets.hpp | 1 + src/UI/ConfigMenuSelectionViewController.cpp | 92 +++++++++++++++++++ src/UI/QuestSoundsFlowCoordinator.cpp | 77 +++++++++++++++- src/UI/SoundSettingsViewController.cpp | 61 ++++++++++-- 9 files changed, 318 insertions(+), 24 deletions(-) create mode 100644 assets/ConfigMenuSelectionViewController.bsml create mode 100644 include/UI/ConfigMenuSelectionViewController.hpp create mode 100644 src/UI/ConfigMenuSelectionViewController.cpp diff --git a/assets/ConfigMenuSelectionViewController.bsml b/assets/ConfigMenuSelectionViewController.bsml new file mode 100644 index 0000000..525247f --- /dev/null +++ b/assets/ConfigMenuSelectionViewController.bsml @@ -0,0 +1,24 @@ + + + + +