From 03cd4b382283d8d1ab047f093dd70087f584c71f Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sat, 12 Jun 2021 18:04:14 +0200 Subject: [PATCH] load beatsaber safedata --- include/beatsaber/beatsaber.h | 6 ++++++ src/beatlevel.cpp | 7 ++++++- src/beatmap.cpp | 14 +++++++++++--- src/beatsaber.cpp | 31 ++++++++++++++++++++++++++++++- src/beatset.cpp | 2 +- tests/main.cpp | 13 ++++++++++++- 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/include/beatsaber/beatsaber.h b/include/beatsaber/beatsaber.h index 3027977..50960e0 100644 --- a/include/beatsaber/beatsaber.h +++ b/include/beatsaber/beatsaber.h @@ -1,11 +1,17 @@ #pragma once #include +#include + +#include "beatmap.h" namespace Beatsaber { const uint32_t STEAMGAMEID = 620980; std::string findBeatsaberInstallation(); +// when gamepath is empty, findBeatsaberInstallation is used to get a Path +// from the installation folder as many mas as possible are loaded +std::list> loadMapsfromInstallation(std::string gamePath = ""); } \ No newline at end of file diff --git a/src/beatlevel.cpp b/src/beatlevel.cpp index 5f212dd..3d66862 100644 --- a/src/beatlevel.cpp +++ b/src/beatlevel.cpp @@ -5,6 +5,7 @@ #include "beatset.h" #include "beatnoteimpl.h" +#include "beatmap.h" // for debug print namespace Beatsaber { @@ -46,7 +47,11 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr p, std::shared_ptrgetBeatMap()->getSongName(); + std::cout << "Could not load difficulty: " << filename << " from: " << mapname << std::endl; //is the direct access after p.lock() a problem? is the parent always loaded? } } } diff --git a/src/beatmap.cpp b/src/beatmap.cpp index 8012e31..036ea09 100644 --- a/src/beatmap.cpp +++ b/src/beatmap.cpp @@ -2,6 +2,10 @@ #include //debug print +#if BEATSABERZIPSUPPORT == 1 +#include +#endif + #include "beatsetimpl.h" #include "filereaderimpl.h" @@ -156,9 +160,13 @@ std::shared_ptr BeatMap::loadFromFolder(const std::string& folderPath) std::shared_ptr BeatMap::loadFromZip(const std::string& zipPath) { #if BEATSABERZIPSUPPORT == 1 - auto map = std::make_shared(std::make_shared(zipPath)); - if(!map->load()) return nullptr; - return map; + try { + auto map = std::make_shared(std::make_shared(zipPath)); + if(!map->load()) return nullptr; + return map; + } catch(zipios::Exception& e) { + return nullptr; + } #else // Zip not supported std::cerr << "Zip not supported" << std::endl; diff --git a/src/beatsaber.cpp b/src/beatsaber.cpp index ca7d0b2..19044ef 100644 --- a/src/beatsaber.cpp +++ b/src/beatsaber.cpp @@ -9,6 +9,7 @@ #include #include //debug print #include +#include namespace Beatsaber { @@ -56,13 +57,14 @@ std::string findBeatsaberInstallation() { //search in libs for beatsaber for(const std::string& it : paths) { + //check if manifest exists const std::string appmani = it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf"; //std::cout << "Try to read file: " << appmani << std::endl; std::ifstream appmanifest(appmani); if(appmanifest.is_open()) { //found it! //do stuff with the manifest??? - + appmanifest.close(); return it + "common/Beat Saber/"; @@ -72,4 +74,31 @@ std::string findBeatsaberInstallation() { return ""; //not found } +std::list> loadMapsfromInstallation(std::string gamePath) { + if(gamePath.empty()) { + gamePath = findBeatsaberInstallation(); + } + + std::filesystem::path path(gamePath); + + std::list> out; + + for(const auto& i : std::filesystem::directory_iterator(path / "Beat Saber_Data/CustomLevels")) { + if(i.exists()) { + if(i.is_directory()) { + //try to load + auto map = BeatMap::loadFromFolder(i.path().string()); + if(map) + out.push_back(map); + } else if(i.is_regular_file()) { + auto map = BeatMap::loadFromZip(i.path().string()); + if(map) + out.push_back(map); + } + } + } + + return out; +} + } \ No newline at end of file diff --git a/src/beatset.cpp b/src/beatset.cpp index a733e79..b2b0a04 100644 --- a/src/beatset.cpp +++ b/src/beatset.cpp @@ -15,7 +15,7 @@ BeatSetImpl::BeatSetImpl(std::weak_ptr p, std::shared_ptr r const json& arr = j["_difficultyBeatmaps"]; if(arr.is_array()) { level.reserve(arr.size()); - std::cout << "Try to load: " << arr.size() << std::endl; + //std::cout << "Try to load: " << arr.size() << " BeatLevel" << std::endl; for(const json& beat : arr) { level.push_back(std::make_shared(weak_from_this(), r, beat)); } diff --git a/tests/main.cpp b/tests/main.cpp index da986e4..0cf6298 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -34,13 +34,24 @@ int main(int argc, char** argv) { std::string installdir = Beatsaber::findBeatsaberInstallation(); std::cout << "Beatsaber installation directory: " << installdir << std::endl; + auto list = Beatsaber::loadMapsfromInstallation(); + std::cout << "Loaded: " << list.size() << " Maps from Beatsaber Installation" << std::endl; + + /*for(auto i : list) { + if(i) { + i->printDebug(); + std::cin.get(); + } + }*/ + //simple read test - std::shared_ptr bmap = Beatsaber::BeatMap::loadFromFolder("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)"); + /*std::shared_ptr bmap = Beatsaber::BeatMap::loadFromFolder("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)"); if(!bmap) std::cout << "Could not load File" << std::endl; else bmap->printDebug(); bmap = Beatsaber::BeatMap::loadFromZip("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/18b92 (Empress of Light - ShadowLantern).zip"); if(!bmap) std::cout << "Could not load File" << std::endl; else bmap->printDebug(); + */ return failcount > 0; }