Skip to content

Commit

Permalink
SiraUtil 3.1.2
Browse files Browse the repository at this point in the history
SiraUtil 3.1.2
  • Loading branch information
Auros authored Aug 25, 2022
2 parents beae7a1 + d674352 commit 63cce15
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 59 deletions.
3 changes: 1 addition & 2 deletions SiraUtil.Suite/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class Plugin
public Plugin(IPALogger logger, Zenjector zenjector)
{
Log = logger;

zenjector.UseAutoBinder();
zenjector.Install<GenericCustomInstaller>(Location.Menu);
zenjector.Install<MonoCustomInstaller>(Location.Tutorial);
Expand Down Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions SiraUtil/Installers/SiraGameplayFPFCInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SiraUtil.Services.Controllers;
using Zenject;

namespace SiraUtil.Installers
{
internal class SiraAllPlayersFPFCInstaller : Installer
{
public override void InstallBindings()
{
Container.BindInterfacesAndSelfTo<GameMenuControllerAccessor>().AsSingle();
}
}
}
3 changes: 0 additions & 3 deletions SiraUtil/Installers/SiraGameplayInstaller.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,8 +11,6 @@ internal class SiraGameplayInstaller : Installer
{
public override void InstallBindings()
{
// FPFC stuff
Container.BindInterfacesAndSelfTo<GameMenuControllerAccessor>().AsSingle();
Container.BindInterfacesTo<GameTransformFPFCListener>().AsSingle();

// SongControl stuff
Expand Down
3 changes: 2 additions & 1 deletion SiraUtil/Installers/SiraSettingsInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public override void InstallBindings()
Container.BindInstance(_config.SongControl).AsSingle();
Container.BindInterfacesTo<FPFCSettingsController>().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<FPFCAffinityDaemon>().AsSingle().NonLazy();
}
}
Expand Down
5 changes: 3 additions & 2 deletions SiraUtil/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public Plugin(Conf conf, IPALogger logger, PluginMetadata pluginMetadata)

Zenjector zenjector = (ConstructZenjector(null!, null!, pluginMetadata) as Zenjector)!;
zenjector.Install<SiraStandardCampaignMultiplayerInstaller>(Location.StandardPlayer | Location.CampaignPlayer | Location.MultiPlayer);
zenjector.Install<SiraFullFPFCInstaller>(Location.Menu | Location.Player | Location.InactiveMultiPlayer | Location.Tutorial);
zenjector.Install<SiraAllPlayersFPFCInstaller>(Location.Player | Location.InactiveMultiPlayer | Location.Tutorial);
zenjector.Install<SiraInitializationInstaller>(Location.App, _zenjectManager, zenjector);
zenjector.Install<FPFCInstaller>(Location.Menu | Location.Player | Location.Tutorial);
zenjector.Install<SiraGameplayInstaller>(Location.Player | Location.Tutorial);
zenjector.Install<SiraSingleplayerInstaller>(Location.Singleplayer);
zenjector.Install<SiraMultiplayerInstaller>(Location.MultiPlayer);
Expand All @@ -51,7 +52,7 @@ public Plugin(Conf conf, IPALogger logger, PluginMetadata pluginMetadata)
zenjector.Install<SiraMenuInstaller>(Location.Menu);

zenjector.Install<SiraCreditsInstaller, GameObjectContext>("Credits");
zenjector.Install<FPFCInstaller, GameObjectContext>("Credits");
zenjector.Install<SiraFullFPFCInstaller, GameObjectContext>("Credits");

zenjector.UseMetadataBinder<Plugin>();
zenjector.UseLogger(logger);
Expand Down
10 changes: 5 additions & 5 deletions SiraUtil/Services/Controllers/GameMenuControllerAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MultiplayerLocalInactivePlayerInGameMenuViewController>()) == 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<VRController>();
RightController = controllerWrapper.Find("ControllerRight").GetComponent<VRController>();
Parent = controllerWrapper.transform;
Expand Down
5 changes: 3 additions & 2 deletions SiraUtil/Tools/FPFC/FPFCInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace SiraUtil.Tools.FPFC
{
internal class FPFCInstaller : Installer
internal class SiraFullFPFCInstaller : 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<IFPFCSettings>().To<NoFPFCSettings>().AsSingle();
return;
Expand Down
3 changes: 2 additions & 1 deletion SiraUtil/Tools/FPFC/FPFCToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
86 changes: 46 additions & 40 deletions SiraUtil/Web/Implementations/UWRHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using IPA.Utilities.Async;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -81,57 +82,62 @@ public Task<IHttpResponse> DeleteAsync(string url, CancellationToken? cancellati

public async Task<IHttpResponse> SendAsync(HTTPMethod method, string url, string? body = null, IDictionary<string, string>? withHeaders = null, IProgress<float>? 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;
}
}
}
2 changes: 1 addition & 1 deletion SiraUtil/Zenject/ZenjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions SiraUtil/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"id": "SiraUtil",
"name": "SiraUtil",
"author": "Auros",
"version": "3.1.0",
"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.22.1",
"gameVersion": "1.24.0",
"dependsOn": {
"BSIPA": "^4.2.1"
},
Expand Down

0 comments on commit 63cce15

Please sign in to comment.