Skip to content

Commit

Permalink
Merge pull request #30 from Meivyn/fix/1.31.1
Browse files Browse the repository at this point in the history
Fix for game v1.31.1
  • Loading branch information
kinsi55 authored Sep 5, 2023
2 parents 41b3fd8 + 904b85d commit 29f6701
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
8 changes: 4 additions & 4 deletions HarmonyPatches/HookLevelCollectionTableSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void FilterWrapper(ref IPreviewBeatmapLevel[] previewBeatmapLevels) {
customSorter.DoSort(ref outV, Config.Instance.SortAsc);
} else {
var pSorter = (ISorterPrimitive)sorter;
outV = Config.Instance.SortAsc ?
outV = Config.Instance.SortAsc ?
outV.OrderBy(x => pSorter.GetValueFor(x) ?? float.MaxValue) :
outV.OrderByDescending(x => pSorter.GetValueFor(x) ?? float.MinValue);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ static bool PrepareStuffIfNecessary(Action cb = null, bool cbOnAlreadyPrepared =
[HarmonyPriority(int.MaxValue)]
static void Prefix(
LevelCollectionTableView __instance, TableView ____tableView,
ref IPreviewBeatmapLevel[] previewBeatmapLevels, HashSet<string> favoriteLevelIds, ref bool beatmapLevelsAreSorted
ref IPreviewBeatmapLevel[] previewBeatmapLevels, HashSet<string> favoriteLevelIds, ref bool beatmapLevelsAreSorted, bool sortPreviewBeatmapLevels
) {
#if TRACE
Plugin.Log.Debug("LevelCollectionTableView.SetData():Prefix");
Expand All @@ -176,7 +176,7 @@ static void Prefix(

lastInMapList = previewBeatmapLevels;
var _isSorted = beatmapLevelsAreSorted;
recallLast = (overrideData) => __instance.SetData(overrideData ?? lastInMapList, favoriteLevelIds, _isSorted);
recallLast = (overrideData) => __instance.SetData(overrideData ?? lastInMapList, favoriteLevelIds, _isSorted, sortPreviewBeatmapLevels);

//Console.WriteLine("=> {0}", new System.Diagnostics.StackTrace().ToString());

Expand Down Expand Up @@ -209,7 +209,7 @@ static void Postfix(TableView ____tableView, AlphabetScrollbar ____alphabetScrol
lastOutMapList = previewBeatmapLevels;

// Basegame already handles cleaning up the legend etc
if(customLegend == null)
if(customLegend == null || customLegend.Length == 0)
return;

/*
Expand Down
53 changes: 40 additions & 13 deletions HarmonyPatches/ImproveBasegameSearch.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
using HarmonyLib;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace BetterSongList.HarmonyPatches {
[HarmonyPatch(typeof(BeatmapLevelFilterModel), "LevelContainsText")]
[HarmonyPatch(typeof(BeatmapLevelSearchHelper), nameof(BeatmapLevelSearchHelper.SearchAndSortBeatmapLevels))]
static class ImproveBasegameSearch {
[HarmonyPriority(int.MinValue + 10)]
static bool Prefix(IPreviewBeatmapLevel beatmapLevel, ref string[] searchTexts, ref bool __result) {
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
if(!Config.Instance.ModBasegameSearch)
return true;
return instructions;

if(searchTexts.Any(x => x.Length > 2 && beatmapLevel.levelAuthorName.IndexOf(x, 0, StringComparison.CurrentCultureIgnoreCase) != -1)) {
__result = true;
return false;
}
if(searchTexts.Length > 1)
searchTexts = new string[] { string.Join(" ", searchTexts) };
// This appends a space and the levelAuthorName to the levelString variable.
var matcher = new CodeMatcher(instructions)
.MatchForward(true,
new CodeMatch(OpCodes.Ldloc_S, null, "L_previewBeatmapLevel"),
new CodeMatch(),
new CodeMatch(OpCodes.Stelem_Ref),
new CodeMatch(x => x.opcode == OpCodes.Call && (x.operand as MethodInfo)?.Name == nameof(string.Concat), "Call_Concat"),
new CodeMatch(OpCodes.Stloc_S, null, "L_levelStringSt")
);

return true;
matcher.Advance(1).Insert(
new CodeInstruction(OpCodes.Ldc_I4_3),
new CodeInstruction(OpCodes.Newarr, typeof(string)),

new CodeInstruction(OpCodes.Dup),
new CodeInstruction(OpCodes.Ldc_I4_0),
new CodeInstruction(OpCodes.Ldloc_S, matcher.NamedMatch("L_levelStringSt").operand),
new CodeInstruction(OpCodes.Stelem_Ref),

new CodeInstruction(OpCodes.Dup),
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ldstr, " "),
new CodeInstruction(OpCodes.Stelem_Ref),

new CodeInstruction(OpCodes.Dup),
new CodeInstruction(OpCodes.Ldc_I4_2),
matcher.NamedMatch("L_previewBeatmapLevel"),
new CodeInstruction(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(IPreviewBeatmapLevel), nameof(IPreviewBeatmapLevel.levelAuthorName))),
new CodeInstruction(OpCodes.Stelem_Ref),

matcher.NamedMatch("Call_Concat"),
matcher.NamedMatch("L_levelStringSt")
);

return matcher.InstructionEnumeration();
}
}
}
4 changes: 0 additions & 4 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using IPA;
using IPA.Config.Stores;
using System.Reflection;
using System.Linq;
using IPALogger = IPA.Logging.Logger;

namespace BetterSongList {
Expand All @@ -19,9 +18,6 @@ public class Plugin {
public void Init(IPALogger logger, IPA.Config.Config conf) {
Instance = this;
Log = logger;

SharedCoroutineStarter.Init();

Config.Instance = conf.Generated<Config>();
}

Expand Down
2 changes: 1 addition & 1 deletion UI/BSML/SplitViews/Settings.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/>
<toggle-setting
text='Improve Basegame search' apply-on-change='true' value='ModBasegameSearch'
hover-hint='Adds searching by Mapper name and handling of Songs with spaces to the Basegame search'
hover-hint='Adds searching by Mapper name to the Basegame search'
/>
<toggle-setting
text='Extend Basegame scrollbar' apply-on-change='true' value='ExtendSongsScrollbar'
Expand Down
2 changes: 2 additions & 0 deletions Util/PlaylistsUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static IBeatmapLevelPack GetPack(string packName) {
return p;
} else if(hasPlaylistLib) {
IBeatmapLevelPack wrapper() {
if(!SongCore.Loader.AreSongsLoaded)
return null;
foreach(var x in BeatSaberPlaylistsLib.PlaylistManager.DefaultManager.GetAllPlaylists(true)) {
if(x.packName == packName)
return x;
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"id": "BetterSongList",
"name": "BetterSongList",
"author": "Kinsi55",
"version": "0.3.7",
"version": "0.3.8",
"description": "Adds Various improvements to the Basegame Map list like Filters, a persisted state and much more",
"gameVersion": "1.24.0",
"gameVersion": "1.31.1",
"dependsOn": {
"BSIPA": "^4.2.0",
"SongCore": "^3.5.0",
Expand Down

0 comments on commit 29f6701

Please sign in to comment.