From f6a342a384eaea0c3a3f25af3d9ce189184424d4 Mon Sep 17 00:00:00 2001 From: Auros Nexus <41306347+Auros@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:20:03 -0400 Subject: [PATCH 1/6] Run UWR on main thread --- SiraUtil.Suite/Plugin.cs | 3 +- .../Web/Implementations/UWRHttpService.cs | 86 ++++++++++--------- SiraUtil/manifest.json | 4 +- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/SiraUtil.Suite/Plugin.cs b/SiraUtil.Suite/Plugin.cs index 176c6cd..3a23441 100644 --- a/SiraUtil.Suite/Plugin.cs +++ b/SiraUtil.Suite/Plugin.cs @@ -16,7 +16,6 @@ public class Plugin public Plugin(IPALogger logger, Zenjector zenjector) { Log = logger; - zenjector.UseAutoBinder(); zenjector.Install(Location.Menu); zenjector.Install(Location.Tutorial); @@ -69,7 +68,7 @@ private MultiplayerConnectedPlayerGameNoteController Create(MultiplayerConnected g.transform.SetParent(before.transform.GetChild(0)); g.transform.localPosition = new Vector3(0f, 0f, 0); g.transform.localScale *= 3f; - + return before; } } diff --git a/SiraUtil/Web/Implementations/UWRHttpService.cs b/SiraUtil/Web/Implementations/UWRHttpService.cs index 94136f5..18694be 100644 --- a/SiraUtil/Web/Implementations/UWRHttpService.cs +++ b/SiraUtil/Web/Implementations/UWRHttpService.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using IPA.Utilities.Async; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -81,57 +82,62 @@ public Task DeleteAsync(string url, CancellationToken? cancellati public async Task SendAsync(HTTPMethod method, string url, string? body = null, IDictionary? withHeaders = null, IProgress? downloadProgress = null, CancellationToken? cancellationToken = null) { - string newURL = url; - if (BaseURL != null) - newURL = Path.Combine(BaseURL, url); - DownloadHandler? dHandler = new DownloadHandlerBuffer(); - - HTTPMethod originalMethod = method; - if (method == HTTPMethod.POST && body != null) - method = HTTPMethod.PUT; + // I HATE UNITY I HATE UNITY I HATE UNITY + var response = await await UnityMainThreadTaskScheduler.Factory.StartNew(async () => + { + string newURL = url; + if (BaseURL != null) + newURL = Path.Combine(BaseURL, url); + DownloadHandler? dHandler = new DownloadHandlerBuffer(); - using UnityWebRequest request = new(newURL, method.ToString(), dHandler, body == null ? null : new UploadHandlerRaw(Encoding.UTF8.GetBytes(body))); - request.timeout = 60; + HTTPMethod originalMethod = method; + if (method == HTTPMethod.POST && body != null) + method = HTTPMethod.PUT; - foreach (var header in Headers) - request.SetRequestHeader(header.Key, header.Value); + using UnityWebRequest request = new(newURL, method.ToString(), dHandler, body == null ? null : new UploadHandlerRaw(Encoding.UTF8.GetBytes(body))); + request.timeout = 60; - if (withHeaders != null) - foreach (var header in withHeaders) + foreach (var header in Headers) request.SetRequestHeader(header.Key, header.Value); - if (body != null) - { - request.SetRequestHeader("Content-Type", "application/json"); - } - - // some unity bull - if (body != null && originalMethod == HTTPMethod.POST && method == HTTPMethod.PUT) - request.method = originalMethod.ToString(); + if (withHeaders != null) + foreach (var header in withHeaders) + request.SetRequestHeader(header.Key, header.Value); - float _lastProgress = -1f; - AsyncOperation asyncOp = request.SendWebRequest(); - while (!asyncOp.isDone) - { - if (cancellationToken.HasValue && cancellationToken.Value.IsCancellationRequested) + if (body != null) { - request.Abort(); - break; + request.SetRequestHeader("Content-Type", "application/json"); } - if (downloadProgress is not null && dHandler is not null) + + // some unity bull + if (body != null && originalMethod == HTTPMethod.POST && method == HTTPMethod.PUT) + request.method = originalMethod.ToString(); + + float _lastProgress = -1f; + AsyncOperation asyncOp = request.SendWebRequest(); + while (!asyncOp.isDone) { - float currentProgress = asyncOp.progress; - if (_lastProgress != currentProgress) + if (cancellationToken.HasValue && cancellationToken.Value.IsCancellationRequested) { - downloadProgress.Report(currentProgress); - _lastProgress = currentProgress; + request.Abort(); + break; } + if (downloadProgress is not null && dHandler is not null) + { + float currentProgress = asyncOp.progress; + if (_lastProgress != currentProgress) + { + downloadProgress.Report(currentProgress); + _lastProgress = currentProgress; + } + } + await Task.Delay(10); } - await Task.Delay(10); - } - downloadProgress?.Report(1f); - bool successful = request.isDone && !request.isHttpError && !request.isNetworkError; - return new UnityWebRequestHttpResponse(request, successful); + downloadProgress?.Report(1f); + bool successful = request.isDone && !request.isHttpError && !request.isNetworkError; + return new UnityWebRequestHttpResponse(request, successful); + }); + return response; } } } \ No newline at end of file diff --git a/SiraUtil/manifest.json b/SiraUtil/manifest.json index 61235c2..fb6be59 100644 --- a/SiraUtil/manifest.json +++ b/SiraUtil/manifest.json @@ -3,10 +3,10 @@ "id": "SiraUtil", "name": "SiraUtil", "author": "Auros", - "version": "3.1.0", + "version": "3.1.1", "icon": "SiraUtil.Resources.logo.png", "description": "A powerful utility mod which expands the capabilities and provides more tools to Beat Saber modders.", - "gameVersion": "1.22.1", + "gameVersion": "1.24.0", "dependsOn": { "BSIPA": "^4.2.1" }, From d8860741fcb5c1db1be19560c6278821a2a9694d Mon Sep 17 00:00:00 2001 From: Auros Nexus <41306347+Auros@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:31:39 -0400 Subject: [PATCH 2/6] Added --no-sirautil-fpfc command line argument for disabling sirautil's fpfc functions --- SiraUtil/Installers/SiraSettingsInstaller.cs | 3 ++- SiraUtil/Tools/FPFC/FPFCInstaller.cs | 3 ++- SiraUtil/Tools/FPFC/FPFCToggle.cs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SiraUtil/Installers/SiraSettingsInstaller.cs b/SiraUtil/Installers/SiraSettingsInstaller.cs index 5d707d7..a5f2a84 100644 --- a/SiraUtil/Installers/SiraSettingsInstaller.cs +++ b/SiraUtil/Installers/SiraSettingsInstaller.cs @@ -20,7 +20,8 @@ public override void InstallBindings() Container.BindInstance(_config.SongControl).AsSingle(); Container.BindInterfacesTo().AsSingle(); - if (Environment.GetCommandLineArgs().Any(a => a.ToLower() == FPFCToggle.Argument)) + var args = Environment.GetCommandLineArgs(); + if (args.Any(a => a.Equals(FPFCToggle.EnableArgument, StringComparison.OrdinalIgnoreCase)) && !args.Any(a => a.Equals(FPFCToggle.DisableArgument, StringComparison.OrdinalIgnoreCase))) Container.BindInterfacesTo().AsSingle().NonLazy(); } } diff --git a/SiraUtil/Tools/FPFC/FPFCInstaller.cs b/SiraUtil/Tools/FPFC/FPFCInstaller.cs index b5fe024..5e96b9a 100644 --- a/SiraUtil/Tools/FPFC/FPFCInstaller.cs +++ b/SiraUtil/Tools/FPFC/FPFCInstaller.cs @@ -8,7 +8,8 @@ internal class FPFCInstaller : Installer { public override void InstallBindings() { - if (!Environment.GetCommandLineArgs().Any(a => a.ToLower() == FPFCToggle.Argument)) + var args = Environment.GetCommandLineArgs(); + if (!args.Any(a => a.Equals(FPFCToggle.EnableArgument, StringComparison.OrdinalIgnoreCase) || args.Any(a => a.Equals(FPFCToggle.DisableArgument, StringComparison.OrdinalIgnoreCase)))) { Container.Bind().To().AsSingle(); return; diff --git a/SiraUtil/Tools/FPFC/FPFCToggle.cs b/SiraUtil/Tools/FPFC/FPFCToggle.cs index 7d1e8f6..1478049 100644 --- a/SiraUtil/Tools/FPFC/FPFCToggle.cs +++ b/SiraUtil/Tools/FPFC/FPFCToggle.cs @@ -14,7 +14,8 @@ namespace SiraUtil.Tools.FPFC { internal class FPFCToggle : IAsyncInitializable, ITickable, IDisposable { - public const string Argument = "fpfc"; + public const string EnableArgument = "fpfc"; + public const string DisableArgument = "--no-sirautil-fpfc"; private Pose? _lastPose = new(); private readonly FPFCState _initialState = new(); From bc6f2f692c2526144d26b4453a4cb2c322df0835 Mon Sep 17 00:00:00 2001 From: Auros Nexus <41306347+Auros@users.noreply.github.com> Date: Wed, 27 Jul 2022 16:02:02 -0400 Subject: [PATCH 3/6] Allow FPFC in multiplayer --- SiraUtil/Installers/SiraGameplayFPFCInstaller.cs | 13 +++++++++++++ SiraUtil/Installers/SiraGameplayInstaller.cs | 3 --- SiraUtil/Plugin.cs | 5 +++-- .../Controllers/GameMenuControllerAccessor.cs | 10 +++++----- SiraUtil/Tools/FPFC/FPFCInstaller.cs | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 SiraUtil/Installers/SiraGameplayFPFCInstaller.cs diff --git a/SiraUtil/Installers/SiraGameplayFPFCInstaller.cs b/SiraUtil/Installers/SiraGameplayFPFCInstaller.cs new file mode 100644 index 0000000..c254895 --- /dev/null +++ b/SiraUtil/Installers/SiraGameplayFPFCInstaller.cs @@ -0,0 +1,13 @@ +using SiraUtil.Services.Controllers; +using Zenject; + +namespace SiraUtil.Installers +{ + internal class SiraAllPlayersFPFCInstaller : Installer + { + public override void InstallBindings() + { + Container.BindInterfacesAndSelfTo().AsSingle(); + } + } +} \ No newline at end of file diff --git a/SiraUtil/Installers/SiraGameplayInstaller.cs b/SiraUtil/Installers/SiraGameplayInstaller.cs index d55159a..14f7ec5 100644 --- a/SiraUtil/Installers/SiraGameplayInstaller.cs +++ b/SiraUtil/Installers/SiraGameplayInstaller.cs @@ -1,6 +1,5 @@ using SiraUtil.Sabers; using SiraUtil.Sabers.Effects; -using SiraUtil.Services.Controllers; using SiraUtil.Tools.FPFC; using SiraUtil.Tools.SongControl; using Zenject; @@ -12,8 +11,6 @@ internal class SiraGameplayInstaller : Installer { public override void InstallBindings() { - // FPFC stuff - Container.BindInterfacesAndSelfTo().AsSingle(); Container.BindInterfacesTo().AsSingle(); // SongControl stuff diff --git a/SiraUtil/Plugin.cs b/SiraUtil/Plugin.cs index 43c6dd1..21a0e12 100644 --- a/SiraUtil/Plugin.cs +++ b/SiraUtil/Plugin.cs @@ -41,8 +41,9 @@ public Plugin(Conf conf, IPALogger logger, PluginMetadata pluginMetadata) Zenjector zenjector = (ConstructZenjector(null!, null!, pluginMetadata) as Zenjector)!; zenjector.Install(Location.StandardPlayer | Location.CampaignPlayer | Location.MultiPlayer); + zenjector.Install(Location.Menu | Location.Player | Location.InactiveMultiPlayer | Location.Tutorial); + zenjector.Install(Location.Player | Location.InactiveMultiPlayer | Location.Tutorial); zenjector.Install(Location.App, _zenjectManager, zenjector); - zenjector.Install(Location.Menu | Location.Player | Location.Tutorial); zenjector.Install(Location.Player | Location.Tutorial); zenjector.Install(Location.Singleplayer); zenjector.Install(Location.MultiPlayer); @@ -51,7 +52,7 @@ public Plugin(Conf conf, IPALogger logger, PluginMetadata pluginMetadata) zenjector.Install(Location.Menu); zenjector.Install("Credits"); - zenjector.Install("Credits"); + zenjector.Install("Credits"); zenjector.UseMetadataBinder(); zenjector.UseLogger(logger); diff --git a/SiraUtil/Services/Controllers/GameMenuControllerAccessor.cs b/SiraUtil/Services/Controllers/GameMenuControllerAccessor.cs index c0c9c10..c4be514 100644 --- a/SiraUtil/Services/Controllers/GameMenuControllerAccessor.cs +++ b/SiraUtil/Services/Controllers/GameMenuControllerAccessor.cs @@ -9,13 +9,13 @@ internal class GameMenuControllerAccessor : IMenuControllerAccessor public VRController RightController { get; } public Transform Parent { get; } - public GameMenuControllerAccessor([InjectOptional] PauseMenuManager pauseMenuManager, [InjectOptional] MultiplayerLocalActivePlayerInGameMenuViewController multiplayerLocalActivePlayerInGameMenuViewController) + public GameMenuControllerAccessor([InjectOptional] PauseMenuManager pauseMenuManager, [InjectOptional] MultiplayerLocalActivePlayerInGameMenuViewController activeViewController, Context context) { - if (pauseMenuManager is null && multiplayerLocalActivePlayerInGameMenuViewController is null) - { + MultiplayerLocalInactivePlayerInGameMenuViewController? inactive = null; + if (pauseMenuManager == null && activeViewController == null && (inactive = context.GetComponentInChildren()) == null) throw new System.Exception("Cannot find menu controllers!"); - } - Transform controllerWrapper = pauseMenuManager is not null ? pauseMenuManager!.transform.Find("MenuControllers") : multiplayerLocalActivePlayerInGameMenuViewController.transform.Find("MenuControllers"); + + Transform controllerWrapper = pauseMenuManager != null ? pauseMenuManager!.transform.Find("MenuControllers") : activeViewController != null ? activeViewController.transform.Find("MenuControllers") : inactive!.transform.Find("MenuControllers"); LeftController = controllerWrapper.Find("ControllerLeft").GetComponent(); RightController = controllerWrapper.Find("ControllerRight").GetComponent(); Parent = controllerWrapper.transform; diff --git a/SiraUtil/Tools/FPFC/FPFCInstaller.cs b/SiraUtil/Tools/FPFC/FPFCInstaller.cs index 5e96b9a..27707c9 100644 --- a/SiraUtil/Tools/FPFC/FPFCInstaller.cs +++ b/SiraUtil/Tools/FPFC/FPFCInstaller.cs @@ -4,7 +4,7 @@ namespace SiraUtil.Tools.FPFC { - internal class FPFCInstaller : Installer + internal class SiraFullFPFCInstaller : Installer { public override void InstallBindings() { From 1d5f8ab499f5958d6ab21a87be6ad94fc23c25de Mon Sep 17 00:00:00 2001 From: Auros Nexus <41306347+Auros@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:43:20 -0400 Subject: [PATCH 4/6] Verbose Logging: Show full installer type #52 --- SiraUtil/Zenject/ZenjectManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SiraUtil/Zenject/ZenjectManager.cs b/SiraUtil/Zenject/ZenjectManager.cs index 9a10acf..a94a43f 100644 --- a/SiraUtil/Zenject/ZenjectManager.cs +++ b/SiraUtil/Zenject/ZenjectManager.cs @@ -90,7 +90,7 @@ private void ContextDecorator_ContextInstalling(Context mainContext, IEnumerable { if (set.installFilter.ShouldInstall(binding)) { - Plugin.Log.Debug($"Installing: {set.installerType.Name} onto {binding.installerType}"); + Plugin.Log.Debug($"Installing: {set.installerType.FullName} onto {binding.installerType}"); IInstructor? instructor = _instructorManager.InstructorForSet(set); if (instructor is null) { From 256559204e8a4990e476d58171c3400464cff65b Mon Sep 17 00:00:00 2001 From: Auros Nexus <41306347+Auros@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:45:36 -0400 Subject: [PATCH 5/6] Fix unfortunate paranthesis placement --- SiraUtil/Tools/FPFC/FPFCInstaller.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SiraUtil/Tools/FPFC/FPFCInstaller.cs b/SiraUtil/Tools/FPFC/FPFCInstaller.cs index 27707c9..92f77ad 100644 --- a/SiraUtil/Tools/FPFC/FPFCInstaller.cs +++ b/SiraUtil/Tools/FPFC/FPFCInstaller.cs @@ -9,7 +9,7 @@ internal class SiraFullFPFCInstaller : Installer public override void InstallBindings() { var args = Environment.GetCommandLineArgs(); - if (!args.Any(a => a.Equals(FPFCToggle.EnableArgument, StringComparison.OrdinalIgnoreCase) || args.Any(a => a.Equals(FPFCToggle.DisableArgument, StringComparison.OrdinalIgnoreCase)))) + if (!args.Any(a => a.Equals(FPFCToggle.EnableArgument, StringComparison.OrdinalIgnoreCase)) || args.Any(a => a.Equals(FPFCToggle.DisableArgument, StringComparison.OrdinalIgnoreCase))) { Container.Bind().To().AsSingle(); return; From d674352737c7767cf85f572c29174e8e0e012e68 Mon Sep 17 00:00:00 2001 From: Auros Nexus <41306347+Auros@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:46:35 -0400 Subject: [PATCH 6/6] SiraUtil 3.1.2 --- SiraUtil/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SiraUtil/manifest.json b/SiraUtil/manifest.json index fb6be59..3f20f61 100644 --- a/SiraUtil/manifest.json +++ b/SiraUtil/manifest.json @@ -3,7 +3,7 @@ "id": "SiraUtil", "name": "SiraUtil", "author": "Auros", - "version": "3.1.1", + "version": "3.1.2", "icon": "SiraUtil.Resources.logo.png", "description": "A powerful utility mod which expands the capabilities and provides more tools to Beat Saber modders.", "gameVersion": "1.24.0",