diff --git a/src/layers/ExtendedLevelInfo.cpp b/src/layers/ExtendedLevelInfo.cpp index ca0afb2..49095bb 100644 --- a/src/layers/ExtendedLevelInfo.cpp +++ b/src/layers/ExtendedLevelInfo.cpp @@ -1,16 +1,11 @@ #include "ExtendedLevelInfo.h" -#include "UnregisteredProfileLayer.h" -#include "PaginatedFLAlert.h" #include "../utils.hpp" -#include "../managers/BetterInfoStats.h" //#include "../managers/BetterInfoStatsV2.h" #include "../managers/BetterInfoCache.h" -#include #include #include #include -#include ExtendedLevelInfo* ExtendedLevelInfo::create(GJGameLevel* level){ auto ret = new ExtendedLevelInfo(); @@ -96,8 +91,8 @@ void ExtendedLevelInfo::refreshInfoTexts() { m_primary = infoText.str(); infoText.str(""); - infoText << "\nUploaded: " << TimeUtils::isoTimeToString(m_uploadDateEstimated) - << "\nObjects: " << LevelMetadata::zeroIfNA(m_level->m_objectCount) + if(!ServerUtils::isGDPS()) infoText << "\nUploaded: " << TimeUtils::isoTimeToString(m_uploadDateEstimated); + infoText << "\nObjects: " << LevelMetadata::zeroIfNA(m_level->m_objectCount) << "\nObjects (est.): " << LevelMetadata::zeroIfNA(m_objectsEstimated) //i have no idea what the 0 and 11 mean, i just copied them from PlayLayer::init << "\nFeature Score: " << LevelMetadata::zeroIfNA(m_level->m_featured) << "\nTwo-player: " << LevelMetadata::boolString(m_level->m_twoPlayerMode) diff --git a/src/utils/LevelMetadata.cpp b/src/utils/LevelMetadata.cpp index 7b80087..5a34a82 100644 --- a/src/utils/LevelMetadata.cpp +++ b/src/utils/LevelMetadata.cpp @@ -3,6 +3,15 @@ #include #include +bool isRobTopStyleDate(const std::string& date){ + std::array times = {"second", "minute", "hour", "day", "week", "month", "year"}; + for(auto time : times) if(date.contains(time)) { + return true; + } + + return false; +} + std::string LevelMetadata::getGameVersionName(int version){ if(version < 1 || version > 99) return std::string("NA"); @@ -24,10 +33,13 @@ std::string LevelMetadata::getGameVersionName(int version){ return contentStream.str(); } -std::string LevelMetadata::stringDate(std::string date){ +std::string LevelMetadata::stringDate(const std::string& date){ if(date == "") return "NA"; std::ostringstream stream; - stream << date << " ago"; + + stream << date; + if(isRobTopStyleDate(date)) stream << " ago"; + return stream.str(); } @@ -84,6 +96,8 @@ std::string LevelMetadata::zeroIfNA(int value){ } std::string LevelMetadata::addPlus(std::string date) { + if(!isRobTopStyleDate(date)) return date; + auto spaceIt = date.find_first_of(' '); if(spaceIt != std::string::npos) date.insert(date.cbegin() + spaceIt, '+'); return date; diff --git a/src/utils/LevelMetadata.h b/src/utils/LevelMetadata.h index 448fed2..a3a9a8f 100644 --- a/src/utils/LevelMetadata.h +++ b/src/utils/LevelMetadata.h @@ -5,7 +5,7 @@ namespace LevelMetadata { BI_DLL std::string getGameVersionName(int version); - BI_DLL std::string stringDate(std::string date); + BI_DLL std::string stringDate(const std::string& date); BI_DLL const char* getDifficultyIcon(int stars); BI_DLL const char* getDemonDifficultyIcon(int demonDifficulty); BI_DLL std::string passwordString(int password); diff --git a/src/utils/ServerUtils.cpp b/src/utils/ServerUtils.cpp index e45d685..d651ccc 100644 --- a/src/utils/ServerUtils.cpp +++ b/src/utils/ServerUtils.cpp @@ -9,12 +9,28 @@ static inline std::unordered_map> s_cache; static inline std::unordered_map s_requests; static inline std::shared_mutex s_requestsMutex; +static bool s_isGDPS = false; + +bool ServerUtils::isGDPS() { + return getBaseURL() != "https://www.boomlings.com/database"; +} web::WebRequest ServerUtils::getBaseRequest(bool setUserAgent) { return web::WebRequest().userAgent(setUserAgent ? fmt::format("BetterInfo {} / Geode {}", Mod::get()->getVersion().toVString(true), Loader::get()->getVersion().toVString(true)) : ""); } std::string ServerUtils::getBaseURL() { + // A cleaner solution for this would be a Server API dependency + // however I'd rather avoid depending on a mod that 90% of users + // don't actually use + if(Loader::get()->isModLoaded("km7dev.gdps-switcher")) { + auto url = Loader::get()->getLoadedMod("km7dev.gdps-switcher")->getSavedValue("server"); + if(!url.empty()) { + while(url.ends_with("/")) url.pop_back(); + return url; + } + } + // The addresses are pointing to "https://www.boomlings.com/database/getGJLevels21.php" // in the main game executable char* originalUrl = nullptr; diff --git a/src/utils/ServerUtils.h b/src/utils/ServerUtils.h index 7f1a0c2..2dafd2b 100644 --- a/src/utils/ServerUtils.h +++ b/src/utils/ServerUtils.h @@ -8,6 +8,7 @@ using namespace geode::prelude; namespace ServerUtils { + BI_DLL bool isGDPS(); BI_DLL web::WebRequest getBaseRequest(bool setUserAgent = true); BI_DLL std::string getBaseURL(); BI_DLL std::string getBasePostString(bool includeAccount = true);