Esempio n. 1
0
        static bool Prefix(string userId, BeatmapIdentifierNetSerializable beatmapId, LobbyPlayersDataModel __instance)
        {
            if (beatmapId != null)
            {
                var hash = Utilities.Utilities.LevelIdToHash(beatmapId.levelID);
                if (hash != null)
                {
                    Plugin.Log?.Debug($"'{userId}' selected song '{hash}'.");
                    if (SongCore.Loader.GetLevelById(hash) != null)
                    {
                        Plugin.Log?.Debug($"Custom song '{hash}' loaded.");
                        return(true);
                    }

                    Plugin.Log?.Debug("Getting song characteristics");
                    var characteristicCollection = __instance.GetField <BeatmapCharacteristicCollectionSO, LobbyPlayersDataModel>("_beatmapCharacteristicCollection");
                    var characteristic           = characteristicCollection.GetBeatmapCharacteristicBySerializedName(beatmapId.beatmapCharacteristicSerializedName);

                    Plugin.Log?.Debug("Setting song preview");
                    var beatmap = BeatSaver.Client.Hash(Utilities.Utilities.LevelIdToHash(beatmapId.levelID));
                    beatmap.ContinueWith(r =>
                    {
                        if (r.IsCanceled)
                        {
                            Plugin.Log?.Debug($"Metadata retrieval for {beatmapId.levelID} was canceled.");
                            return;
                        }
                        else if (r.IsFaulted)
                        {
                            Plugin.Log?.Error($"Error retrieving metadata for {beatmapId.levelID}: {r.Exception.Message}");
                            Plugin.Log?.Debug(r.Exception);
                        }
                        HMMainThreadDispatcher.instance.Enqueue(() =>
                        {
                            __instance.SetPlayerBeatmapLevel(userId, new PreviewBeatmapLevelStub(beatmapId.levelID, r.Result), beatmapId.difficulty, characteristic);
                        });
                    });

                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        static bool Prefix(string levelId, BeatmapDifficulty beatmapDifficulty, BeatmapCharacteristicSO characteristic, LobbyPlayersDataModel __instance)
        {
            if (Utilities.Utilities.LevelIdToHash(levelId) != null)
            {
                Plugin.Log?.Debug($"Local user selected song '{levelId}'.");
                if (SongCore.Loader.GetLevelById(levelId) != null)
                {
                    Plugin.Log?.Debug($"Custom song '{levelId}' loaded.");
                    return(true);
                }

                Plugin.Log?.Debug("Updating RPC");
                var menuRpcManager = __instance.GetField <IMenuRpcManager, LobbyPlayersDataModel>("_menuRpcManager");
                menuRpcManager.SelectBeatmap(new BeatmapIdentifierNetSerializable(levelId, characteristic.serializedName, beatmapDifficulty));

                Plugin.Log?.Debug("Setting song preview");
                var beatmap = BeatSaver.Client.Hash(Utilities.Utilities.LevelIdToHash(levelId));
                beatmap.ContinueWith(r =>
                {
                    HMMainThreadDispatcher.instance.Enqueue(() =>
                    {
                        __instance.SetPlayerBeatmapLevel(__instance.localUserId, new PreviewBeatmapLevelStub(levelId, r.Result), beatmapDifficulty, characteristic);
                    });
                });

                return(false);
            }
            return(true);
        }
        static bool Prefix(string userId, BeatmapIdentifierNetSerializable beatmapId, LobbyPlayersDataModel __instance)
        {
            if (beatmapId != null)
            {
                if (beatmapId.levelID.StartsWith("custom_level_"))
                {
                    Plugin.Log?.Debug($"'{userId}' selected song '{beatmapId.levelID}'");
                    if (SongCore.Loader.GetLevelById(beatmapId.levelID) != null)
                    {
                        Plugin.Log?.Debug($"Custom song '{beatmapId.levelID}' loaded.");
                        return(true);
                    }

                    Plugin.Log?.Debug("getting characteristics");
                    var beatmapCharacteristicCollection = __instance.GetField <BeatmapCharacteristicCollectionSO, LobbyPlayersDataModel>("_beatmapCharacteristicCollection");
                    Plugin.Log?.Debug("setting preview");
                    __instance.SetPlayerBeatmapLevel(userId, new OverrideClasses.PreviewBeatmapLevelStub(beatmapId.levelID), beatmapId.difficulty,
                                                     beatmapCharacteristicCollection.GetBeatmapCharacteristicBySerializedName(beatmapId.beatmapCharacteristicSerializedName));

                    return(false);
                }
            }
            return(true);
        }