Update Setlist for Beat Saber 1.44.1 startup scan

This commit is contained in:
pleb
2026-07-19 20:25:22 -07:00
parent 14d21ad6a3
commit a3b8169fd6
7 changed files with 79 additions and 87 deletions
+24 -54
View File
@@ -3,8 +3,6 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using BeatSaberPlaylistsLib.Types;
using UnityEngine;
using IPALogger = IPA.Logging.Logger;
@@ -20,7 +18,6 @@ namespace Setlist
private const float PlatformUserPollStepSeconds = 0.5f;
/// <summary>How long to wait for <see cref="PlatformLeaderboardsModel"/> to appear and populate <c>playerId</c> (plugin runs before menu init).</summary>
private const float PlatformUserWaitTimeoutSeconds = 30f;
private const float PlatformUserGetUserInfoRetrySeconds = 3f;
internal static bool TryExtractBeatLeaderPlaylistGuid(string syncUrl, out string guid)
{
@@ -111,55 +108,18 @@ namespace Setlist
internal static IEnumerator FetchPlatformUserIdCoroutine(Action<string> onDone)
{
var waited = 0f;
var lastGetUserInfoAttempt = -PlatformUserGetUserInfoRetrySeconds;
while (waited < PlatformUserWaitTimeoutSeconds)
{
foreach (var plm in EnumerateLeaderboardModels())
{
var pid = plm.playerId;
var pid = ReadPlatformUserId(plm);
if (!string.IsNullOrEmpty(pid))
{
onDone(pid.Trim());
onDone(pid);
yield break;
}
}
if (waited - lastGetUserInfoAttempt >= PlatformUserGetUserInfoRetrySeconds)
{
lastGetUserInfoAttempt = waited;
var model = ResolvePlatformUserModel();
if (model != null)
{
Task<UserInfo> task;
try
{
task = model.GetUserInfo(CancellationToken.None);
}
catch (Exception)
{
task = null;
}
if (task != null)
{
while (!task.IsCompleted)
{
yield return null;
}
if (!task.IsFaulted)
{
var uid = task.Result?.platformUserId;
if (!string.IsNullOrEmpty(uid))
{
onDone(uid.Trim());
yield break;
}
}
}
}
}
waited += PlatformUserPollStepSeconds;
yield return new WaitForSeconds(PlatformUserPollStepSeconds);
}
@@ -188,26 +148,36 @@ namespace Setlist
}
}
private static IPlatformUserModel ResolvePlatformUserModel()
private static string ReadPlatformUserId(PlatformLeaderboardsModel model)
{
var field = typeof(PlatformLeaderboardsModel).GetField(
"_platformUserModel",
BindingFlags.Instance | BindingFlags.NonPublic);
if (field == null)
if (model == null)
{
return null;
}
IPlatformUserModel last = null;
foreach (var plm in EnumerateLeaderboardModels())
var id = NormalizeUserId(model.playerId);
if (!string.IsNullOrEmpty(id))
{
if (field.GetValue(plm) is IPlatformUserModel m)
{
last = m;
}
return id;
}
return last;
var platformField = typeof(PlatformLeaderboardsModel).GetField(
"_platform",
BindingFlags.Instance | BindingFlags.NonPublic);
var platform = platformField?.GetValue(model);
var user = platform?.GetType().GetProperty("user")?.GetValue(platform, null);
return NormalizeUserId(user?.GetType().GetProperty("userId")?.GetValue(user, null));
}
private static string NormalizeUserId(object raw)
{
if (raw == null)
{
return null;
}
var value = raw.ToString()?.Trim();
return string.IsNullOrEmpty(value) || value == "0" ? null : value;
}
/// <summary>