Skip to content

Commit

Permalink
Fixed VR Issue. (I shouldn't code while tired)
Browse files Browse the repository at this point in the history
  • Loading branch information
gompocp committed Mar 26, 2021
1 parent 1e2128a commit 6140fbe
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 272 deletions.
447 changes: 224 additions & 223 deletions ActionMenuApi/Tools.cs → ActionMenuApi/AMAPI.cs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions ActionMenuApi/ActionMenuApi.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using System.Diagnostics;
using Harmony;
using MelonLoader;

using MelonLoader;
using ActionMenuApi.Managers;
using UnityEngine;

namespace ActionMenuApi
{
internal static class ModInfo
{
public const string Name = "ActionMenuApi";
public const string Author = "gompo#6956";
public const string Version = "1.0.0";
public const string Author = "gompo";
public const string Version = "0.1.0";
public const string DownloadLink = null;
}

public class ActionMenuApi : MelonMod
{
private static MelonMod Instance;
public static HarmonyInstance HarmonyInstance => Instance.Harmony;
public override void OnApplicationStart()
{
Instance = this;
Patches.PatchAll();
RadialPuppetManager.Setup();
FourAxisPuppetManager.Setup();
Expand All @@ -29,6 +25,10 @@ public override void OnUpdate()
{
RadialPuppetManager.OnUpdate();
FourAxisPuppetManager.OnUpdate();
if (Input.GetKey(KeyCode.P))
{
MelonLogger.Msg(Utilities.GetCursorPosRight().ToString());
}
}
}
}
2 changes: 1 addition & 1 deletion ActionMenuApi/ActionMenuApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Compile Include="Managers\RadialPuppetManager.cs" />
<Compile Include="Pedals\PedalFourAxis.cs" />
<Compile Include="Pedals\PedalToggle.cs" />
<Compile Include="Tools.cs" />
<Compile Include="AMAPI.cs" />
<Compile Include="Patches.cs" />
<Compile Include="Pedals\PedalButton.cs" />
<Compile Include="Pedals\PedalRadial.cs" />
Expand Down
55 changes: 28 additions & 27 deletions ActionMenuApi/Managers/FourAxisPuppetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MelonLoader;
using UnityEngine;

namespace ActionMenuApi
namespace ActionMenuApi.Managers
{
public static class FourAxisPuppetManager
{
Expand Down Expand Up @@ -40,49 +40,50 @@ public static void OnUpdate()
{
if (hand == ActionMenuHand.Right)
{
if (Input.GetKeyUp(InputAxes.RightTrigger))
if (Input.GetAxis(InputAxes.RightTrigger) >= 0.4)
{
CloseFourAxisMenu();
return;
}
}
else if (hand == ActionMenuHand.Left)
{
if (Input.GetKeyUp(InputAxes.LeftTrigger))
if (Input.GetAxis(InputAxes.LeftTrigger) >= 0.4)
{
CloseFourAxisMenu();
return;
}
}
}
else if (Input.GetMouseButton(0))
{
CloseFourAxisMenu();
return;
}
else

try
{
try
{
current.Method_Private_Void_Vector2_Boolean_1(fourAxisPuppetValue, false);
}catch {}
fourAxisPuppetValue = ((hand == ActionMenuHand.Left) ? Utilities.GetCursorPosLeft() : Utilities.GetCursorPosRight())/ 16;
float x = fourAxisPuppetValue.x;
float y = fourAxisPuppetValue.y;
if (x >= 0) {
current.GetFillLeft().SetAlpha(0);
current.GetFillRight().SetAlpha(x);
}else {
current.GetFillLeft().SetAlpha(Math.Abs(x));
current.GetFillRight().SetAlpha(0);
}
if (y >= 0) {
current.GetFillDown().SetAlpha(0);
current.GetFillUp().SetAlpha(y);
}else {
current.GetFillDown().SetAlpha(Math.Abs(y));
current.GetFillUp().SetAlpha(0);
}
UpdateMathStuff();
onUpdate.Invoke(fourAxisPuppetValue);
current.Method_Private_Void_Vector2_Boolean_1(fourAxisPuppetValue, false);
}catch {}
fourAxisPuppetValue = ((hand == ActionMenuHand.Left) ? Utilities.GetCursorPosLeft() : Utilities.GetCursorPosRight())/ 16;
float x = fourAxisPuppetValue.x;
float y = fourAxisPuppetValue.y;
if (x >= 0) {
current.GetFillLeft().SetAlpha(0);
current.GetFillRight().SetAlpha(x);
}else {
current.GetFillLeft().SetAlpha(Math.Abs(x));
current.GetFillRight().SetAlpha(0);
}
if (y >= 0) {
current.GetFillDown().SetAlpha(0);
current.GetFillUp().SetAlpha(y);
}else {
current.GetFillDown().SetAlpha(Math.Abs(y));
current.GetFillUp().SetAlpha(0);
}
UpdateMathStuff();
onUpdate.Invoke(fourAxisPuppetValue);
}
}
public static void OpenFourAxisMenu(Vector2 startingValue, Action<Vector2> close, string title, Action<Vector2> update)
Expand Down
19 changes: 10 additions & 9 deletions ActionMenuApi/Managers/RadialPuppetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MelonLoader;
using UnityEngine;

namespace ActionMenuApi
namespace ActionMenuApi.Managers
{
internal static class RadialPuppetManager
{
Expand Down Expand Up @@ -42,29 +42,30 @@ public static void OnUpdate()
{
if (hand == ActionMenuHand.Right)
{
if (Input.GetKeyUp(InputAxes.RightTrigger))
if (Input.GetAxis(InputAxes.RightTrigger) >= 0.4)
{
CloseRadialMenu();
return;
}
}
else if (hand == ActionMenuHand.Left)
{
if (Input.GetKeyUp(InputAxes.LeftTrigger))
if (Input.GetAxis(InputAxes.LeftTrigger) >= 0.4)
{
CloseRadialMenu();
return;
}
}
}
else if (Input.GetMouseButton(0))
{
CloseRadialMenu();
return;
}
else
{
UpdateMathStuff();
radialPuppetValue = (current.GetFill().field_Public_Single_3 / 360) * 100;
if(onUpdate != null) onUpdate.Invoke(radialPuppetValue);
}

UpdateMathStuff();
radialPuppetValue = (current.GetFill().field_Public_Single_3 / 360) * 100;
if(onUpdate != null) onUpdate.Invoke(radialPuppetValue);
}
}

Expand Down
14 changes: 14 additions & 0 deletions ActionMenuApi/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,23 @@ public static List<PedalStruct>
private static readonly List<string> openNameplatesVisibilityPageKeyWords = new (new [] { "Nameplates Shown", "Icons Only", "Nameplates Hidden" });
private static readonly List<string> openNameplatesSizePageKeyWords = new (new [] { "Large", "Medium", "Normal", "Small", "Tiny" });
private static readonly List<string> openMenuSizePageKeyWords = new (new [] { "XXXXXXXXX" }); // No strings found :( Unusable for now. Scanning for methods doesnt help either as there are other functions that yield similar results
unsafe static private void ApplyPatches()
{
var CollideTarget = *(IntPtr*)(IntPtr)typeof(DynamicBoneCollider).GetField("NativeMethodInfoPtr_Method_Public_Void_byref_Vector3_Single_0", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
MelonUtils.NativeHookAttach((IntPtr)(&CollideTarget), Marshal.GetFunctionPointerForDelegate(new Action<IntPtr, IntPtr, IntPtr>(OnCollide)));
collideDelegate = Marshal.GetDelegateForFunctionPointer<CollideDelegate>(CollideTarget);
}

public delegate void CollideDelegate(IntPtr instance, IntPtr particlePosition, IntPtr particleRadius);
public static CollideDelegate collideDelegate;

unsafe static private void OnCollide(IntPtr instance, IntPtr particlePosition, IntPtr particleRadius)
{
collideDelegate(instance, particlePosition, particleRadius); // Error happens here
}
public static void PatchAll()
{
ApplyPatches();
try {
unsafe
{
Expand Down
2 changes: 1 addition & 1 deletion ActionMenuApi/Pedals/PedalFourAxis.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using MelonLoader;
using ActionMenuApi.Managers;
using UnityEngine;

namespace ActionMenuApi.Pedals
Expand Down
2 changes: 1 addition & 1 deletion ActionMenuApi/Pedals/PedalRadial.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Experimental.PlayerLoop;
using ActionMenuApi.Managers;

namespace ActionMenuApi.Pedals
{
Expand Down
1 change: 1 addition & 0 deletions ActionMenuApi/Stuff/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static void AddPedalsInList(List<PedalStruct> list, ActionMenu instance)

public static double ConvertFromDegToEuler(double angle)
{
//TODO: Rewrite/Remove Unnecessary Addition/Subtraction
if (angle >= 0 && angle <= 90) return 90 - angle;
if (angle > 90 && angle <= 180) return 360 - (angle - 90);
if (angle <= -90 && angle >= -180) return 270 - (angle + 180);
Expand Down
2 changes: 1 addition & 1 deletion ActionMenuApi/Types/ActionMenuPageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum ActionMenuPageType
SDK2Expression,
Main,
MenuOpacity,
MenuSize,
MenuSize, //Not Implemented
Nameplates,
NameplatesOpacity,
NameplatesVisibilty,
Expand Down

0 comments on commit 6140fbe

Please sign in to comment.