Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzo committed Aug 24, 2024
1 parent b0a3fc9 commit ffe689d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
58 changes: 36 additions & 22 deletions projects/Bonelab/FlatPlayer/src/FlatBooter.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
using System;
using System.Reflection;
using HarmonyLib;
using MelonLoader;
using Unity.XR.MockHMD;
using UnityEngine;
using UnityEngine.XR.Management;
using UnityEngine.XR;
using Sst.Utilities;

#if PATCH5 && ML6
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Input;
using MarrowXrDevice = Il2CppSLZ.Marrow.Input.XRDevice;
#elif PATCH3 && ML5
using SLZ.Marrow.Input;
using SLZ.Marrow.Utilities;
using SLZ.Rig;
using System.Reflection;
using SLZ.Marrow.Warehouse;
using Sst.Utilities;
using SLZ.SaveData;
using MarrowXrDevice = SLZ.Marrow.Input.XRDevice;
#endif

namespace Sst.FlatPlayer;

public class FlatBooter : MelonMod {
private static Vector3 ORIGIN = new Vector3(0f, 1.76f, 0f);

public static FlatBooter Instance;

private FlatMode _flatMode;
Expand All @@ -40,36 +46,33 @@ public override void OnInitializeMelon() {

public override void OnUpdate() { _flatMode.OnUpdate(); }

public override void OnLateUpdate() {
_flatMode.UpdateHmd();
_flatMode.UpdateLeftController();
_flatMode.UpdateRightController();
}

[HarmonyPatch(typeof(HmdActionMap), nameof(HmdActionMap.Refresh))]
internal static class HmdActionMap_Refresh {
[HarmonyPrefix]
private static bool Prefix() {
Instance._flatMode.UpdateHmd();
return false;
}
private static bool Prefix() => false;
}

[HarmonyPatch(
typeof(ControllerActionMap), nameof(ControllerActionMap.Refresh)
)]
internal static class ControllerActionMap_Refresh {
[HarmonyPrefix]
private static bool Prefix(ControllerActionMap __instance) {
if (__instance.Equals(Instance._flatMode.LeftController)) {
Instance._flatMode.UpdateLeftController();
} else {
Instance._flatMode.UpdateRightController();
}
return false;
}
private static bool Prefix() => false;
}

[HarmonyPatch(typeof(OpenControllerRig), nameof(OpenControllerRig.OnAwake))]
internal static class OpenControllerAwake {
[HarmonyPrefix]
private static void Prefix(OpenControllerRig __instance) {
if (__instance.transform.parent.gameObject.name != "[RigManager (Blank)]")
return;
// if (__instance.transform.parent.gameObject.name != "[RigManager
// (Blank)]")
// return;

Instance._flatMode.Start();
}
Expand All @@ -79,8 +82,9 @@ private static void Prefix(OpenControllerRig __instance) {
internal static class OpenControllerDestroy {
[HarmonyPrefix]
private static void Prefix(OpenControllerRig __instance) {
if (__instance.transform.parent.gameObject.name == "[RigManager (Blank)]")
Instance._flatMode.Stop();
// if (__instance.transform.parent.gameObject.name == "[RigManager
// (Blank)]")
Instance._flatMode.Stop();
}
}

Expand All @@ -93,10 +97,16 @@ internal static class XRApi_InitializeXRLoader {

[HarmonyTargetMethod]
public static MethodBase TargetMethod() {
#if PATCH5 && ML6
return typeof(XRApi.__c__DisplayClass60_0)
.GetMethod(nameof(XRApi.__c__DisplayClass60_0._InitializeXRLoader_b__0
));
#elif PATCH3 && ML5
var xrApi = typeof(XRApi);
return xrApi.GetNestedType(STEAM_CLASS_NAME)
?.GetMethod(STEAM_METHOD_NAME) ??
xrApi.GetNestedType(OCULUS_CLASS_NAME)?.GetMethod(OCULUS_METHOD_NAME);
#endif
}

[HarmonyPrefix]
Expand All @@ -114,14 +124,18 @@ public static bool Prefix(ref bool __result) {
internal static class XRDevice_IsPresent {
[HarmonyPrefix]
private static bool Prefix(InputFeatureUsage<bool> usage, out bool value) {
#if PATCH5 && ML6
value = true;
#elif PATCH3 && ML5
value = usage.name == "UserPresence";
#endif
return false;
}
}

[HarmonyPatch(
typeof(SLZ.Marrow.Input.XRDevice),
nameof(SLZ.Marrow.Input.XRDevice.IsTracking), MethodType.Getter
typeof(MarrowXrDevice), nameof(MarrowXrDevice.IsTracking),
MethodType.Getter
)]
internal static class XRDevice_IsTracking {
[HarmonyPrefix]
Expand Down
17 changes: 17 additions & 0 deletions projects/Bonelab/FlatPlayer/src/FlatMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
using UnityEngine;
using UnityEngine.XR;

#if PATCH5 && ML6
using Il2CppSLZ.Marrow.Input;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.Marrow.Utilities;
using Il2CppSLZ.Bonelab.SaveData;
using Il2CppSLZ.Marrow.SaveData;
#elif PATCH3 && ML5
using SLZ.Marrow.Input;
using SLZ.Marrow.Warehouse;
using SLZ.Marrow.Utilities;
using SLZ.SaveData;
#endif

namespace Sst.Utilities;

Expand Down Expand Up @@ -140,6 +148,9 @@ public void ResetRotation() {
}

public void UpdateHmd() {
if (Hmd == null)
return;

var playerRotation =
Quaternion.AngleAxis(cameraLastRotation.x, Vector3.up) *
Quaternion.AngleAxis(cameraLastRotation.y, Vector3.left);
Expand All @@ -148,6 +159,9 @@ public void UpdateHmd() {
}

public void UpdateLeftController() {
if (LeftController == null)
return;

var moveDirection = Vector2.zero;
if (Input.GetKey(KeyCode.W))
moveDirection += Vector2.up;
Expand Down Expand Up @@ -185,6 +199,9 @@ public void UpdateLeftController() {
}

public void UpdateRightController() {
if (RightController == null)
return;

var stickAxis = Vector2.zero;
if (Input.GetKey(KeyCode.UpArrow))
stickAxis += Vector2.up;
Expand Down
4 changes: 2 additions & 2 deletions projects/Bonelab/ThirdPersonCamera/src/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class PlayerAvatarArt_DisableHair_Patch {
[HarmonyPrefix()]
internal static bool Prefix() {
Dbg.Log("PlayerAvatarArt_DisableHair_Patch");
return !Instance._thirdPersonCamera;
return false;
}
}

Expand All @@ -214,7 +214,7 @@ class PlayerAvatarArt_DisableHead_Patch {
[HarmonyPrefix()]
internal static bool Prefix() {
Dbg.Log("PlayerAvatarArt_DisableHead_Patch");
return !Instance._thirdPersonCamera;
return false;
}
}
}

0 comments on commit ffe689d

Please sign in to comment.