Skip to content

Commit

Permalink
Fixes for Beat Saber 1.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Oct 13, 2020
1 parent 5349762 commit 28f693a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Packaging/DynamicOpenVR/Plugins/DynamicOpenVR.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"$schema": "https://raw.githubusercontent.com/beat-saber-modding-group/BSIPA-MetadataFileSchema/master/Schema.json",
"author": "Nicolas Gnyra",
"description": "Unity scripts to allow dynamic creation of OpenVR actions at runtime.",
"gameVersion": "1.11.0",
"gameVersion": "1.12.1",
"id": "DynamicOpenVR",
"name": "DynamicOpenVR",
"version": "0.3.0+dev",
"version": "0.3.1+dev",
"features": [],
"dependsOn": {},
"files": [
Expand Down
10 changes: 5 additions & 5 deletions Source/DynamicOpenVR.BeatSaber/DynamicOpenVR.BeatSaber.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@
</ItemGroup>
<ItemGroup>
<CopyToOutput Include="$(ProjectDir)..\..\Packaging\DynamicOpenVR.BeatSaber\**\*.*" />
<CopyToBeatSaberFolder Include="$(TargetDir)**\*.*" />
<CopyToBeatSaberFolder Include="$(PublishDir)**\*.*" />
</ItemGroup>
<Target Name="ClearReferenceCopyLocalPaths" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<!-- prevent any referenced DLLs from being copied to the output folder -->
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
</Target>
<Target Name="Organize" AfterTargets="Publish">
<Target Name="Organize" AfterTargets="AfterBuild">
<!-- create Plugins folder and move plugin DLL/PDB inside -->
<MakeDir Directories="$(PublishDir)Plugins" />
<Move SourceFiles="$(PublishDir)$(TargetName).dll" DestinationFolder="$(PublishDir)Plugins" />
<Move SourceFiles="$(PublishDir)$(TargetName).pdb" DestinationFolder="$(PublishDir)Plugins" Condition="$(DebugType) == 'portable'" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PublishDir)Plugins" />
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb" DestinationFolder="$(PublishDir)Plugins" Condition="$(DebugType) == 'portable'" />

<!-- copy static files -->
<Copy SourceFiles="@(CopyToOutput)" DestinationFiles="@(CopyToOutput->'$(PublishDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<Target Name="CopyToBeatSaberFolder" AfterTargets="AfterBuild" Condition="$(AutomatedBuild) == 'false' and $(BeatSaberDir) != ''">
<Target Name="CopyToBeatSaberFolder" AfterTargets="AfterBuild" Condition="$(BeatSaberDir) != ''">
<Copy SourceFiles="@(CopyToBeatSaberFolder)" DestinationFiles="@(CopyToBeatSaberFolder->'$(BeatSaberDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public static bool Prefix(ref bool __result)
}
}

[HarmonyPatch(typeof(VRPlatformHelper))]
[HarmonyPatch(typeof(OpenVRHelper))]
[HarmonyPatch("TriggerHapticPulse", MethodType.Normal)]
internal class VRPlatformHelper_TriggerHapticPulse
internal class OpenVRHelper_TriggerHapticPulse
{
[HarmonyPriority(Priority.Last)]
public static bool Prefix(XRNode node, float strength)
Expand Down
27 changes: 19 additions & 8 deletions Source/DynamicOpenVR.BeatSaber/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using DynamicOpenVR.IO;
using HarmonyLib;
using IPA;
using IPA.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
Expand All @@ -48,7 +49,6 @@ internal class Plugin

private Harmony _harmonyInstance;

private VRPlatformHelper _vrPlatformHelper;
private OpenVRHelper _openVRHelper;

[Init]
Expand Down Expand Up @@ -113,38 +113,37 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (scene.name == "PCInit")
{
_vrPlatformHelper = Resources.FindObjectsOfTypeAll<VRPlatformHelper>().First();
_openVRHelper = (OpenVRHelper) typeof(VRPlatformHelper).GetField("_openVRHeper", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_vrPlatformHelper);
_openVRHelper = Resources.FindObjectsOfTypeAll<OpenVRHelper>().First();
}
}

private void OnOpenVREventTriggered(VREvent_t evt)
{
if (!_vrPlatformHelper || _openVRHelper == null) return;
if (_openVRHelper == null) return;

EVREventType eventType = (EVREventType)evt.eventType;

if (eventType == EVREventType.VREvent_InputFocusReleased && evt.data.process.pid == 0)
{
_vrPlatformHelper.HandleInputFocusWasReleased();
InvokeEvent(_openVRHelper, nameof(_openVRHelper.inputFocusWasReleasedEvent));
_openVRHelper.EnableEventSystem();
}

if (eventType == EVREventType.VREvent_InputFocusCaptured && evt.data.process.oldPid == 0)
{
_vrPlatformHelper.HandleInputFocusWasCaptured();
InvokeEvent(_openVRHelper, nameof(_openVRHelper.inputFocusWasCapturedEvent));
_openVRHelper.DisableEventSystem();
}

if (eventType == EVREventType.VREvent_DashboardActivated)
{
_vrPlatformHelper.HandleDashboardWasActivated();
InvokeEvent(_openVRHelper, nameof(_openVRHelper.inputFocusWasCapturedEvent));
_openVRHelper.DisableEventSystem();
}

if (eventType == EVREventType.VREvent_DashboardDeactivated)
{
_vrPlatformHelper.HandleDashboardWasDectivated();
InvokeEvent(_openVRHelper, nameof(_openVRHelper.inputFocusWasReleasedEvent));
_openVRHelper.EnableEventSystem();
}

Expand All @@ -154,6 +153,18 @@ private void OnOpenVREventTriggered(VREvent_t evt)
}
}

private void InvokeEvent<T>(T obj, string name, params object[] args)
{
var multicastDelegate = (MulticastDelegate)obj.GetType().GetField(name, BindingFlags.Public | BindingFlags.Instance).GetValue(obj);

if (multicastDelegate == null) return;

foreach (Delegate handler in multicastDelegate.GetInvocationList())
{
handler.Method.Invoke(handler.Target, args);
}
}

private void AddManifestToSteamConfig()
{
string steamFolder = SteamUtilities.GetSteamHomeDirectory();
Expand Down
4 changes: 2 additions & 2 deletions Source/DynamicOpenVR.BeatSaber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

[assembly: Guid("1a5be41d-60b4-4185-97c1-78c4a78354b5")]

[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.3.1.0")]
[assembly: AssemblyFileVersion("0.3.1.0")]
6 changes: 3 additions & 3 deletions Source/DynamicOpenVR.BeatSaber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"$schema": "https://raw.githubusercontent.com/nike4613/ModSaber-MetadataFileSchema/master/Schema.json",
"author": "nicoco007",
"description": "Adds support for action-based OpenVR bindings",
"gameVersion": "1.11.0",
"gameVersion": "1.12.1",
"id": "DynamicOpenVR.BeatSaber",
"name": "DynamicOpenVR.BeatSaber",
"icon": "DynamicOpenVR.BeatSaber.Resources.icon.png",
"version": "0.3.0+dev",
"version": "0.3.1+dev",
"features": [],
"dependsOn": {
"BSIPA": "^4.0.0",
"DynamicOpenVR": "^0.3.0"
"DynamicOpenVR": "^0.3.1"
},
"files": [
"DynamicOpenVR\\Actions\\beatsaber.json",
Expand Down
8 changes: 4 additions & 4 deletions Source/DynamicOpenVR/DynamicOpenVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
</Target>
<Target Name="Organize" AfterTargets="Publish">
<Target Name="Organize" AfterTargets="AfterBuild">
<!-- create Libs folder and move DLL/PDB inside -->
<MakeDir Directories="$(PublishDir)Libs" />
<Move SourceFiles="$(PublishDir)$(TargetName).dll" DestinationFolder="$(PublishDir)Libs" />
<Move SourceFiles="$(PublishDir)$(TargetName).pdb" DestinationFolder="$(PublishDir)Libs" Condition="$(DebugType) == 'portable'" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PublishDir)Libs" />
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb" DestinationFolder="$(PublishDir)Libs" Condition="$(DebugType) == 'portable'" />

<!-- copy static files -->
<Copy SourceFiles="@(CopyToOutput)" DestinationFiles="@(CopyToOutput->'$(PublishDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<Target Name="CopyToBeatSaberFolder" AfterTargets="Publish" Condition="$(AutomatedBuild) == 'false' and $(BeatSaberDir) != ''">
<Target Name="CopyToBeatSaberFolder" AfterTargets="AfterBuild" Condition="$(BeatSaberDir) != ''">
<Copy SourceFiles="@(CopyToBeatSaberFolder)" DestinationFiles="@(CopyToBeatSaberFolder->'$(BeatSaberDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
</Project>
4 changes: 2 additions & 2 deletions Source/DynamicOpenVR/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

[assembly: Guid("12b5ba1f-421f-4860-b27d-95a11a54e59d")]

[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.3.1.0")]
[assembly: AssemblyFileVersion("0.3.1.0")]

0 comments on commit 28f693a

Please sign in to comment.