diff --git a/PlaySpaceScaleFix/HarmonyPatches.cs b/PlaySpaceScaleFix/HarmonyPatches.cs new file mode 100644 index 0000000..81e5cbe --- /dev/null +++ b/PlaySpaceScaleFix/HarmonyPatches.cs @@ -0,0 +1,41 @@ +using ABI_RC.Core.Player; +using ABI_RC.Systems.IK; +using HarmonyLib; +using UnityEngine; + +namespace NAK.PlaySpaceScaleFix.HarmonyPatches; + +class PlayerSetupPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))] + private static void Prefix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state) + { + __state = __instance.vrCamera.transform.position; + __state.y = __instance.transform.position.y; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))] + private static void Postfix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance, ref Vector3 __state) + { + if (!PlaySpaceScaleFix.EntryEnabled.Value) + return; + + Vector3 newPosition = __instance.vrCamera.transform.position; + newPosition.y = __instance.transform.position.y; + + Vector3 offset = __state + newPosition; + + // Offset _PlayerLocal to keep player in place + __instance.transform.position += offset; + + // TODO: Figure out why VRIK is wonky still + if (IKSystem.vrik != null) + { + IKSystem.vrik.solver.locomotion.AddDeltaPosition(offset); + IKSystem.vrik.solver.raycastOriginPelvis += offset; + IKSystem.vrik.transform.position += offset; + } + } +} \ No newline at end of file diff --git a/PlaySpaceScaleFix/Main.cs b/PlaySpaceScaleFix/Main.cs new file mode 100644 index 0000000..c5b328a --- /dev/null +++ b/PlaySpaceScaleFix/Main.cs @@ -0,0 +1,30 @@ +using MelonLoader; + +namespace NAK.PlaySpaceScaleFix; + +public class PlaySpaceScaleFix : MelonMod +{ + public static readonly MelonPreferences_Category Category = + MelonPreferences.CreateCategory(nameof(PlaySpaceScaleFix)); + + public static readonly MelonPreferences_Entry EntryEnabled = + Category.CreateEntry("Enabled", true, description: "Toggle PlaySpaceScaleFix entirely."); + + public override void OnInitializeMelon() + { + ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); + } + + void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } + } +} \ No newline at end of file diff --git a/PlaySpaceScaleFix/PlaySpaceScaleFix.csproj b/PlaySpaceScaleFix/PlaySpaceScaleFix.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/PlaySpaceScaleFix/PlaySpaceScaleFix.csproj @@ -0,0 +1,2 @@ + + diff --git a/PlaySpaceScaleFix/Properties/AssemblyInfo.cs b/PlaySpaceScaleFix/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..44b0844 --- /dev/null +++ b/PlaySpaceScaleFix/Properties/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using MelonLoader; +using NAK.PlaySpaceScaleFix.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.PlaySpaceScaleFix))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.PlaySpaceScaleFix))] + +[assembly: MelonInfo( + typeof(NAK.PlaySpaceScaleFix.PlaySpaceScaleFix), + nameof(NAK.PlaySpaceScaleFix), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/PlaySpaceScaleFix" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: MelonColor(255, 241, 200, 82)] +[assembly: MelonAuthorColor(255, 114, 17, 25)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.PlaySpaceScaleFix.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.0"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/PlaySpaceScaleFix/format.json b/PlaySpaceScaleFix/format.json new file mode 100644 index 0000000..e2144fb --- /dev/null +++ b/PlaySpaceScaleFix/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "PlaySpaceScaleFix", + "modversion": "1.0.0", + "gameversion": "2022r170p1", + "loaderversion": "0.6.1", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Fixes the issue where the player in VR is incorrectly positioned relative to the center of the playspace when adjusting playspace scales.\n\nEnsures that scaling and switching avatars no longer result in unusual offsets.", + "searchtags": [ + "scale", + "play", + "space", + "offset" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r4/PlaySpaceScaleFix.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/PlaySpaceScaleFix/", + "changelog": "- Initial Release", + "embedcolor": "#e56597" +} \ No newline at end of file