Skip to content

Commit

Permalink
Fix for 1.39.1
Browse files Browse the repository at this point in the history
-  A certain iPixelGalaxy forced my hand
  • Loading branch information
Arimodu committed Dec 11, 2024
1 parent 6eb4b38 commit 5fe4994
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 78 deletions.
85 changes: 85 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>

<Project>
<!-- Target for copying DLLs to Plugins folder -->
<Target Name="CopyToPlugins" AfterTargets="Build">
<PropertyGroup>
<PluginsDirectory>$(BeatSaberDir)\Plugins</PluginsDirectory>
<PendingPluginsDirectory>$(BeatSaberDir)\IPA\Pending\Plugins</PendingPluginsDirectory>
<OutputAssemblyName>$(OutputPath)$(AssemblyName)</OutputAssemblyName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugPdbFile>$(OutputPath)$(AssemblyName).pdb</DebugPdbFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'Release Final'">
<ReleasePdbFile>$(OutputPath)$(AssemblyName).pdb</ReleasePdbFile>
</PropertyGroup>

<Message Importance="High" Text="Copying '$(OutputAssemblyName).dll' -> '$(PluginsDirectory)'" Condition="'$(Configuration)' == 'Debug'" />

<Copy Condition="'$(Configuration)' == 'Debug'"
SourceFiles="$(OutputAssemblyName).dll;$(DebugPdbFile)"
DestinationFolder="$(PluginsDirectory)"
ContinueOnError="false"/>

<Message Importance="High" Text="Copying '$(OutputAssemblyName).dll' -> '$(PluginsDirectory)'" Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'Release Final'" />
<Copy Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'Release Final'"
SourceFiles="$(OutputAssemblyName).dll"
DestinationFolder="$(PluginsDirectory)"
ContinueOnError="false"/>

<Error Condition="!Exists('$(PluginsDirectory)\$(AssemblyName).dll') And !Exists('$(PluginsDirectory)\$(AssemblyName).pdb')"
Text="Copying to Plugins folder failed. Copying to Pending Plugins folder instead."/>

<Message Importance="High" Text="Copying '$(OutputAssemblyName).dll' -> '$(PendingPluginsDirectory)'" Condition="'$(Configuration)' == 'Debug'" />
<Copy Condition="'$(Configuration)' == 'Debug'"
SourceFiles="$(OutputAssemblyName).dll;$(DebugPdbFile)"
DestinationFolder="$(PendingPluginsDirectory)"
ContinueOnError="false"/>

<Message Importance="High" Text="Copying '$(OutputAssemblyName).dll' -> '$(PendingPluginsDirectory)'" Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'Release Final'" />
<Copy Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'Release Final'"
SourceFiles="$(OutputAssemblyName).dll;$(ReleasePdbFile)"
DestinationFolder="$(PendingPluginsDirectory)"
ContinueOnError="false"/>

<Error Condition="!Exists('$(PendingPluginsDirectory)\$(AssemblyName).dll') And !Exists('$(PendingPluginsDirectory)\$(AssemblyName).pdb')"
Text="Copying to Pending Plugins folder failed. Please check the build output for more information."/>

<Message Importance="High" Text="Beat Saber is running. Please restart the game for changes to be applied." Condition="!Exists('$(PluginsDirectory)\$(AssemblyName).dll') And !Exists('$(PluginsDirectory)\$(AssemblyName).pdb')" />
</Target>

<!-- Target for Release configuration -->
<Target Name="CopyDllToReleaseDirectory" AfterTargets="CopyToPlugins" Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'Release Final'">
<PropertyGroup>
<DestinationRoot>G:\WebStatic\dirlist\SelfReleases\Build</DestinationRoot>
<BeatSaberDirName>$([System.IO.Path]::GetFileName($(BeatSaberDir)))</BeatSaberDirName>
<DestinationDirectory>$(DestinationRoot)\$(BeatSaberDirName)\$(MSBuildProjectName)</DestinationDirectory>
<OutputAssemblyName>$(OutputPath)$(AssemblyName)</OutputAssemblyName>
<BuildTargetDestinationFile>$(DestinationDirectory)\BuildTarget.txt</BuildTargetDestinationFile>
</PropertyGroup>

<MakeDir Directories="$(DestinationDirectory)" />

<Message Text="Copying '$(OutputAssemblyName).dll' -> '$(DestinationDirectory)\$(AssemblyName).dll'" Importance="high" />
<Copy SourceFiles="$(OutputAssemblyName).dll" DestinationFolder="$(DestinationDirectory)" />

<WriteLinesToFile File="$(BuildTargetDestinationFile)" Lines="$(BeatSaberDir)" Overwrite="true" />
</Target>

<!-- Target for Release Final configuration -->
<Target Name="CopyDllToReleaseFinalDirectory" AfterTargets="CopyToPlugins" Condition="'$(Configuration)' == 'Release Final'">
<PropertyGroup>
<FinalDestinationRoot>G:\WebStatic\dirlist\SelfReleases\Beat Saber</FinalDestinationRoot>
<FinalDestinationDirectory>$(FinalDestinationRoot) $(BeatSaberDirName)</FinalDestinationDirectory>
<FinalOutputAssemblyName>$(OutputPath)$(AssemblyName)</FinalOutputAssemblyName>
</PropertyGroup>

<MakeDir Directories="$(FinalDestinationDirectory)" />

<Message Text="Copying '$(FinalOutputAssemblyName).dll' -> '$(FinalDestinationDirectory)\$(AssemblyName).dll'" Importance="high" />
<Copy SourceFiles="$(FinalOutputAssemblyName).dll" DestinationFolder="$(FinalDestinationDirectory)" />
</Target>
</Project>
60 changes: 19 additions & 41 deletions MirrorManager.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,48 @@
using SiraUtil.Logging;
using System;
using System.Linq;
using UnityEngine;
using Zenject;
using static BeatSaber.Settings.QualitySettings;

namespace QuickMirrorToggle
{
internal class MirrorManager : IInitializable, IDisposable
{
private readonly MirrorRendererSO MirrorRenderer;
private readonly MirrorRendererGraphicsSettingsPresets MirrorGraphicsPreset;
private readonly MainSettingsModelSO MainSettingsModel;
[Inject] private readonly SettingsManager _settingsManager;
[Inject] private readonly SettingsApplicatorSO _settingsApplicator;
[Inject] private readonly GameScenesManager _gameScenesManager;
[Inject] private readonly IFileStorage _fileStorage;
[Inject] private readonly QMTConfig _config;
[Inject] private readonly SiraLog _logger;
[Inject] private readonly QMTUI UI;

public MirrorManager()
{
MirrorRenderer = Resources.FindObjectsOfTypeAll<MirrorRendererSO>().First();
MirrorGraphicsPreset = Resources.FindObjectsOfTypeAll<MirrorRendererGraphicsSettingsPresets>().First();
MainSettingsModel = Resources.FindObjectsOfTypeAll<MainSettingsModelSO>().First();
}

public void Initialize()
{
_logger.Info("Initializing MirrorManager");
_config.GameMirrorSetting = (MirrorState)(int)MainSettingsModel.mirrorGraphicsSettings;
_config.GameMirrorSetting = _settingsManager.settings.quality.mirror;
SetMirrorState(_config.MirrorState);
UI.QMTToggleValue = _config.GameMirrorSetting == MirrorState.Off ? (_config.MirrorState != MirrorState.Off) : (_config.MirrorState == MirrorState.Off);

_config.OnChanged += Config_OnChanged;
_gameScenesManager.transitionDidFinishEvent += GameScenesManager_transitionDidFinishEvent;
}

private void Config_OnChanged(QMTConfig newConfig)
private void GameScenesManager_transitionDidFinishEvent(GameScenesManager.SceneTransitionType arg1, ScenesTransitionSetupDataSO SceneSetupData, DiContainer arg3)
{
SetMirrorState(newConfig.MirrorState);
SetMirrorState(_config.MirrorState);
}

public void SetMirrorState(MirrorState state)
private void Config_OnChanged(QMTConfig newConfig)
{
var preset = MirrorGraphicsPreset.presets[MainSettingsModel.mirrorGraphicsSettings]; // Default to game default if anything unexpected happens
switch (state)
{
case MirrorState.Off:
preset = MirrorGraphicsPreset.presets[0];
break;
case MirrorState.Low:
preset = MirrorGraphicsPreset.presets[1];
break;
case MirrorState.Medium:
preset = MirrorGraphicsPreset.presets[2];
break;
case MirrorState.High:
preset = MirrorGraphicsPreset.presets[3];
break;
default:
break;
}

SetMirrorFromPreset(preset);
SetMirrorState(newConfig.MirrorState);
}

private void SetMirrorFromPreset(MirrorRendererGraphicsSettingsPresets.Preset preset)
public void SetMirrorState(MirrorQuality state)
{
_logger.Info($"Setting mirror to {preset.mirrorType}");
MirrorRenderer.Init(preset.reflectLayers, preset.stereoTextureWidth, preset.stereoTextureHeight, preset.monoTextureWidth, preset.monoTextureHeight, preset.maxAntiAliasing, preset.enableBloomPrePassFog);
_logger.Info($"Setting mirror to {state}");
var settings = _settingsManager.settings;
settings.quality.mirror = state;
//await SettingsIO.SaveAsync(_fileStorage, settings);
_settingsManager.settings = settings;
_settingsApplicator.ApplyGraphicSettings(settings, SceneType.Menu);
_settingsApplicator.ApplyGraphicSettings(settings, SceneType.Game);
}

public void Dispose()
Expand Down
17 changes: 5 additions & 12 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@ public Plugin(IPALogger logger, Config config, Zenjector zenject)

zenject.Install(Location.Menu, Container =>
{
#if LATEST
Container.BindInterfacesAndSelfTo<QMTUI>().AsSingle();
#else
Container.BindInterfacesAndSelfTo<QMTUI>().FromNewComponentAsViewController().AsSingle();
#endif
Container.BindInterfacesAndSelfTo<MirrorManager>().AsSingle();
});
}
}

public enum MirrorState
{
Off,
Low,
Medium,
High
//zenject.Install(Location.GameCore, Container =>
//{
// Container.BindInterfacesAndSelfTo<MirrorManager>().AsSingle();
//});
}
}
}
13 changes: 7 additions & 6 deletions QMTConfig.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using IPA.Config.Stores.Attributes;
using System;
using BeatSaber.Settings;

namespace QuickMirrorToggle
{
public class QMTConfig
{
[UseConverter(typeof(StringEnumConverter<MirrorState>))]
public virtual MirrorState MirrorState { get; set; } = MirrorState.Off;
[UseConverter(typeof(StringEnumConverter<MirrorState>))]
public virtual MirrorState QMTMirrorSetting { get; set; } = MirrorState.High;
[UseConverter(typeof(StringEnumConverter<MirrorState>))]
public virtual MirrorState GameMirrorSetting { get; set; } = MirrorState.Medium;
[UseConverter(typeof(StringEnumConverter<QualitySettings.MirrorQuality>))]
public virtual QualitySettings.MirrorQuality MirrorState { get; set; } = QualitySettings.MirrorQuality.Off;
[UseConverter(typeof(StringEnumConverter<QualitySettings.MirrorQuality>))]
public virtual QualitySettings.MirrorQuality QMTMirrorSetting { get; set; } = QualitySettings.MirrorQuality.High;
[UseConverter(typeof(StringEnumConverter<QualitySettings.MirrorQuality>))]
public virtual QualitySettings.MirrorQuality GameMirrorSetting { get; set; } = QualitySettings.MirrorQuality.Medium;

public event Action<QMTConfig> OnChanged;
public void Changed()
Expand Down
39 changes: 20 additions & 19 deletions QMTUI.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
using BeatSaberMarkupLanguage;
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.GameplaySetup;
#if LATEST
using BeatSaberMarkupLanguage.Util;
#else
using BeatSaberMarkupLanguage.Components;
#endif
using BeatSaberMarkupLanguage.ViewControllers;
using SiraUtil.Logging;
using System.Linq;
using UnityEngine;
using Zenject;
using static BeatSaber.Settings.QualitySettings;

#pragma warning disable IDE0052 // Remove unread private members
namespace QuickMirrorToggle
{
internal class QMTUI : NotifiableSingleton<QMTUI>, IInitializable
internal class QMTUI : BSMLAutomaticViewController, IInitializable
{
private const string QMT_TOGGLE = "" +
"<bg id='qmt-root'>" +
"<horizontal anchor-pos-x='-80' anchor-pos-y='65' preferred-width='40' horizontal-fit='PreferredSize' ignore-layout='true'>" +
"<toggle-setting id='qmt-toggle' hover-hint='His name is Teddy ;3' text='~qmt-toggle-text' size-delta-x='1' size-delta-y='1' bind-value='true' apply-on-change='true' value='qmt-toggle-value'/>" +
"</horizontal>" +
"</bg>";

[UIValue("qmt-mirror-setting-options")]
private string[] _mirrorSettings = new string[] { "Low", "Medium", "High" };
private readonly string[] _mirrorSettings = new string[] { "Low", "Medium", "High" };

[Inject] private readonly QMTConfig _config;
[Inject] private readonly SiraLog _logger;
private string _qmtText = "Disable Mirror";
Expand Down Expand Up @@ -51,13 +51,13 @@ public bool QMTToggleValue
_logger.Info("QMTToggleValue set to " + value);
_qmtToggleValue = value;
NotifyPropertyChanged();
if (_config.GameMirrorSetting == MirrorState.Off)
if (_config.GameMirrorSetting == MirrorQuality.Off)
{
_config.MirrorState = value ? _config.QMTMirrorSetting : MirrorState.Off;
_config.MirrorState = value ? _config.QMTMirrorSetting : MirrorQuality.Off;
}
else
{
_config.MirrorState = value ? MirrorState.Off : _config.GameMirrorSetting;
_config.MirrorState = value ? MirrorQuality.Off : _config.GameMirrorSetting;
}
_config.Changed();
}
Expand All @@ -69,8 +69,8 @@ public string SetValue
get => _config.QMTMirrorSetting.ToString();
set
{
_config.QMTMirrorSetting = (MirrorState)System.Enum.Parse(typeof(MirrorState), value);
if (_config.GameMirrorSetting == MirrorState.Off && _config.MirrorState != MirrorState.Off)
_config.QMTMirrorSetting = (MirrorQuality)System.Enum.Parse(typeof(MirrorQuality), value);
if (_config.GameMirrorSetting == MirrorQuality.Off && _config.MirrorState != MirrorQuality.Off)
{
_config.MirrorState = _config.QMTMirrorSetting;
}
Expand All @@ -80,23 +80,24 @@ public string SetValue

public void Initialize()
{
GameplaySetup.instance.AddTab("Quick Mirror Toggle", "QuickMirrorToggle.SettingsUI.bsml", this);
BSMLParser.instance.Parse(QMT_TOGGLE, Resources.FindObjectsOfTypeAll<LevelSelectionNavigationController>().First().gameObject, this);
GameplaySetup.Instance.AddTab("Quick Mirror Toggle", "QuickMirrorToggle.SettingsUI.bsml", this);
BSMLParser.Instance.Parse(QMT_TOGGLE, Resources.FindObjectsOfTypeAll<LevelSelectionNavigationController>().First().gameObject, this);
_qmtRectTransform.localScale *= 0.6f;
QMTText = _config.GameMirrorSetting == MirrorState.Off ? "Enable Mirror" : "Disable Mirror";
QMTText = _config.GameMirrorSetting == MirrorQuality.Off ? "Enable Mirror" : "Disable Mirror";
_config.OnChanged += Config_OnChanged;
QMTToggleValue = _config.GameMirrorSetting == MirrorQuality.Off ? (_config.MirrorState != MirrorQuality.Off) : (_config.MirrorState == MirrorQuality.Off);
}

private void Config_OnChanged(QMTConfig newConfig)
{
switch (newConfig.GameMirrorSetting)
{
case MirrorState.Off:
case MirrorQuality.Off:
QMTText = "Enable Mirror";
break;
case MirrorState.Low:
case MirrorState.Medium:
case MirrorState.High:
case MirrorQuality.Low:
case MirrorQuality.Medium:
case MirrorQuality.High:
QMTText = "Disable Mirror";
break;
default:
Expand Down
40 changes: 40 additions & 0 deletions QuickMirrorToggle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@
<DisableZipRelease>True</DisableZipRelease>
</PropertyGroup>
<ItemGroup>
<Reference Include="BeatSaber.Settings">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.Settings.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BeatSaber.ViewSystem, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.ViewSystem.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BGLib.AppFlow">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.AppFlow.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BGLib.FileStorage">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.FileStorage.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="BGLib.UnityExtension">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.UnityExtension.dll</HintPath>
<Private>False</Private>
Expand All @@ -79,6 +99,11 @@
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="DataModels, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\DataModels.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Rendering">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Rendering.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -111,6 +136,11 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Unity.Mathematics">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.Mathematics.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -139,6 +169,16 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRUI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\VRUI.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="VRUI.Interfaces">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\VRUI.Interfaces.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Zenject">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
<Private>False</Private>
Expand Down

0 comments on commit 5fe4994

Please sign in to comment.