Skip to content

Commit

Permalink
1.37.3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Reezonate committed Aug 22, 2024
1 parent 388d337 commit 14f622c
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 85 deletions.
1 change: 0 additions & 1 deletion Source/0_Harmony/HarmonyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ private static void ApplyPermanentPatches() {
LazyInit();
AppInstallerPermanentPatch.ApplyPatch(_permanentHarmony);
MenuInstallerPermanentPatch.ApplyPatch(_permanentHarmony);
MainSettingsModelPermanentPatch.ApplyPatch(_permanentHarmony);
}

private static void ApplyRemovablePatches() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public static void ApplyPatch(Harmony harmony) {
}

[UsedImplicitly]
private static void Postfix() {
private static void Postfix(MainSettingsMenuViewControllersInstaller __instance) {
PluginConfig.MainSettingsManager = __instance.Container.TryResolve<SettingsManager>();
PluginConfig.SettingsApplicator = __instance.Container.TryResolve<SettingsApplicatorSO>();
Plugin.InitializeUI();
}
}
Expand Down
20 changes: 10 additions & 10 deletions Source/1_Config/ConfigMigration/ConfigMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ private static void OnVRPlatformHelperChanged(IVRPlatformHelper vrPlatformHelper
public static ConfigImportResult ImportFromSettings() {
if (!IsMigrationPossible) return ConfigImportResult.DevicelessFail;

var position = PluginConfig.MainSettingsHandler.instance.controllerSettings.positionOffset;
var rotationEuler = PluginConfig.MainSettingsHandler.instance.controllerSettings.rotationOffset;
var position = PluginConfig.BaseGameControllerPosition;
var rotationEuler = PluginConfig.BaseGameControllerRotation;

ConfigConversions.FromBaseGame(
_vrPlatformHelper,
Expand Down Expand Up @@ -157,23 +157,23 @@ public static ConfigExportResult ExportToSettings(Hand hand) {
out var rotationEuler
);

var beforePosition = PluginConfig.MainSettingsHandler.instance.controllerSettings.positionOffset;
var beforeRotation = PluginConfig.MainSettingsHandler.instance.controllerSettings.rotationOffset;
var beforePosition = PluginConfig.BaseGameControllerPosition;
var beforeRotation = PluginConfig.BaseGameControllerRotation;

PluginConfig.CreateUndoStep(
$"Export To Settings",
() => {
PluginConfig.MainSettingsHandler.instance.controllerSettings.positionOffset = beforePosition;
PluginConfig.MainSettingsHandler.instance.controllerSettings.rotationOffset = beforeRotation;
PluginConfig.BaseGameControllerPosition = beforePosition;
PluginConfig.BaseGameControllerRotation = beforeRotation;
},
() => {
PluginConfig.MainSettingsHandler.instance.controllerSettings.positionOffset = position;
PluginConfig.MainSettingsHandler.instance.controllerSettings.rotationOffset = rotationEuler;
PluginConfig.BaseGameControllerPosition = position;
PluginConfig.BaseGameControllerRotation = rotationEuler;
}
);

PluginConfig.MainSettingsHandler.instance.controllerSettings.positionOffset = position;
PluginConfig.MainSettingsHandler.instance.controllerSettings.rotationOffset = rotationEuler;
PluginConfig.BaseGameControllerPosition = position;
PluginConfig.BaseGameControllerRotation = rotationEuler;

return ConfigExportResult.Success;
}
Expand Down
50 changes: 42 additions & 8 deletions Source/1_Config/PluginConfig/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using BeatSaber.GameSettings;
using UnityEngine;

namespace EasyOffset;

Expand Down Expand Up @@ -27,20 +27,54 @@ public static IVRPlatformHelper VRPlatformHelper {

#endregion

#region MainSettingsModel
#region GameSettings

public static event Action<MainSettingsHandler> MainSettingsHandlerChangedEvent;
public static SettingsManager MainSettingsManager { private get; set; } = SettingsManager.CreateUninitialized();

private static MainSettingsHandler _mainSettingsHandler;
public static SettingsApplicatorSO SettingsApplicator { private get; set; }

public static MainSettingsHandler MainSettingsHandler {
get => _mainSettingsHandler;
public static float BaseGameAudioVolume => MainSettingsManager.settings.audio.volume;

public static Vector3 BaseGameRoomCenter {
get => MainSettingsManager.settings.room.center;
set {
MainSettingsManager.settings.room.center = value;
ApplyRoomSettings();
}
}

public static float BaseGameRoomRotation {
get => MainSettingsManager.settings.room.rotation;
set {
MainSettingsManager.settings.room.rotation = value;
ApplyRoomSettings();
}
}

public static Vector3 BaseGameControllerPosition {
get => MainSettingsManager.settings.controller.position;
set {
_mainSettingsHandler = value;
MainSettingsHandlerChangedEvent?.Invoke(value);
MainSettingsManager.settings.controller.position = value;
ApplyControllerSettings();
}
}

public static Vector3 BaseGameControllerRotation {
get => MainSettingsManager.settings.controller.rotation;
set {
MainSettingsManager.settings.controller.rotation = value;
ApplyControllerSettings();
}
}

private static void ApplyRoomSettings() {
SettingsApplicator?.NotifyRoomTransformOffsetWasUpdated();
}

private static void ApplyControllerSettings() {
VRPlatformHelper?.RefreshControllersReference();
}

#endregion

#region IsInMainMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void OnGrabStarted(
ReeTransform freeHandTransform
) {
_grabPosition = adjustmentHandTransform.Position;
_grabRoomCenter = PluginConfig.MainSettingsHandler.instance.roomCenter;
_grabRoomCenter = PluginConfig.BaseGameRoomCenter;
}

protected override void OnGrabUpdated(
Expand All @@ -58,7 +58,7 @@ ReeTransform freeHandTransform
var positionChange = adjustmentHandTransform.Position - _grabPosition;
var result = _grabRoomCenter - positionChange;

PluginConfig.MainSettingsHandler.instance.roomCenter = new Vector3(
PluginConfig.BaseGameRoomCenter = new Vector3(
PluginConfig.AllowRoomXChange ? result.x : _grabRoomCenter.x,
PluginConfig.AllowRoomYChange ? result.y : _grabRoomCenter.y,
PluginConfig.AllowRoomZChange ? result.z : _grabRoomCenter.z
Expand All @@ -71,12 +71,12 @@ protected override void OnGrabFinished(
ReeTransform freeHandTransform
) {
var beforeChange = _grabRoomCenter;
var afterChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
var afterChange = PluginConfig.BaseGameRoomCenter;

PluginConfig.CreateUndoStep(
"Room Offset",
() => PluginConfig.MainSettingsHandler.instance.roomCenter = beforeChange,
() => PluginConfig.MainSettingsHandler.instance.roomCenter = afterChange
() => PluginConfig.BaseGameRoomCenter = beforeChange,
() => PluginConfig.BaseGameRoomCenter = afterChange
);
}

Expand Down
22 changes: 8 additions & 14 deletions Source/7_Utils/StaticUtils/TransformUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using BGLib.SaveDataCore;
using UnityEngine;
using UnityEngine.XR;

Expand Down Expand Up @@ -191,21 +190,18 @@ float zOffset
#region ApplyRoomOffsets

public static void ApplyRoomOffset(ref Vector3 position, ref Quaternion rotation) {
if (PluginConfig.MainSettingsHandler.state < LoaderState.FileLoaded) return;
var roomRotation = Quaternion.Euler(0, PluginConfig.MainSettingsHandler.instance.roomRotation, 0);
position = PluginConfig.MainSettingsHandler.instance.roomCenter + roomRotation * position;
var roomRotation = Quaternion.Euler(0, PluginConfig.BaseGameRoomRotation, 0);
position = PluginConfig.BaseGameRoomCenter + roomRotation * position;
rotation = roomRotation * rotation;
}

public static void ApplyRoomOffsetToVector(ref Vector3 position) {
if (PluginConfig.MainSettingsHandler.state < LoaderState.FileLoaded) return;
var roomRotation = Quaternion.Euler(0, PluginConfig.MainSettingsHandler.instance.roomRotation, 0);
position = PluginConfig.MainSettingsHandler.instance.roomCenter + roomRotation * position;
var roomRotation = Quaternion.Euler(0, PluginConfig.BaseGameRoomRotation, 0);
position = PluginConfig.BaseGameRoomCenter + roomRotation * position;
}

public static void ApplyRoomOffsetToDirection(ref Vector3 direction) {
if (PluginConfig.MainSettingsHandler.state < LoaderState.FileLoaded) return;
var roomRotation = Quaternion.Euler(0, PluginConfig.MainSettingsHandler.instance.roomRotation, 0);
var roomRotation = Quaternion.Euler(0, PluginConfig.BaseGameRoomRotation, 0);
direction = roomRotation * direction;
}

Expand All @@ -214,14 +210,12 @@ public static void ApplyRoomOffsetToDirection(ref Vector3 direction) {
#region RemoveRoomOffset

public static void RemoveRoomOffsetFromVector(ref Vector3 position) {
if (PluginConfig.MainSettingsHandler.state < LoaderState.FileLoaded) return;
var roomRotation = Quaternion.Euler(0, PluginConfig.MainSettingsHandler.instance.roomRotation, 0);
position = Quaternion.Inverse(roomRotation) * (position - PluginConfig.MainSettingsHandler.instance.roomCenter);
var roomRotation = Quaternion.Euler(0, PluginConfig.BaseGameRoomRotation, 0);
position = Quaternion.Inverse(roomRotation) * (position - PluginConfig.BaseGameRoomCenter);
}

public static void RemoveRoomOffsetFromDirection(ref Vector3 direction) {
if (PluginConfig.MainSettingsHandler.state < LoaderState.FileLoaded) return;
var roomRotation = Quaternion.Euler(0, PluginConfig.MainSettingsHandler.instance.roomRotation, 0);
var roomRotation = Quaternion.Euler(0, PluginConfig.BaseGameRoomRotation, 0);
direction = Quaternion.Inverse(roomRotation) * direction;
}

Expand Down
32 changes: 16 additions & 16 deletions Source/8_UI/ModPanelUI/Panels/RoomOffsetPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void OnAdjustmentModeChanged(AdjustmentMode adjustmentMode) {
}

private void UpdateRoomCenter() {
var tmp = PluginConfig.MainSettingsHandler.instance.roomCenter;
var tmp = PluginConfig.BaseGameRoomCenter;
RoomXText = BuildRoomOffsetValueString("Room X", tmp.x, 40);
RoomYText = BuildRoomOffsetValueString("Room Y", tmp.y, 40);
RoomZText = BuildRoomOffsetValueString("Room Z", tmp.z, 40);
Expand Down Expand Up @@ -117,14 +117,14 @@ private void RoomXToggleOnChange(bool value) {

[UIAction("room-x-reset-on-click"), UsedImplicitly]
private void RoomXResetOnClick() {
var beforeChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
PluginConfig.MainSettingsHandler.instance.roomCenter = new Vector3(0, beforeChange.y, beforeChange.z);
var afterChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
var beforeChange = PluginConfig.BaseGameRoomCenter;
PluginConfig.BaseGameRoomCenter = new Vector3(0, beforeChange.y, beforeChange.z);
var afterChange = PluginConfig.BaseGameRoomCenter;

PluginConfig.CreateUndoStep(
"Room Offset",
() => PluginConfig.MainSettingsHandler.instance.roomCenter = beforeChange,
() => PluginConfig.MainSettingsHandler.instance.roomCenter = afterChange
() => PluginConfig.BaseGameRoomCenter = beforeChange,
() => PluginConfig.BaseGameRoomCenter = afterChange
);
}

Expand Down Expand Up @@ -153,14 +153,14 @@ private void RoomYToggleOnChange(bool value) {

[UIAction("room-y-reset-on-click"), UsedImplicitly]
private void RoomYResetOnClick() {
var beforeChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
PluginConfig.MainSettingsHandler.instance.roomCenter = new Vector3(beforeChange.x, 0, beforeChange.z);
var afterChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
var beforeChange = PluginConfig.BaseGameRoomCenter;
PluginConfig.BaseGameRoomCenter = new Vector3(beforeChange.x, 0, beforeChange.z);
var afterChange = PluginConfig.BaseGameRoomCenter;

PluginConfig.CreateUndoStep(
"Room Offset",
() => PluginConfig.MainSettingsHandler.instance.roomCenter = beforeChange,
() => PluginConfig.MainSettingsHandler.instance.roomCenter = afterChange
() => PluginConfig.BaseGameRoomCenter = beforeChange,
() => PluginConfig.BaseGameRoomCenter = afterChange
);
}

Expand Down Expand Up @@ -189,14 +189,14 @@ private void RoomZToggleOnChange(bool value) {

[UIAction("room-z-reset-on-click"), UsedImplicitly]
private void RoomZResetOnClick() {
var beforeChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
PluginConfig.MainSettingsHandler.instance.roomCenter = new Vector3(beforeChange.x, beforeChange.y, 0);
var afterChange = PluginConfig.MainSettingsHandler.instance.roomCenter;
var beforeChange = PluginConfig.BaseGameRoomCenter;
PluginConfig.BaseGameRoomCenter = new Vector3(beforeChange.x, beforeChange.y, 0);
var afterChange = PluginConfig.BaseGameRoomCenter;

PluginConfig.CreateUndoStep(
"Room Offset",
() => PluginConfig.MainSettingsHandler.instance.roomCenter = beforeChange,
() => PluginConfig.MainSettingsHandler.instance.roomCenter = afterChange
() => PluginConfig.BaseGameRoomCenter = beforeChange,
() => PluginConfig.BaseGameRoomCenter = afterChange
);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/8_UI/UserGuide/VideoPlayer/VideoRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void Construct(ImageView screen) {
_videoPlayer.aspectRatio = VideoAspectRatio.Stretch;
_videoPlayer.source = VideoSource.Url;
_videoPlayer.playOnAwake = false;
_videoPlayer.SetDirectAudioVolume(0, PluginConfig.MainSettingsHandler.instance.audioSettings.volume);
_videoPlayer.SetDirectAudioVolume(0, PluginConfig.BaseGameAudioVolume);

_videoPlayer.loopPointReached += _ => OnVideoEnded?.Invoke();

Expand Down
7 changes: 5 additions & 2 deletions Source/EasyOffset.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<Reference Include="Unity.InputSystem">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.InputSystem.dll</HintPath>
</Reference>
<Reference Include="Unity.Mathematics">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.Mathematics.dll</HintPath>
</Reference>
</ItemGroup>

<!-- HM REFERENCES -->
Expand All @@ -96,8 +99,8 @@
<Reference Include="BeatSaber.Init">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.Init.dll</HintPath>
</Reference>
<Reference Include="BeatSaber.GameSettings">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.GameSettings.dll</HintPath>
<Reference Include="BeatSaber.Settings">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.Settings.dll</HintPath>
</Reference>
<Reference Include="DataModels">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\DataModels.dll</HintPath>
Expand Down
6 changes: 2 additions & 4 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public static void InitializeUI() {

#region OnApplicationStart

[OnStart]
[UsedImplicitly]
[OnStart, UsedImplicitly]
public void OnApplicationStart() {
HarmonyHelper.Initialize();
}
Expand All @@ -59,8 +58,7 @@ public void OnApplicationStart() {

#region OnApplicationQuit

[OnExit]
[UsedImplicitly]
[OnExit, UsedImplicitly]
public void OnApplicationQuit() { }

#endregion
Expand Down
4 changes: 2 additions & 2 deletions Source/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"id": "EasyOffset",
"name": "EasyOffset",
"author": "Reezonate",
"version": "2.1.10",
"version": "2.1.11",
"description": "Easy controller offset adjustment tool",
"gameVersion": "1.37.1",
"gameVersion": "1.37.3",
"dependsOn": {
"BSIPA": "^4.3.3",
"BeatSaberMarkupLanguage": "^1.11.0",
Expand Down

0 comments on commit 14f622c

Please sign in to comment.