Skip to content

Commit fed2450

Browse files
authored
Merge pull request #155 from EnderdracheLP/1.16.3-1.18.3
Fix MultiplayerModeSelectionFlowCoordinatorPatch, Remove ConnectToMatchmakingPatch, Improve CenterScreenLoadingPanel
2 parents bb1c616 + f1046f8 commit fed2450

File tree

13 files changed

+90
-56
lines changed

13 files changed

+90
-56
lines changed

MultiplayerExtensions/Downloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static bool TryGetDownload(string levelId, out Task<IPreviewBeatmapLevel?
4949
byte[]? beatmapBytes = await bm.Versions.ToList().Find(version => {
5050
Plugin.Log?.Info($"Version: '{version.Key}' '{version.Hash}'");
5151
return version.Hash.ToUpper() == hash;
52-
}).DownloadZIP(progress: UI.CenterScreenLoadingPanel.self);
52+
}).DownloadZIP(progress: UI.CenterScreenLoadingPanel.Instance);
5353
#if DEBUG
5454
TimeSpan delay = TimeSpan.FromSeconds(Plugin.Config.DebugConfig?.MinDownloadTime ?? 0) - TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
5555
if (delay > TimeSpan.Zero)

MultiplayerExtensions/Extensions/ExtendedEntitlementChecker.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BeatSaverSharp.Models;
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Zenject;
@@ -75,12 +76,40 @@ public override Task<EntitlementsStatus> GetEntitlementStatus(string levelId)
7576
return base.GetEntitlementStatus(levelId);
7677

7778
if (SongCore.Collections.songWithHashPresent(hash))
79+
{
80+
// The input parameter for RetrieveExtraSongData is called levelId but it only takes the level hash
81+
var extraSongData = SongCore.Collections.RetrieveExtraSongData(hash);
82+
if (extraSongData != null)
83+
{
84+
foreach (var difficultyData in extraSongData._difficulties)
85+
{
86+
if (difficultyData.additionalDifficultyData != null &&
87+
((difficultyData.additionalDifficultyData._requirements.Contains("Noodle Extensions") && !Plugin.IsNoodleInstalled) ||
88+
(difficultyData.additionalDifficultyData._requirements.Contains("Mapping Extensions") && !Plugin.IsMappingInstalled)))
89+
return Task.FromResult(EntitlementsStatus.NotOwned);
90+
else if (difficultyData.additionalDifficultyData != null)
91+
{
92+
foreach (string requirement in difficultyData.additionalDifficultyData._requirements) Plugin.Log?.Info($"Requirement found: {requirement}");
93+
}
94+
else Plugin.Log?.Debug("difficultyData.additionalDifficultyData is null");
95+
96+
}
97+
}
98+
else Plugin.Log?.Debug("extraSongData is null");
7899
return Task.FromResult(EntitlementsStatus.Ok);
100+
}
79101
return Plugin.BeatSaver.BeatmapByHash(hash).ContinueWith<EntitlementsStatus>(r =>
80102
{
81103
Beatmap? beatmap = r.Result;
82104
if (beatmap == null)
83105
return EntitlementsStatus.NotOwned;
106+
else
107+
{
108+
foreach (var difficulty in beatmap.Versions[0].Difficulties)
109+
{
110+
if ((difficulty.NoodleExtensions && !Plugin.IsNoodleInstalled) || (difficulty.MappingExtensions && !Plugin.IsMappingInstalled)) return EntitlementsStatus.NotOwned;
111+
}
112+
}
84113
return EntitlementsStatus.NotDownloaded;
85114
});
86115
}
@@ -118,7 +147,11 @@ public async Task WaitForOkEntitlement(string userId, string levelId, Cancellati
118147
{
119148
if (_entitlementsDictionary.TryGetValue(userId, out Dictionary<string, EntitlementsStatus> userDictionary))
120149
if (userDictionary.TryGetValue(levelId, out EntitlementsStatus entitlement) && entitlement == EntitlementsStatus.Ok)
150+
{
151+
UI.CenterScreenLoadingPanel.Instance.playersReady++;
152+
Plugin.Log?.Info($"User '{userId}' for level '{levelId}' is '{entitlement}'");
121153
return;
154+
}
122155

123156
if (!_tcsDictionary.ContainsKey(userId))
124157
_tcsDictionary[userId] = new Dictionary<string, TaskCompletionSource<EntitlementsStatus>>();
@@ -133,6 +166,8 @@ public async Task WaitForOkEntitlement(string userId, string levelId, Cancellati
133166
result = await _tcsDictionary[userId][levelId].Task.ContinueWith(t => t.IsCompleted ? t.Result : EntitlementsStatus.Unknown);
134167
_tcsDictionary[userId][levelId] = new TaskCompletionSource<EntitlementsStatus>();
135168
}
169+
if (!cancellationToken.IsCancellationRequested) UI.CenterScreenLoadingPanel.Instance.playersReady++;
170+
Plugin.Log?.Info($"User '{userId}' for level '{levelId}' is '{result}' was task cancelled {(cancellationToken.IsCancellationRequested ? "true" : "false")}");
136171
}
137172
}
138173
}

MultiplayerExtensions/Extensions/ExtendedGameStateController.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using IPA.Utilities;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Threading;
@@ -91,7 +92,13 @@ public override void StopLoading()
9192

9293
public async override void HandleMultiplayerLevelLoaderCountdownFinished(IPreviewBeatmapLevel previewBeatmapLevel, BeatmapDifficulty beatmapDifficulty, BeatmapCharacteristicSO beatmapCharacteristic, IDifficultyBeatmap difficultyBeatmap, GameplayModifiers gameplayModifiers)
9394
{
95+
if (_multiplayerLevelLoader.GetField<MultiplayerLevelLoader.MultiplayerBeatmapLoaderState, MultiplayerLevelLoader>("_loaderState") == MultiplayerLevelLoader.MultiplayerBeatmapLoaderState.NotLoading)
96+
{
97+
return;
98+
}
99+
_multiplayerLevelLoader.SetField("_loaderState", MultiplayerLevelLoader.MultiplayerBeatmapLoaderState.NotLoading);
94100
Plugin.Log?.Debug("Map finished loading, waiting for other players...");
101+
UI.CenterScreenLoadingPanel.Instance.playersReady = 0;
95102
_menuRpcManager.SetIsEntitledToLevel(previewBeatmapLevel.levelID, EntitlementsStatus.Ok);
96103

97104
if (_levelStartedOnTime == false)
@@ -116,11 +123,6 @@ public async override void HandleMultiplayerLevelLoaderCountdownFinished(IPrevie
116123

117124
Plugin.Log?.Debug("All players ready, starting game.");
118125

119-
Plugin.Log?.Debug($"Null Checking previewBeatmapLevel: '{(previewBeatmapLevel == null ? "null" : "not null")}'");
120-
Plugin.Log?.Debug($"Null Checking beatmapDifficulty: '{beatmapDifficulty}'");
121-
Plugin.Log?.Debug($"Null Checking beatmapCharacteristic: '{(beatmapCharacteristic == null ? "null" : "not null")}'");
122-
Plugin.Log?.Debug($"Null Checking difficultyBeatmap: '{(difficultyBeatmap == null ? "null" : "not null")}'");
123-
Plugin.Log?.Debug($"Null Checking gameplayModifiers: '{(gameplayModifiers == null ? "null" : "not null")}'");
124126

125127
base.HandleMultiplayerLevelLoaderCountdownFinished(previewBeatmapLevel, beatmapDifficulty, beatmapCharacteristic, difficultyBeatmap, gameplayModifiers);
126128
}

MultiplayerExtensions/Extensions/ExtendedPlayer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ExtendedPlayer : IConnectedPlayer
2222
/// <summary>
2323
/// MultiplayerExtensions version reported by BSIPA.
2424
/// </summary>
25-
public SemVer.Version mpexVersion;
25+
public Hive.Versioning.Version mpexVersion;
2626

2727
/// <summary>
2828
/// Player's color set in the plugin config.
@@ -37,19 +37,19 @@ public class ExtendedPlayer : IConnectedPlayer
3737
public ExtendedPlayer(IConnectedPlayer player)
3838
{
3939
_connectedPlayer = player;
40-
this.mpexVersion = Plugin.PluginMetadata.Version;
40+
this.mpexVersion = Plugin.ProtocolVersion;
4141
}
4242

4343
public ExtendedPlayer(IConnectedPlayer player, string platformID, Platform platform, Color playerColor)
4444
{
4545
_connectedPlayer = player;
4646
this.platformID = platformID;
4747
this.platform = platform;
48-
this.mpexVersion = Plugin.PluginMetadata.Version;
48+
this.mpexVersion = Plugin.ProtocolVersion;
4949
this.playerColor = playerColor;
5050
}
5151

52-
public ExtendedPlayer(IConnectedPlayer player, string platformID, Platform platform, SemVer.Version mpexVersion, Color playerColor)
52+
public ExtendedPlayer(IConnectedPlayer player, string platformID, Platform platform, Hive.Versioning.Version mpexVersion, Color playerColor)
5353
{
5454
_connectedPlayer = player;
5555
this.platformID = platformID;
@@ -102,7 +102,7 @@ public void Deserialize(NetDataReader reader)
102102
public ExtendedPlayerPacket Init(string platformID, Platform platform, Color playerColor)
103103
{
104104
this.platformID = platformID;
105-
this.mpexVersion = Plugin.PluginMetadata.Version.ToString();
105+
this.mpexVersion = Plugin.ProtocolVersion.ToString();
106106
this.playerColor = playerColor;
107107
this.platform = platform;
108108
return this;

MultiplayerExtensions/Extensions/ExtendedSessionManager.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ internal void Inject([InjectOptional] PacketManager packetManager, [InjectOption
3737

3838
SetLocalPlayerState("modded", true);
3939

40+
SetLocalPlayerState("ME_Installed", Plugin.IsMappingInstalled);
41+
SetLocalPlayerState("NE_Installed", Plugin.IsNoodleInstalled);
42+
SetLocalPlayerState("Chroma_Installed", Plugin.IsChromaInstalled);
43+
4044
connectedEvent += HandleConnected;
4145

4246
playerConnectedEvent += HandlePlayerConnected;
@@ -92,19 +96,20 @@ private void HandleExtendedPlayerPacket(ExtendedPlayerPacket packet, IConnectedP
9296
extendedPlayer.platformID = packet.platformID;
9397
extendedPlayer.platform = packet.platform;
9498
extendedPlayer.playerColor = packet.playerColor;
95-
extendedPlayer.mpexVersion = new SemVer.Version(packet.mpexVersion);
99+
extendedPlayer.mpexVersion = new Hive.Versioning.Version(packet.mpexVersion);
100+
extendedPlayerConnectedEvent?.Invoke(extendedPlayer);
96101
}
97102
else
98103
{
99104
Plugin.Log?.Info($"Received 'ExtendedPlayerPacket' from '{player.userId}' with platformID: '{packet.platformID}' mpexVersion: '{packet.mpexVersion}'");
100-
ExtendedPlayer extendedPlayer = new ExtendedPlayer(player, packet.platformID, packet.platform, new SemVer.Version(packet.mpexVersion), packet.playerColor);
105+
ExtendedPlayer extendedPlayer = new ExtendedPlayer(player, packet.platformID, packet.platform, new Hive.Versioning.Version(packet.mpexVersion), packet.playerColor);
101106

102-
if (Plugin.PluginMetadata.Version != extendedPlayer.mpexVersion)
107+
if (Plugin.ProtocolVersion != extendedPlayer.mpexVersion)
103108
{
104109
Plugin.Log?.Warn("###################################################################");
105-
Plugin.Log?.Warn("Different MultiplayerExtensions version detected!");
106-
Plugin.Log?.Warn($"The player '{player.userName}' is using MultiplayerExtensions {extendedPlayer.mpexVersion} while you are using MultiplayerExtensions {Plugin.PluginMetadata.Version}");
107-
Plugin.Log?.Warn("For best compatibility all players should use the same version of MultiplayerExtensions.");
110+
Plugin.Log?.Warn("Different MultiplayerExtensions protocol detected!");
111+
Plugin.Log?.Warn($"The player '{player.userName}' is using MpEx protocol version {extendedPlayer.mpexVersion} while you are using MpEx protocol {Plugin.ProtocolVersion}");
112+
Plugin.Log?.Warn("For best compatibility all players should use a compatible version of MultiplayerExtensions/MultiQuestensions.");
108113
Plugin.Log?.Warn("###################################################################");
109114
}
110115

MultiplayerExtensions/HarmonyPatches/CustomSongsPatches.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ static void Prefix(CreateServerFormData data)
2222
}
2323
}
2424

25-
[HarmonyPatch(typeof(MultiplayerLobbyConnectionController), nameof(MultiplayerLobbyConnectionController.ConnectToMatchmaking), MethodType.Normal)]
26-
internal class ConnectToMatchmakingPatch
27-
{
28-
/// <summary>
29-
/// Modifies the data used to matchmake
30-
/// </summary>
31-
static void Prefix(ref SongPackMask songPackMask)
32-
{
33-
if (!MPState.CurrentMasterServer.isOfficial)
34-
songPackMask |= new SongPackMask("custom_levelpack_CustomLevels");
35-
}
36-
}
3725

3826
[HarmonyPatch(typeof(MultiplayerLevelSelectionFlowCoordinator), "enableCustomLevels", MethodType.Getter)]
3927
internal class EnableCustomLevelsPatch

MultiplayerExtensions/HarmonyPatches/InstallerPatches.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HarmonyLib;
2+
using IPA.Utilities;
23
using MultiplayerExtensions.Extensions;
34
using System;
45
using System.Collections.Generic;
@@ -145,7 +146,7 @@ internal static void Prefix(ref GameplayCoreInstaller __instance, ref IConnected
145146
____sceneSetupData = new GameplayCoreSceneSetupData(
146147
____sceneSetupData.difficultyBeatmap,
147148
____sceneSetupData.previewBeatmapLevel,
148-
____sceneSetupData.gameplayModifiers.CopyWith(zenMode: Plugin.Config.LagReducer),
149+
____sceneSetupData.gameplayModifiers.CopyWith(zenMode: (____sceneSetupData.gameplayModifiers.zenMode || Plugin.Config.LagReducer)),
149150
____sceneSetupData.playerSpecificSettings,
150151
____sceneSetupData.practiceSettings,
151152
____sceneSetupData.useTestNoteCutSoundEffects,

MultiplayerExtensions/HarmonyPatches/QuickplayPatches.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ namespace MultiplayerExtensions.HarmonyPatches
1212
[HarmonyPatch(typeof(MultiplayerModeSelectionFlowCoordinator), nameof(MultiplayerModeSelectionFlowCoordinator.HandleJoinQuickPlayViewControllerDidFinish), MethodType.Normal)]
1313
internal class MultiplayerModeSelectionFlowCoordinatorPatch
1414
{
15+
internal static bool skipCheck = false;
1516
static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool success, JoinQuickPlayViewController ____joinQuickPlayViewController, SimpleDialogPromptViewController ____simpleDialogPromptViewController, SongPackMaskModelSO ____songPackMaskModel)
1617
{
1718
string levelPackName = ____joinQuickPlayViewController.multiplayerModeSettings.quickPlaySongPackMaskSerializedName;
1819
Plugin.Log?.Debug(levelPackName);
19-
if (success && ____songPackMaskModel.ToSongPackMask(levelPackName).Contains("custom_levelpack_CustomLevels"))
20+
if (success && ____songPackMaskModel.ToSongPackMask(levelPackName).Contains("custom_levelpack_CustomLevels") && !skipCheck)
2021
{
2122
____simpleDialogPromptViewController.Init(
2223
"Custom Song Quickplay",
@@ -29,6 +30,7 @@ static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool succ
2930
{
3031
default:
3132
case 0: // Continue
33+
skipCheck = true;
3234
__instance.HandleJoinQuickPlayViewControllerDidFinish(true);
3335
break;
3436
case 1: // Cancel
@@ -44,6 +46,7 @@ static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool succ
4446
});
4547
return false;
4648
}
49+
skipCheck = false;
4750
return true;
4851
}
4952
}

MultiplayerExtensions/MultiplayerExtensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Library</OutputType>
55
<AppDesignerFolder>Properties</AppDesignerFolder>
66
<AssemblyName>MultiplayerExtensions</AssemblyName>
7-
<AssemblyVersion>0.6.1</AssemblyVersion>
7+
<AssemblyVersion>0.6.2</AssemblyVersion>
88
<TargetFramework>net472</TargetFramework>
99
<DebugSymbols>true</DebugSymbols>
1010
<DebugType>portable</DebugType>

MultiplayerExtensions/Plugin.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
using IPA.Config;
44
using IPA.Config.Stores;
55
using IPA.Loader;
6-
using MultiplayerExtensions.HarmonyPatches;
76
using MultiplayerExtensions.Installers;
87
using SiraUtil.Zenject;
98
using MultiplayerExtensions.Utilities;
109
using System;
11-
using System.Reflection;
1210
using System.Threading.Tasks;
1311
using IPALogger = IPA.Logging.Logger;
1412
using BeatSaverSharp;
1513
using System.Diagnostics;
16-
using Zenject;
1714
using MultiplayerExtensions.UI;
1815
using BeatSaberMarkupLanguage.Settings;
19-
using System.Net.Http;
2016

2117
namespace MultiplayerExtensions
2218
{
@@ -27,10 +23,15 @@ public class Plugin
2723

2824
internal static Plugin Instance { get; private set; } = null!;
2925
internal static PluginMetadata PluginMetadata = null!;
26+
27+
internal static bool IsNoodleInstalled { get; private set; }
28+
internal static bool IsMappingInstalled { get; private set; }
29+
internal static bool IsChromaInstalled { get; private set; }
30+
31+
internal static Hive.Versioning.Version ProtocolVersion { get; } = new Hive.Versioning.Version("0.7.1");
3032
internal static IPALogger Log { get; private set; } = null!;
3133
internal static PluginConfig Config = null!;
3234

33-
internal static HttpClient HttpClient { get; private set; } = null!;
3435
internal static BeatSaver BeatSaver = null!;
3536
internal static Harmony? _harmony;
3637
internal static Harmony Harmony
@@ -41,15 +42,6 @@ internal static Harmony Harmony
4142
}
4243
}
4344

44-
public static string UserAgent
45-
{
46-
get
47-
{
48-
var modVersion = PluginMetadata.Version.ToString();
49-
var bsVersion = IPA.Utilities.UnityGame.GameVersion.ToString();
50-
return $"MultiplayerExtensions/{modVersion} (BeatSaber/{bsVersion})";
51-
}
52-
}
5345

5446
private const int MaxPlayers = 100;
5547
private const int MinPlayers = 10;
@@ -67,9 +59,8 @@ public Plugin(IPALogger logger, Config conf, Zenjector zenjector, PluginMetadata
6759
zenjector.OnGame<MPGameInstaller>().OnlyForMultiplayer();
6860

6961
BeatSaverOptions options = new BeatSaverOptions("MultiplayerExtensions", new Version(pluginMetadata.Version.ToString()));
62+
options.Timeout = TimeSpan.FromMinutes(1);
7063
BeatSaver = new BeatSaver(options);
71-
HttpClient = new HttpClient();
72-
HttpClient.DefaultRequestHeaders.Add("User-Agent", Plugin.UserAgent);
7364
}
7465

7566
[OnStart]
@@ -82,6 +73,11 @@ public void OnApplicationStart()
8273

8374
HarmonyManager.ApplyDefaultPatches();
8475
Task versionTask = CheckVersion();
76+
77+
IsNoodleInstalled = IPA.Loader.PluginManager.IsEnabled(IPA.Loader.PluginManager.GetPluginFromId("NoodleExtensions"));
78+
IsMappingInstalled = IPA.Loader.PluginManager.IsEnabled(IPA.Loader.PluginManager.GetPluginFromId("MappingExtensions"));
79+
IsChromaInstalled = IPA.Loader.PluginManager.IsEnabled(IPA.Loader.PluginManager.GetPluginFromId("Chroma"));
80+
8581
MPEvents_Test();
8682

8783
Sprites.PreloadSprites();

0 commit comments

Comments
 (0)