Skip to content

Commit

Permalink
Update to 1.40.2
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenAlex committed Feb 16, 2025
1 parent b6a7c89 commit 8578bcb
Show file tree
Hide file tree
Showing 22 changed files with 317 additions and 335 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_link_options(-Wl,--exclude-libs,ALL)
add_compile_options(-frtti -fPIE -fPIC -fexceptions -fvisibility=hidden)

if(${CMAKE_BUILD_TYPE} STREQUAL "RELEASE" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" OR ${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel")

# Better optimizations
add_compile_options(-O3)

Expand Down Expand Up @@ -67,13 +67,18 @@ RECURSE_FILES(cpp_file_list ${SOURCE_DIR}/*.cpp)
RECURSE_FILES(cpp_file_test_list ./test/src/*.cpp)
RECURSE_FILES(c_file_list ${SOURCE_DIR}/*.c)

RECURSE_FILES(inline_hook_c ${EXTERN_DIR}/includes/beatsaber-hook/shared/inline-hook/*.c)
RECURSE_FILES(inline_hook_cpp ${EXTERN_DIR}/includes/beatsaber-hook/shared/inline-hook/*.cpp)

# add all src files to compile
add_library(
${COMPILE_ID}
SHARED
${cpp_file_list}
${cpp_file_test_list}
${c_file_list}
${inline_hook_c}
${inline_hook_cpp}
)

target_include_directories(${COMPILE_ID} PRIVATE .)
Expand Down
180 changes: 101 additions & 79 deletions include/FilterOptions.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once

#include <vector>
#include <tuple>
#include <vector>

#include "rapidjson-macros/shared/macros.hpp"
#include "PluginConfig.hpp"
#include "rapidjson-macros/shared/macros.hpp"

namespace BetterSongSearch {
DECLARE_JSON_CLASS(FilterProfile,
VALUE_DEFAULT(int, downloadType, (int)FilterTypes::DownloadFilter::All);
VALUE_DEFAULT(int, localScoreType, (int)FilterTypes::LocalScoreFilter::All);
VALUE_DEFAULT(int, rankedType, (int)FilterTypes::RankedFilter::ShowAll);
VALUE_DEFAULT(int, difficultyFilter, (int)FilterTypes::DifficultyFilter::All);
VALUE_DEFAULT(int, charFilter, (int)FilterTypes::CharFilter::All);
VALUE_DEFAULT(int, modRequirement, (int)FilterTypes::Requirement::Any);
DECLARE_JSON_STRUCT(FilterProfile) {
VALUE_DEFAULT(int, downloadType, (int) FilterTypes::DownloadFilter::All);
VALUE_DEFAULT(int, localScoreType, (int) FilterTypes::LocalScoreFilter::All);
VALUE_DEFAULT(int, rankedType, (int) FilterTypes::RankedFilter::ShowAll);
VALUE_DEFAULT(int, difficultyFilter, (int) FilterTypes::DifficultyFilter::All);
VALUE_DEFAULT(int, charFilter, (int) FilterTypes::CharFilter::All);
VALUE_DEFAULT(int, modRequirement, (int) FilterTypes::Requirement::Any);

VALUE_DEFAULT(float, minLength, 0);
VALUE_DEFAULT(float, maxLength, 900);
Expand All @@ -40,73 +40,95 @@ namespace BetterSongSearch {
VALUE_DEFAULT(std::string, mapGenreString, "");
VALUE_DEFAULT(std::string, mapGenreExcludeString, "");

public:
bool IsEqual(const FilterProfile& other) const;

// Because RapidJSON does not support enums... we have to make methods to convert them to/from int
FilterTypes::DownloadFilter getDownloadType() { return (FilterTypes::DownloadFilter) downloadType; };
FilterTypes::LocalScoreFilter getLocalScoreType() { return (FilterTypes::LocalScoreFilter) localScoreType; };
FilterTypes::RankedFilter getRankedType() { return (FilterTypes::RankedFilter) rankedType; };
FilterTypes::DifficultyFilter getDifficultyFilter() { return (FilterTypes::DifficultyFilter) difficultyFilter; };
FilterTypes::CharFilter getCharFilter() { return (FilterTypes::CharFilter) charFilter; };
FilterTypes::Requirement getModRequirement() { return (FilterTypes::Requirement) modRequirement; };
void setDownloadType(FilterTypes::DownloadFilter value) { downloadType = (int) value; };
void setLocalScoreType(FilterTypes::LocalScoreFilter value) { localScoreType = (int) value; };
void setRankedType(FilterTypes::RankedFilter value) { rankedType = (int) value; };
void setDifficultyFilter(FilterTypes::DifficultyFilter value) { difficultyFilter = (int) value; };
void setCharFilter(FilterTypes::CharFilter value) { charFilter = (int) value; };
void setModRequirement(FilterTypes::Requirement value) { modRequirement = (int) value; };


// This value is valid only if the related filter is not set to "All" and recalculated
SongDetailsCache::MapCharacteristic charFilterPreprocessed = SongDetailsCache::MapCharacteristic::Custom;
// This value is valid only if the related filter is not set to "All" and recalculated
SongDetailsCache::MapDifficulty difficultyFilterPreprocessed = SongDetailsCache::MapDifficulty::Easy;

uint64_t _mapStyleBitfield = 0;
uint64_t _mapGenreBitfield = 0;
uint64_t _mapGenreExcludeBitfield = 0;

bool isDefaultPreprocessed = true;

// @brief Checks if the profile is the default profile (no filters)
bool IsDefault();

// @brief Recalculates preprocessed values (variables that are used in search)
void RecalculatePreprocessedValues();

// @brief Loads the profile from the mod config
void LoadFromConfig();

// @brief Saves the profile to the mod config
void SaveToConfig();

void PrintToDebug();


// @brief Counts the included and excluded tags in the profile
// @return A tuple with the count of included and excluded tags
std::tuple<int, int> CountTags();

// @brief Saves the profile to a preset
// @param presetName The name of the preset to save
// @return True if the preset was saved successfully
bool SaveToPreset(std::string presetName) const;

// @brief Deletes a preset
// @param presetName The name of the preset to delete
// @return True if the preset was deleted successfully
static bool DeletePreset(std::string presetName);

// @brief Gets a list of all available presets
// @return A list of all available presets
static std::vector<std::string> GetPresetList();

// @brief Loads the profile from a preset
// @param presetName The name of the preset to load
// @return The loaded profile
static std::optional<FilterProfile> LoadFromPreset(std::string presetName);

void CopyFrom(const FilterProfile& other);
)
}
public:
bool IsEqual(FilterProfile const& other) const;

// Because RapidJSON does not support enums... we have to make methods to convert them to/from int
FilterTypes::DownloadFilter getDownloadType() {
return (FilterTypes::DownloadFilter) downloadType;
};
FilterTypes::LocalScoreFilter getLocalScoreType() {
return (FilterTypes::LocalScoreFilter) localScoreType;
};
FilterTypes::RankedFilter getRankedType() {
return (FilterTypes::RankedFilter) rankedType;
};
FilterTypes::DifficultyFilter getDifficultyFilter() {
return (FilterTypes::DifficultyFilter) difficultyFilter;
};
FilterTypes::CharFilter getCharFilter() {
return (FilterTypes::CharFilter) charFilter;
};
FilterTypes::Requirement getModRequirement() {
return (FilterTypes::Requirement) modRequirement;
};
void setDownloadType(FilterTypes::DownloadFilter value) {
downloadType = (int) value;
};
void setLocalScoreType(FilterTypes::LocalScoreFilter value) {
localScoreType = (int) value;
};
void setRankedType(FilterTypes::RankedFilter value) {
rankedType = (int) value;
};
void setDifficultyFilter(FilterTypes::DifficultyFilter value) {
difficultyFilter = (int) value;
};
void setCharFilter(FilterTypes::CharFilter value) {
charFilter = (int) value;
};
void setModRequirement(FilterTypes::Requirement value) {
modRequirement = (int) value;
};

// This value is valid only if the related filter is not set to "All" and recalculated
SongDetailsCache::MapCharacteristic charFilterPreprocessed = SongDetailsCache::MapCharacteristic::Custom;
// This value is valid only if the related filter is not set to "All" and recalculated
SongDetailsCache::MapDifficulty difficultyFilterPreprocessed = SongDetailsCache::MapDifficulty::Easy;

uint64_t _mapStyleBitfield = 0;
uint64_t _mapGenreBitfield = 0;
uint64_t _mapGenreExcludeBitfield = 0;

bool isDefaultPreprocessed = true;

// @brief Checks if the profile is the default profile (no filters)
bool IsDefault();

// @brief Recalculates preprocessed values (variables that are used in search)
void RecalculatePreprocessedValues();

// @brief Loads the profile from the mod config
void LoadFromConfig();

// @brief Saves the profile to the mod config
void SaveToConfig();

void PrintToDebug();

// @brief Counts the included and excluded tags in the profile
// @return A tuple with the count of included and excluded tags
std::tuple<int, int> CountTags();

// @brief Saves the profile to a preset
// @param presetName The name of the preset to save
// @return True if the preset was saved successfully
bool SaveToPreset(std::string presetName) const;

// @brief Deletes a preset
// @param presetName The name of the preset to delete
// @return True if the preset was deleted successfully
static bool DeletePreset(std::string presetName);

// @brief Gets a list of all available presets
// @return A list of all available presets
static std::vector<std::string> GetPresetList();

// @brief Loads the profile from a preset
// @param presetName The name of the preset to load
// @return The loaded profile
static std::optional<FilterProfile> LoadFromPreset(std::string presetName);

void CopyFrom(FilterProfile const& other);
};
} // namespace BetterSongSearch
98 changes: 25 additions & 73 deletions include/PluginConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,27 @@
#include <string>
#include <unordered_map>

#include "config-utils/shared/config-utils.hpp"
#include "song-details/shared/Data/MapCharacteristic.hpp"
#include "song-details/shared/Data/MapDifficulty.hpp"
#include "song-details/shared/Data/RankedStates.hpp"
#include "song-details/shared/Data/SongDifficulty.hpp"

#include "config-utils/shared/config-utils.hpp"

static inline const float SONG_LENGTH_FILTER_MAX = 15.0f;
static inline const float STAR_FILTER_MAX = 18.0f;
static inline const float NJS_FILTER_MAX = 25.0f;
static inline const float NPS_FILTER_MAX = 12.0f;
static inline const int64_t BEATSAVER_EPOCH = 1525136400;
static inline const std::chrono::system_clock::time_point BEATSAVER_EPOCH_TIME_POINT{std::chrono::seconds(BEATSAVER_EPOCH)};
static inline float const SONG_LENGTH_FILTER_MAX = 15.0f;
static inline float const STAR_FILTER_MAX = 18.0f;
static inline float const NJS_FILTER_MAX = 25.0f;
static inline float const NPS_FILTER_MAX = 12.0f;
static inline int64_t const BEATSAVER_EPOCH = 1525136400;
static inline std::chrono::system_clock::time_point const BEATSAVER_EPOCH_TIME_POINT{std::chrono::seconds(BEATSAVER_EPOCH)};

static inline const std::vector<std::string> MAP_STYLES_OPTIONS = {
"Any", "accuracy", "balanced", "challenge", "dance", "fitness", "speed", "tech"
};
static inline std::vector<std::string> const MAP_STYLES_OPTIONS = {"Any", "accuracy", "balanced", "challenge", "dance", "fitness", "speed", "tech"};

namespace FilterTypes {
enum class DownloadFilter
{
All,
OnlyDownloaded,
HideDownloaded
};
enum class LocalScoreFilter
{
All,
HidePassed,
OnlyPassed
};
enum class RankedFilter
{
ShowAll,
ScoreSaberRanked,
BeatLeaderRanked,
ScoreSaberQualified,
BeatLeaderQualified
};
enum class DifficultyFilter
{
All,
Easy,
Normal,
Hard,
Expert,
ExpertPlus
};
enum class CharFilter
{
enum class DownloadFilter { All, OnlyDownloaded, HideDownloaded };
enum class LocalScoreFilter { All, HidePassed, OnlyPassed };
enum class RankedFilter { ShowAll, ScoreSaberRanked, BeatLeaderRanked, ScoreSaberQualified, BeatLeaderQualified };
enum class DifficultyFilter { All, Easy, Normal, Hard, Expert, ExpertPlus };
enum class CharFilter {
All,
Custom,
Standard,
Expand All @@ -64,34 +35,16 @@ namespace FilterTypes {
Lawless,
};

enum class Requirement {
Any,
NoodleExtensions,
MappingExtensions,
Chroma,
Cinema,
None
};
enum class Requirement { Any, NoodleExtensions, MappingExtensions, Chroma, Cinema, None };

enum class SortMode {
Newest,
Oldest,
Latest_Ranked,
Most_Stars,
Least_Stars,
Best_rated,
Worst_rated
};
enum class SortMode { Newest, Oldest, Latest_Ranked, Most_Stars, Least_Stars, Best_rated, Worst_rated };

enum class PreferredLeaderBoard {
ScoreSaber = 0,
BeatLeader = 1
};
enum class PreferredLeaderBoard { ScoreSaber = 0, BeatLeader = 1 };

}
} // namespace FilterTypes

// Map for characteristics
static const std::unordered_map<FilterTypes::CharFilter, SongDetailsCache::MapCharacteristic> CHARACTERISTIC_MAP = {
static std::unordered_map<FilterTypes::CharFilter, SongDetailsCache::MapCharacteristic> const CHARACTERISTIC_MAP = {
{FilterTypes::CharFilter::Custom, SongDetailsCache::MapCharacteristic::Custom},
{FilterTypes::CharFilter::Standard, SongDetailsCache::MapCharacteristic::Standard},
{FilterTypes::CharFilter::OneSaber, SongDetailsCache::MapCharacteristic::OneSaber},
Expand All @@ -103,7 +56,7 @@ static const std::unordered_map<FilterTypes::CharFilter, SongDetailsCache::MapCh
};

// Map for difficulties
static const std::unordered_map<FilterTypes::DifficultyFilter, SongDetailsCache::MapDifficulty> DIFFICULTY_MAP = {
static std::unordered_map<FilterTypes::DifficultyFilter, SongDetailsCache::MapDifficulty> const DIFFICULTY_MAP = {
{FilterTypes::DifficultyFilter::Easy, SongDetailsCache::MapDifficulty::Easy},
{FilterTypes::DifficultyFilter::Normal, SongDetailsCache::MapDifficulty::Normal},
{FilterTypes::DifficultyFilter::Hard, SongDetailsCache::MapDifficulty::Hard},
Expand All @@ -112,20 +65,19 @@ static const std::unordered_map<FilterTypes::DifficultyFilter, SongDetailsCache:
};

// Map for ranked states
static const std::unordered_map<FilterTypes::RankedFilter, SongDetailsCache::RankedStates> RANK_MAP = {
static std::unordered_map<FilterTypes::RankedFilter, SongDetailsCache::RankedStates> const RANK_MAP = {
{FilterTypes::RankedFilter::ScoreSaberRanked, SongDetailsCache::RankedStates::ScoresaberRanked},
{FilterTypes::RankedFilter::BeatLeaderRanked, SongDetailsCache::RankedStates::BeatleaderRanked},
{FilterTypes::RankedFilter::ScoreSaberQualified, SongDetailsCache::RankedStates::ScoresaberQualified},
{FilterTypes::RankedFilter::BeatLeaderQualified, SongDetailsCache::RankedStates::BeatleaderQualified}
};

// Map for preferred leaderboard
static const std::unordered_map<std::string, FilterTypes::PreferredLeaderBoard> LEADERBOARD_MAP = {
{"Scoresaber", FilterTypes::PreferredLeaderBoard::ScoreSaber},
{"Beatleader", FilterTypes::PreferredLeaderBoard::BeatLeader}
static std::unordered_map<std::string, FilterTypes::PreferredLeaderBoard> const LEADERBOARD_MAP = {
{"Scoresaber", FilterTypes::PreferredLeaderBoard::ScoreSaber}, {"Beatleader", FilterTypes::PreferredLeaderBoard::BeatLeader}
};

DECLARE_CONFIG(PluginConfig,
DECLARE_CONFIG(PluginConfig) {
CONFIG_VALUE(ReturnToBSS, bool, "Return to BSS from Solo", true);
CONFIG_VALUE(LoadSongPreviews, bool, "Load song previews", true);
CONFIG_VALUE(SmallerFontSize, bool, "Smaller font size", true);
Expand All @@ -141,7 +93,7 @@ DECLARE_CONFIG(PluginConfig,
CONFIG_VALUE(RankedType, int, "Ranked Type", 0);
CONFIG_VALUE(MinStars, float, "Minimum Ranked Stars", 0);
CONFIG_VALUE(MaxStars, float, "Maximum Ranked Stars", STAR_FILTER_MAX);
CONFIG_VALUE(MinUploadDateInMonths, int, "Minimum Upload Date In Months", 0); //TEMPORARY UNTIL I FIX CONVERTING UNIX -> MONTHS SINCE BEAT SAVER
CONFIG_VALUE(MinUploadDateInMonths, int, "Minimum Upload Date In Months", 0); // TEMPORARY UNTIL I FIX CONVERTING UNIX -> MONTHS SINCE BEAT SAVER
CONFIG_VALUE(MinUploadDate, int, "Minimum Upload Date", BEATSAVER_EPOCH);
CONFIG_VALUE(MinRating, float, "Minimum Rating", 0);
CONFIG_VALUE(MinVotes, int, "Minimum Votes", 0);
Expand All @@ -156,4 +108,4 @@ DECLARE_CONFIG(PluginConfig,
CONFIG_VALUE(MapStyleString, std::string, "Map Style", "All");
CONFIG_VALUE(MapGenreString, std::string, "Map Genres", "");
CONFIG_VALUE(MapGenreExcludeString, std::string, "Map Genre Exclude", "");
)
};
Loading

0 comments on commit 8578bcb

Please sign in to comment.