Skip to content

Commit

Permalink
Merge pull request #155 from EnderdracheLP/1.16.3-1.18.3
Browse files Browse the repository at this point in the history
Fix MultiplayerModeSelectionFlowCoordinatorPatch, Remove ConnectToMatchmakingPatch, Improve CenterScreenLoadingPanel
  • Loading branch information
Goobwabber authored Nov 14, 2021
2 parents bb1c616 + f1046f8 commit fed2450
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 56 deletions.
2 changes: 1 addition & 1 deletion MultiplayerExtensions/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static bool TryGetDownload(string levelId, out Task<IPreviewBeatmapLevel?
byte[]? beatmapBytes = await bm.Versions.ToList().Find(version => {
Plugin.Log?.Info($"Version: '{version.Key}' '{version.Hash}'");
return version.Hash.ToUpper() == hash;
}).DownloadZIP(progress: UI.CenterScreenLoadingPanel.self);
}).DownloadZIP(progress: UI.CenterScreenLoadingPanel.Instance);
#if DEBUG
TimeSpan delay = TimeSpan.FromSeconds(Plugin.Config.DebugConfig?.MinDownloadTime ?? 0) - TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
if (delay > TimeSpan.Zero)
Expand Down
35 changes: 35 additions & 0 deletions MultiplayerExtensions/Extensions/ExtendedEntitlementChecker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BeatSaverSharp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Zenject;
Expand Down Expand Up @@ -75,12 +76,40 @@ public override Task<EntitlementsStatus> GetEntitlementStatus(string levelId)
return base.GetEntitlementStatus(levelId);

if (SongCore.Collections.songWithHashPresent(hash))
{
// The input parameter for RetrieveExtraSongData is called levelId but it only takes the level hash
var extraSongData = SongCore.Collections.RetrieveExtraSongData(hash);
if (extraSongData != null)
{
foreach (var difficultyData in extraSongData._difficulties)
{
if (difficultyData.additionalDifficultyData != null &&
((difficultyData.additionalDifficultyData._requirements.Contains("Noodle Extensions") && !Plugin.IsNoodleInstalled) ||
(difficultyData.additionalDifficultyData._requirements.Contains("Mapping Extensions") && !Plugin.IsMappingInstalled)))
return Task.FromResult(EntitlementsStatus.NotOwned);
else if (difficultyData.additionalDifficultyData != null)
{
foreach (string requirement in difficultyData.additionalDifficultyData._requirements) Plugin.Log?.Info($"Requirement found: {requirement}");
}
else Plugin.Log?.Debug("difficultyData.additionalDifficultyData is null");

}
}
else Plugin.Log?.Debug("extraSongData is null");
return Task.FromResult(EntitlementsStatus.Ok);
}
return Plugin.BeatSaver.BeatmapByHash(hash).ContinueWith<EntitlementsStatus>(r =>
{
Beatmap? beatmap = r.Result;
if (beatmap == null)
return EntitlementsStatus.NotOwned;
else
{
foreach (var difficulty in beatmap.Versions[0].Difficulties)
{
if ((difficulty.NoodleExtensions && !Plugin.IsNoodleInstalled) || (difficulty.MappingExtensions && !Plugin.IsMappingInstalled)) return EntitlementsStatus.NotOwned;
}
}
return EntitlementsStatus.NotDownloaded;
});
}
Expand Down Expand Up @@ -118,7 +147,11 @@ public async Task WaitForOkEntitlement(string userId, string levelId, Cancellati
{
if (_entitlementsDictionary.TryGetValue(userId, out Dictionary<string, EntitlementsStatus> userDictionary))
if (userDictionary.TryGetValue(levelId, out EntitlementsStatus entitlement) && entitlement == EntitlementsStatus.Ok)
{
UI.CenterScreenLoadingPanel.Instance.playersReady++;
Plugin.Log?.Info($"User '{userId}' for level '{levelId}' is '{entitlement}'");
return;
}

if (!_tcsDictionary.ContainsKey(userId))
_tcsDictionary[userId] = new Dictionary<string, TaskCompletionSource<EntitlementsStatus>>();
Expand All @@ -133,6 +166,8 @@ public async Task WaitForOkEntitlement(string userId, string levelId, Cancellati
result = await _tcsDictionary[userId][levelId].Task.ContinueWith(t => t.IsCompleted ? t.Result : EntitlementsStatus.Unknown);
_tcsDictionary[userId][levelId] = new TaskCompletionSource<EntitlementsStatus>();
}
if (!cancellationToken.IsCancellationRequested) UI.CenterScreenLoadingPanel.Instance.playersReady++;
Plugin.Log?.Info($"User '{userId}' for level '{levelId}' is '{result}' was task cancelled {(cancellationToken.IsCancellationRequested ? "true" : "false")}");
}
}
}
14 changes: 8 additions & 6 deletions MultiplayerExtensions/Extensions/ExtendedGameStateController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using IPA.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -91,7 +92,13 @@ public override void StopLoading()

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

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

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

Plugin.Log?.Debug($"Null Checking previewBeatmapLevel: '{(previewBeatmapLevel == null ? "null" : "not null")}'");
Plugin.Log?.Debug($"Null Checking beatmapDifficulty: '{beatmapDifficulty}'");
Plugin.Log?.Debug($"Null Checking beatmapCharacteristic: '{(beatmapCharacteristic == null ? "null" : "not null")}'");
Plugin.Log?.Debug($"Null Checking difficultyBeatmap: '{(difficultyBeatmap == null ? "null" : "not null")}'");
Plugin.Log?.Debug($"Null Checking gameplayModifiers: '{(gameplayModifiers == null ? "null" : "not null")}'");

base.HandleMultiplayerLevelLoaderCountdownFinished(previewBeatmapLevel, beatmapDifficulty, beatmapCharacteristic, difficultyBeatmap, gameplayModifiers);
}
Expand Down
10 changes: 5 additions & 5 deletions MultiplayerExtensions/Extensions/ExtendedPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ExtendedPlayer : IConnectedPlayer
/// <summary>
/// MultiplayerExtensions version reported by BSIPA.
/// </summary>
public SemVer.Version mpexVersion;
public Hive.Versioning.Version mpexVersion;

/// <summary>
/// Player's color set in the plugin config.
Expand All @@ -37,19 +37,19 @@ public class ExtendedPlayer : IConnectedPlayer
public ExtendedPlayer(IConnectedPlayer player)
{
_connectedPlayer = player;
this.mpexVersion = Plugin.PluginMetadata.Version;
this.mpexVersion = Plugin.ProtocolVersion;
}

public ExtendedPlayer(IConnectedPlayer player, string platformID, Platform platform, Color playerColor)
{
_connectedPlayer = player;
this.platformID = platformID;
this.platform = platform;
this.mpexVersion = Plugin.PluginMetadata.Version;
this.mpexVersion = Plugin.ProtocolVersion;
this.playerColor = playerColor;
}

public ExtendedPlayer(IConnectedPlayer player, string platformID, Platform platform, SemVer.Version mpexVersion, Color playerColor)
public ExtendedPlayer(IConnectedPlayer player, string platformID, Platform platform, Hive.Versioning.Version mpexVersion, Color playerColor)
{
_connectedPlayer = player;
this.platformID = platformID;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Deserialize(NetDataReader reader)
public ExtendedPlayerPacket Init(string platformID, Platform platform, Color playerColor)
{
this.platformID = platformID;
this.mpexVersion = Plugin.PluginMetadata.Version.ToString();
this.mpexVersion = Plugin.ProtocolVersion.ToString();
this.playerColor = playerColor;
this.platform = platform;
return this;
Expand Down
17 changes: 11 additions & 6 deletions MultiplayerExtensions/Extensions/ExtendedSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ internal void Inject([InjectOptional] PacketManager packetManager, [InjectOption

SetLocalPlayerState("modded", true);

SetLocalPlayerState("ME_Installed", Plugin.IsMappingInstalled);
SetLocalPlayerState("NE_Installed", Plugin.IsNoodleInstalled);
SetLocalPlayerState("Chroma_Installed", Plugin.IsChromaInstalled);

connectedEvent += HandleConnected;

playerConnectedEvent += HandlePlayerConnected;
Expand Down Expand Up @@ -92,19 +96,20 @@ private void HandleExtendedPlayerPacket(ExtendedPlayerPacket packet, IConnectedP
extendedPlayer.platformID = packet.platformID;
extendedPlayer.platform = packet.platform;
extendedPlayer.playerColor = packet.playerColor;
extendedPlayer.mpexVersion = new SemVer.Version(packet.mpexVersion);
extendedPlayer.mpexVersion = new Hive.Versioning.Version(packet.mpexVersion);
extendedPlayerConnectedEvent?.Invoke(extendedPlayer);
}
else
{
Plugin.Log?.Info($"Received 'ExtendedPlayerPacket' from '{player.userId}' with platformID: '{packet.platformID}' mpexVersion: '{packet.mpexVersion}'");
ExtendedPlayer extendedPlayer = new ExtendedPlayer(player, packet.platformID, packet.platform, new SemVer.Version(packet.mpexVersion), packet.playerColor);
ExtendedPlayer extendedPlayer = new ExtendedPlayer(player, packet.platformID, packet.platform, new Hive.Versioning.Version(packet.mpexVersion), packet.playerColor);

if (Plugin.PluginMetadata.Version != extendedPlayer.mpexVersion)
if (Plugin.ProtocolVersion != extendedPlayer.mpexVersion)
{
Plugin.Log?.Warn("###################################################################");
Plugin.Log?.Warn("Different MultiplayerExtensions version detected!");
Plugin.Log?.Warn($"The player '{player.userName}' is using MultiplayerExtensions {extendedPlayer.mpexVersion} while you are using MultiplayerExtensions {Plugin.PluginMetadata.Version}");
Plugin.Log?.Warn("For best compatibility all players should use the same version of MultiplayerExtensions.");
Plugin.Log?.Warn("Different MultiplayerExtensions protocol detected!");
Plugin.Log?.Warn($"The player '{player.userName}' is using MpEx protocol version {extendedPlayer.mpexVersion} while you are using MpEx protocol {Plugin.ProtocolVersion}");
Plugin.Log?.Warn("For best compatibility all players should use a compatible version of MultiplayerExtensions/MultiQuestensions.");
Plugin.Log?.Warn("###################################################################");
}

Expand Down
12 changes: 0 additions & 12 deletions MultiplayerExtensions/HarmonyPatches/CustomSongsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ static void Prefix(CreateServerFormData data)
}
}

[HarmonyPatch(typeof(MultiplayerLobbyConnectionController), nameof(MultiplayerLobbyConnectionController.ConnectToMatchmaking), MethodType.Normal)]
internal class ConnectToMatchmakingPatch
{
/// <summary>
/// Modifies the data used to matchmake
/// </summary>
static void Prefix(ref SongPackMask songPackMask)
{
if (!MPState.CurrentMasterServer.isOfficial)
songPackMask |= new SongPackMask("custom_levelpack_CustomLevels");
}
}

[HarmonyPatch(typeof(MultiplayerLevelSelectionFlowCoordinator), "enableCustomLevels", MethodType.Getter)]
internal class EnableCustomLevelsPatch
Expand Down
3 changes: 2 additions & 1 deletion MultiplayerExtensions/HarmonyPatches/InstallerPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using IPA.Utilities;
using MultiplayerExtensions.Extensions;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -145,7 +146,7 @@ internal static void Prefix(ref GameplayCoreInstaller __instance, ref IConnected
____sceneSetupData = new GameplayCoreSceneSetupData(
____sceneSetupData.difficultyBeatmap,
____sceneSetupData.previewBeatmapLevel,
____sceneSetupData.gameplayModifiers.CopyWith(zenMode: Plugin.Config.LagReducer),
____sceneSetupData.gameplayModifiers.CopyWith(zenMode: (____sceneSetupData.gameplayModifiers.zenMode || Plugin.Config.LagReducer)),
____sceneSetupData.playerSpecificSettings,
____sceneSetupData.practiceSettings,
____sceneSetupData.useTestNoteCutSoundEffects,
Expand Down
5 changes: 4 additions & 1 deletion MultiplayerExtensions/HarmonyPatches/QuickplayPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ namespace MultiplayerExtensions.HarmonyPatches
[HarmonyPatch(typeof(MultiplayerModeSelectionFlowCoordinator), nameof(MultiplayerModeSelectionFlowCoordinator.HandleJoinQuickPlayViewControllerDidFinish), MethodType.Normal)]
internal class MultiplayerModeSelectionFlowCoordinatorPatch
{
internal static bool skipCheck = false;
static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool success, JoinQuickPlayViewController ____joinQuickPlayViewController, SimpleDialogPromptViewController ____simpleDialogPromptViewController, SongPackMaskModelSO ____songPackMaskModel)
{
string levelPackName = ____joinQuickPlayViewController.multiplayerModeSettings.quickPlaySongPackMaskSerializedName;
Plugin.Log?.Debug(levelPackName);
if (success && ____songPackMaskModel.ToSongPackMask(levelPackName).Contains("custom_levelpack_CustomLevels"))
if (success && ____songPackMaskModel.ToSongPackMask(levelPackName).Contains("custom_levelpack_CustomLevels") && !skipCheck)
{
____simpleDialogPromptViewController.Init(
"Custom Song Quickplay",
Expand All @@ -29,6 +30,7 @@ static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool succ
{
default:
case 0: // Continue
skipCheck = true;
__instance.HandleJoinQuickPlayViewControllerDidFinish(true);
break;
case 1: // Cancel
Expand All @@ -44,6 +46,7 @@ static bool Prefix(MultiplayerModeSelectionFlowCoordinator __instance, bool succ
});
return false;
}
skipCheck = false;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion MultiplayerExtensions/MultiplayerExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AssemblyName>MultiplayerExtensions</AssemblyName>
<AssemblyVersion>0.6.1</AssemblyVersion>
<AssemblyVersion>0.6.2</AssemblyVersion>
<TargetFramework>net472</TargetFramework>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
Expand Down
28 changes: 12 additions & 16 deletions MultiplayerExtensions/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
using IPA.Config;
using IPA.Config.Stores;
using IPA.Loader;
using MultiplayerExtensions.HarmonyPatches;
using MultiplayerExtensions.Installers;
using SiraUtil.Zenject;
using MultiplayerExtensions.Utilities;
using System;
using System.Reflection;
using System.Threading.Tasks;
using IPALogger = IPA.Logging.Logger;
using BeatSaverSharp;
using System.Diagnostics;
using Zenject;
using MultiplayerExtensions.UI;
using BeatSaberMarkupLanguage.Settings;
using System.Net.Http;

namespace MultiplayerExtensions
{
Expand All @@ -27,10 +23,15 @@ public class Plugin

internal static Plugin Instance { get; private set; } = null!;
internal static PluginMetadata PluginMetadata = null!;

internal static bool IsNoodleInstalled { get; private set; }
internal static bool IsMappingInstalled { get; private set; }
internal static bool IsChromaInstalled { get; private set; }

internal static Hive.Versioning.Version ProtocolVersion { get; } = new Hive.Versioning.Version("0.7.1");
internal static IPALogger Log { get; private set; } = null!;
internal static PluginConfig Config = null!;

internal static HttpClient HttpClient { get; private set; } = null!;
internal static BeatSaver BeatSaver = null!;
internal static Harmony? _harmony;
internal static Harmony Harmony
Expand All @@ -41,15 +42,6 @@ internal static Harmony Harmony
}
}

public static string UserAgent
{
get
{
var modVersion = PluginMetadata.Version.ToString();
var bsVersion = IPA.Utilities.UnityGame.GameVersion.ToString();
return $"MultiplayerExtensions/{modVersion} (BeatSaber/{bsVersion})";
}
}

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

BeatSaverOptions options = new BeatSaverOptions("MultiplayerExtensions", new Version(pluginMetadata.Version.ToString()));
options.Timeout = TimeSpan.FromMinutes(1);
BeatSaver = new BeatSaver(options);
HttpClient = new HttpClient();
HttpClient.DefaultRequestHeaders.Add("User-Agent", Plugin.UserAgent);
}

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

HarmonyManager.ApplyDefaultPatches();
Task versionTask = CheckVersion();

IsNoodleInstalled = IPA.Loader.PluginManager.IsEnabled(IPA.Loader.PluginManager.GetPluginFromId("NoodleExtensions"));
IsMappingInstalled = IPA.Loader.PluginManager.IsEnabled(IPA.Loader.PluginManager.GetPluginFromId("MappingExtensions"));
IsChromaInstalled = IPA.Loader.PluginManager.IsEnabled(IPA.Loader.PluginManager.GetPluginFromId("Chroma"));

MPEvents_Test();

Sprites.PreloadSprites();
Expand Down
Loading

0 comments on commit fed2450

Please sign in to comment.