Skip to content

Commit

Permalink
Migrate to BSIPA 4
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Mar 27, 2020
1 parent 9f4874e commit 3f00ff0
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 48 deletions.
Binary file removed Libraries/0Harmony.1.2.0.1.dll
Binary file not shown.
Binary file added Libraries/0Harmony.dll
Binary file not shown.
Binary file modified Libraries/IPA.Injector.dll
Binary file not shown.
Binary file modified Libraries/IPA.Loader.dll
Binary file not shown.
Binary file removed Libraries/Newtonsoft.Json.12.0.0.0.dll
Binary file not shown.
Binary file added Libraries/Newtonsoft.Json.dll
Binary file not shown.
5 changes: 4 additions & 1 deletion Packaging/DynamicOpenVR/Plugins/DynamicOpenVR.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"name": "DynamicOpenVR",
"version": "0.2.0",
"features": [],
"dependsOn": {}
"dependsOn": {},
"files": [
"Libs\\DynamicOpenVR.dll"
]
}
2 changes: 1 addition & 1 deletion Source/DynamicOpenVR.BeatSaber/BeatSaberInputPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.

using Harmony;
using HarmonyLib;
using System;
using UnityEngine.XR;

Expand Down
10 changes: 6 additions & 4 deletions Source/DynamicOpenVR.BeatSaber/DynamicOpenVR.BeatSaber.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony.1.2.0.1">
<HintPath>..\..\Libraries\0Harmony.1.2.0.1.dll</HintPath>
<Reference Include="0Harmony">
<HintPath>..\..\Libraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="HMLib">
<HintPath>..\..\Libraries\HMLib.dll</HintPath>
Expand All @@ -46,8 +46,9 @@
<Reference Include="Main">
<HintPath>..\..\Libraries\Main.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json.12.0.0.0">
<HintPath>..\..\Libraries\Newtonsoft.Json.12.0.0.0.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Libraries\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -75,6 +76,7 @@
<Compile Include="IPALogHandler.cs" />
<Compile Include="MessageBox.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="OpenVREventHandler.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BeatSaberInputPatches.cs" />
Expand Down
24 changes: 24 additions & 0 deletions Source/DynamicOpenVR.BeatSaber/OpenVREventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using Valve.VR;

namespace DynamicOpenVR.BeatSaber
{
internal class OpenVREventHandler : MonoBehaviour
{
private readonly HashSet<EVREventType> _pauseEvents = new HashSet<EVREventType>(new [] { EVREventType.VREvent_InputFocusCaptured, EVREventType.VREvent_DashboardActivated, EVREventType.VREvent_OverlayShown });

public event Action onGamePaused;

private void Update()
{
VREvent_t evt = default;
if (OpenVR.System.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))) && _pauseEvents.Contains((EVREventType) evt.eventType))
{
onGamePaused?.Invoke();
}
}
}
}
61 changes: 24 additions & 37 deletions Source/DynamicOpenVR.BeatSaber/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using DynamicOpenVR.IO;
using Harmony;
using HarmonyLib;
using IPA;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using Valve.VR;
using Logger = IPA.Logging.Logger;
using Object = UnityEngine.Object;

namespace DynamicOpenVR.BeatSaber
{
public class Plugin : IBeatSaberPlugin
[Plugin(RuntimeOptions.SingleStartInit)]
internal class Plugin
{
public static Logger logger { get; private set; }
public static VectorInput leftTriggerValue { get; private set; }
Expand All @@ -43,18 +42,18 @@ public class Plugin : IBeatSaberPlugin
public static PoseInput rightHandPose { get; private set; }

private readonly string _actionManifestPath = Path.Combine(Environment.CurrentDirectory, "DynamicOpenVR", "action_manifest.json");
private readonly HashSet<EVREventType> _pauseEvents = new HashSet<EVREventType>(new [] { EVREventType.VREvent_InputFocusCaptured, EVREventType.VREvent_DashboardActivated, EVREventType.VREvent_OverlayShown });

private HarmonyInstance _harmonyInstance;
private bool _initialized;
private Harmony _harmonyInstance;

public void Init(Logger logger)
[Init]
public Plugin(Logger logger)
{
Plugin.logger = logger;
Logging.Logger.handler = new IPALogHandler();
}

public void OnApplicationStart()
[OnStart]
public void OnStart()
{
logger.Info("Starting " + typeof(Plugin).Namespace);

Expand Down Expand Up @@ -87,41 +86,29 @@ public void OnApplicationStart()

OpenVRActionManager.instance.Initialize(_actionManifestPath);

_initialized = true;
OpenVREventHandler eventHandler = new GameObject(nameof(OpenVREventHandler)).AddComponent<OpenVREventHandler>();
Object.DontDestroyOnLoad(eventHandler.gameObject);
eventHandler.onGamePaused += OnGamePaused;
}

public void OnApplicationQuit()
[OnExit]
public void OnExit()
{
// not really necessary since the game is closing, just following good practices
if (_initialized)
{
leftTriggerValue?.Dispose();
rightTriggerValue?.Dispose();
menu?.Dispose();
leftSlice?.Dispose();
rightSlice?.Dispose();
leftHandPose?.Dispose();
rightHandPose?.Dispose();
}
leftTriggerValue?.Dispose();
rightTriggerValue?.Dispose();
menu?.Dispose();
leftSlice?.Dispose();
rightSlice?.Dispose();
leftHandPose?.Dispose();
rightHandPose?.Dispose();
}

public void OnUpdate()
private void OnGamePaused()
{
if (_initialized)
{
VREvent_t evt = default;
if (OpenVR.System.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))) && _pauseEvents.Contains((EVREventType) evt.eventType))
{
Resources.FindObjectsOfTypeAll<PauseController>().FirstOrDefault()?.Pause();
}
}
Resources.FindObjectsOfTypeAll<PauseController>().FirstOrDefault()?.Pause();
}

public void OnFixedUpdate() { }
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { }
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) { }
public void OnSceneUnloaded(Scene scene) { }

private void AddManifestToSteamConfig()
{
string steamFolder = SteamUtilities.GetSteamHomeDirectory();
Expand Down Expand Up @@ -294,7 +281,7 @@ private void ApplyHarmonyPatches()
{
logger.Info("Applying input patches");

_harmonyInstance = HarmonyInstance.Create(GetType().Namespace);
_harmonyInstance = new Harmony("com.nicoco007.dynamic-open-vr-beat-saber");
_harmonyInstance.PatchAll();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DynamicOpenVR.BeatSaber/XRInputPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.

using Harmony;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using UnityEngine;
using UnityEngine.XR;

Expand Down
12 changes: 10 additions & 2 deletions Source/DynamicOpenVR.BeatSaber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
"version": "0.2.0",
"features": [],
"dependsOn": {
"BSIPA": "^3.13.0",
"BSIPA": "^4.0.0",
"DynamicOpenVR": "^0.2.0"
}
},
"files": [
"DynamicOpenVR\\Actions\\beatsaber.json",
"DynamicOpenVR\\Bindings\\beatsaber_holographic_controller.json",
"DynamicOpenVR\\Bindings\\beatsaber_hypereal_controller.json",
"DynamicOpenVR\\Bindings\\beatsaber_knuckles.json",
"DynamicOpenVR\\Bindings\\beatsaber_oculus_touch.json",
"DynamicOpenVR\\Bindings\\beatsaber_vive_controller.json"
]
}
5 changes: 3 additions & 2 deletions Source/DynamicOpenVR/DynamicOpenVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json.12.0.0.0">
<HintPath>..\..\Libraries\Newtonsoft.Json.12.0.0.0.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Libraries\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit 3f00ff0

Please sign in to comment.