diff --git a/include/beatsaber/beatsaber.h b/include/beatsaber/beatsaber.h new file mode 100644 index 0000000..3027977 --- /dev/null +++ b/include/beatsaber/beatsaber.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace Beatsaber { + +const uint32_t STEAMGAMEID = 620980; +std::string findBeatsaberInstallation(); + + +} \ No newline at end of file diff --git a/src/beatlevel.cpp b/src/beatlevel.cpp index 4ed7b20..5f212dd 100644 --- a/src/beatlevel.cpp +++ b/src/beatlevel.cpp @@ -94,6 +94,7 @@ void BeatLevelImpl::printDebug() const { << "\n Filename: " << getFilename() << "\n njs: " << getNoteJumpSpeed() << " nso: " << getNoteStartOffset() << "\n noteCount: " << notes.size() << " wallCount: " << walls.size() + << "\n CustomData: " << getCustomData() << std::endl; } diff --git a/src/beatsaber.cpp b/src/beatsaber.cpp new file mode 100644 index 0000000..9854616 --- /dev/null +++ b/src/beatsaber.cpp @@ -0,0 +1,73 @@ +#include "beatsaber.h" + +#if __unix__ +#include +#include +#include +#endif + +#include +#include //debug print +#include + +namespace Beatsaber { + +#if __unix__ +static std::string getSteamDefault() { + //get the user process + uid_t user = getuid(); + struct passwd pwd; + struct passwd* res; + char buf[4096]; + getpwuid_r(user, &pwd, buf, sizeof(buf), &res); + + char* userdirc = pwd.pw_dir; + std::string userdir(userdirc); + + return userdir + "/.steam/steam"; +} +#endif + +std::string findBeatsaberInstallation() { + //get all steamfolders + const std::string defaultSteam = getSteamDefault() + "/steamapps/"; + std::ifstream libinfo(defaultSteam + "libraryfolders.vdf"); + std::string firstline; + libinfo >> firstline; //remove first line, should contain: "\"LibraryFolders\"" + + std::list paths; + paths.push_back(defaultSteam); + + std::string line; + while(std::getline(libinfo, line)) { + if(!line.empty() && line[0] == '\t') { + int num; + char pathbuffer[512]; + int res = sscanf(line.c_str(), "\t\"%d\" \t\"%s\"", &num, pathbuffer); + if(res == 2) { + std::string path(pathbuffer); + paths.push_back(path + "/steamapps/"); + } + } + } + libinfo.close(); + + std::cout << paths.size() << " steam libs found" << std::endl; + + //search in libs for beatsaber + for(const std::string& it : paths) { + std::ifstream appmanifest(it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf"); + if(appmanifest.is_open()) { + //found it! + //do stuff with the manifest??? + + appmanifest.close(); + + return it + "common/Beat Saber/"; + } + } + + return ""; //not found +} + +} \ No newline at end of file diff --git a/tests/main.cpp b/tests/main.cpp index c88f394..da986e4 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -2,6 +2,7 @@ #include "test.h" #include "beatmap.h" +#include "beatsaber.h" //tests int difficulties_test(); @@ -29,6 +30,10 @@ int main(int argc, char** argv) { printf("\033[1;93m%d\033[0;1m/%d failed\n", failcount, testcount); + //beatsaber installation dir discovery test + std::string installdir = Beatsaber::findBeatsaberInstallation(); + std::cout << "Beatsaber installation directory: " << installdir << std::endl; + //simple read test 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;