This commit is contained in:
NotAKidoS 2023-04-25 15:04:09 -05:00
parent dc577c3a2f
commit a468487850
24 changed files with 484 additions and 121 deletions

View file

@ -1,12 +1,15 @@
using ABI_RC.Core;
using ABI.CCK.Components;
using ABI_RC.Core;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using HarmonyLib;
using NAK.Melons.MenuScalePatch.Helpers;
using NAK.MenuScalePatch.Helpers;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
namespace NAK.Melons.MenuScalePatch.HarmonyPatches;
namespace NAK.MenuScalePatch.HarmonyPatches;
/**
ViewManager.SetScale runs once a second when it should only run when aspect ratio changes- CVR bug
@ -21,17 +24,10 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(PlayerSetup), "Start")]
private static void Postfix_PlayerSetup_Start()
{
try
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
MenuScalePatch.UpdateAllSettings();
QuickMenuHelper.Instance.CreateWorldAnchors();
MainMenuHelper.Instance.CreateWorldAnchors();
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
MenuScalePatch.UpdateSettings();
QuickMenuHelper.Instance.CreateWorldAnchors();
MainMenuHelper.Instance.CreateWorldAnchors();
}
[HarmonyPrefix]
@ -83,15 +79,8 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(CVR_MenuManager), "Start")]
private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref GameObject ____leftVrAnchor)
{
try
{
QuickMenuHelper helper = __instance.quickMenu.gameObject.AddComponent<QuickMenuHelper>();
helper.handAnchor = ____leftVrAnchor.transform;
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
QuickMenuHelper helper = __instance.quickMenu.gameObject.AddComponent<QuickMenuHelper>();
helper.handAnchor = ____leftVrAnchor.transform;
}
//Set MM stuff
@ -99,14 +88,7 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(ViewManager), "Start")]
private static void Postfix_ViewManager_Start(ref ViewManager __instance)
{
try
{
__instance.gameObject.AddComponent<MainMenuHelper>();
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
__instance.gameObject.AddComponent<MainMenuHelper>();
}
//hook quickmenu open/close
@ -178,13 +160,28 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(CVRTools), "ConfigureHudAffinity")]
private static void Postfix_CVRTools_ConfigureHudAffinity()
{
try
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
}
// prevents CVRWorld from closing menus when world transitioning, cause cool
[HarmonyTranspiler]
[HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.Start), MethodType.Enumerator)]
private static IEnumerable<CodeInstruction> Transpiler_CVRWorld_Start(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
var patchedInstructions = new CodeMatcher(instructions).MatchForward(false,
new CodeMatch(OpCodes.Ldsfld),
new CodeMatch(OpCodes.Ldc_I4_0),
new CodeMatch(i => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo { Name: "ForceUiStatus" }))
.RemoveInstructions(3)
.InstructionEnumeration();
patchedInstructions = new CodeMatcher(patchedInstructions).MatchForward(false,
new CodeMatch(OpCodes.Ldsfld),
new CodeMatch(OpCodes.Ldc_I4_0),
new CodeMatch(i => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo { Name: "ToggleQuickMenu" }))
.RemoveInstructions(3)
.InstructionEnumeration();
return patchedInstructions;
}
}

View file

@ -3,7 +3,7 @@ using ABI_RC.Core.Savior;
using UnityEngine;
namespace NAK.Melons.MenuScalePatch.Helpers;
namespace NAK.MenuScalePatch.Helpers;
//TODO: Implement desktop ratio scaling back to MM

View file

@ -2,7 +2,7 @@
using ABI_RC.Core.Savior;
using UnityEngine;
namespace NAK.Melons.MenuScalePatch.Helpers;
namespace NAK.MenuScalePatch.Helpers;
/**

View file

@ -2,10 +2,9 @@
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Savior;
using ABI_RC.Systems.MovementSystem;
using System.Reflection;
using UnityEngine;
namespace NAK.Melons.MenuScalePatch.Helpers;
namespace NAK.MenuScalePatch.Helpers;
public class MSP_MenuInfo
{
@ -25,21 +24,14 @@ public class MSP_MenuInfo
public static bool DisableMMHelper;
public static bool DisableMMHelper_VR;
//reflection
internal static readonly FieldInfo _desktopMouseModeQM = typeof(ViewManager).GetField("_desktopMouseMode", BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly FieldInfo _desktopMouseModeMM = typeof(CVR_MenuManager).GetField("_desktopMouseMode", BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly FieldInfo ms_followAngleX = typeof(MovementSystem).GetField("_followAngleX", BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly FieldInfo ms_followAngleY = typeof(MovementSystem).GetField("_followAngleY", BindingFlags.NonPublic | BindingFlags.Instance);
internal static readonly FieldInfo ms_manualAngleX = typeof(MovementSystem).GetField("_manualAngleX", BindingFlags.NonPublic | BindingFlags.Instance);
internal static bool isIndependentHeadTurn = false;
internal static void ToggleDesktopInputMethod(bool flag)
{
if (MetaPort.Instance.isUsingVr) return;
_desktopMouseModeQM.SetValue(ViewManager.Instance, flag);
_desktopMouseModeMM.SetValue(CVR_MenuManager.Instance, flag);
ViewManager.Instance._desktopMouseMode = flag;
CVR_MenuManager.Instance._desktopMouseMode = flag;
RootLogic.Instance.ToggleMouse(flag);
CVRInputManager.Instance.inputEnabled = !flag;
@ -59,9 +51,9 @@ public class MSP_MenuInfo
}
else if (!isPressed && isIndependentHeadTurn)
{
float angleX = (float)ms_followAngleX.GetValue(MovementSystem.Instance);
float angleY = (float)ms_followAngleY.GetValue(MovementSystem.Instance);
float manualAngleX = (float)ms_manualAngleX.GetValue(MovementSystem.Instance);
float angleX = MovementSystem.Instance._followAngleX;
float angleY = MovementSystem.Instance._followAngleY;
float manualAngleX = MovementSystem.Instance._manualAngleX;
if (angleY == 0f && angleX == manualAngleX)
{
isIndependentHeadTurn = false;

View file

@ -1,35 +1,29 @@
using MelonLoader;
using NAK.Melons.MenuScalePatch.Helpers;
namespace NAK.Melons.MenuScalePatch;
namespace NAK.MenuScalePatch;
public class MenuScalePatch : MelonMod
{
internal static MelonLogger.Instance Logger;
internal static MelonPreferences_Category m_categoryMenuScalePatch;
internal static MelonPreferences_Entry<bool>
//m_entryWorldAnchorVRQM,
m_entryUseIndependentHeadTurn,
m_entryPlayerAnchorMenus;
internal static MelonPreferences_Category Category = MelonPreferences.CreateCategory(nameof(MenuScalePatch));
internal static MelonPreferences_Entry<bool> EntryUseIndependentHeadTurn =
Category.CreateEntry<bool>("Use Independent Head Turn", true, description: "Should you be able to use independent head turn in a menu while in Desktop?");
internal static MelonPreferences_Entry<bool> EntryPlayerAnchorMenus =
Category.CreateEntry<bool>("Player Anchor Menus", true, description: "Should the menus be anchored to & constantly follow the player?");
public override void OnInitializeMelon()
{
m_categoryMenuScalePatch = MelonPreferences.CreateCategory(nameof(MenuScalePatch));
//m_entryWorldAnchorVRQM = m_categoryMenuScalePatch.CreateEntry<bool>("World Anchor VR QM", false, description: "Should place QM in World Space while VR.");
m_entryUseIndependentHeadTurn = m_categoryMenuScalePatch.CreateEntry<bool>("Use Independent Head Turn", true, description: "Should you be able to use independent head turn in a menu while in Desktop?");
m_entryPlayerAnchorMenus = m_categoryMenuScalePatch.CreateEntry<bool>("Player Anchor Menus", true, description: "Should the menus be anchored to & constantly follow the player?");
foreach (var setting in m_categoryMenuScalePatch.Entries)
foreach (var setting in Category.Entries)
{
setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
}
}
Logger = LoggerInstance;
}
internal static void UpdateAllSettings()
internal static void UpdateSettings()
{
//MSP_MenuInfo.WorldAnchorQM = m_entryWorldAnchorVRQM.Value;
MSP_MenuInfo.UseIndependentHeadTurn = m_entryUseIndependentHeadTurn.Value;
MSP_MenuInfo.PlayerAnchorMenus = m_entryPlayerAnchorMenus.Value;
Helpers.MSP_MenuInfo.UseIndependentHeadTurn = EntryUseIndependentHeadTurn.Value;
Helpers.MSP_MenuInfo.PlayerAnchorMenus = EntryPlayerAnchorMenus.Value;
}
private static void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();
private static void OnUpdateSettings(object arg1, object arg2) => UpdateSettings();
}

View file

@ -6,29 +6,30 @@
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
<HintPath>..\_ManagedLibs\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>..\_ManagedLibs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Cohtml.Runtime">
<HintPath>C:\Program Files (x86)\\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll</HintPath>
<HintPath>..\_ManagedLibs\Cohtml.Runtime.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
<HintPath>..\_ManagedLibs\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>C:\Program Files (x86)\\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
<HintPath>..\_ManagedLibs\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\_ManagedLibs\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
<HintPath>..\_ManagedLibs\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
</ItemGroup>

View file

@ -1,30 +1,30 @@
using MelonLoader;
using NAK.Melons.MenuScalePatch.Properties;
using NAK.MenuScalePatch.Properties;
using System.Reflection;
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyTitle(nameof(NAK.Melons.MenuScalePatch))]
[assembly: AssemblyTitle(nameof(NAK.MenuScalePatch))]
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
[assembly: AssemblyProduct(nameof(NAK.Melons.MenuScalePatch))]
[assembly: AssemblyProduct(nameof(NAK.MenuScalePatch))]
[assembly: MelonInfo(
typeof(NAK.Melons.MenuScalePatch.MenuScalePatch),
nameof(NAK.Melons.MenuScalePatch),
typeof(NAK.MenuScalePatch.MenuScalePatch),
nameof(NAK.MenuScalePatch),
AssemblyInfoParams.Version,
AssemblyInfoParams.Author,
downloadLink: "https://github.com/NotAKidOnSteam/MenuScalePatch"
downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods"
)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
namespace NAK.Melons.MenuScalePatch.Properties;
namespace NAK.MenuScalePatch.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "4.2.6";
public const string Version = "4.2.7";
public const string Author = "NotAKidoS";
}

View file

@ -1,7 +1,7 @@
{
"_id": 95,
"name": "MenuScalePatch",
"modversion": "4.2.6",
"modversion": "4.2.7",
"gameversion": "2022r170",
"loaderversion": "0.5.7",
"modtype": "Mod",
@ -16,8 +16,8 @@
"requirements": [
"None"
],
"downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/v4.2.6/MenuScalePatch.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/MenuScalePatch/",
"changelog": "- Fixed hitching & potential crash when opening menu after a long time of it being closed. Don't disable CohtmlView, only enable it.\n- Let game update menu position while its closed.\n- Tweaked independent head turn handling to ensure menu is correctly positioned on recenter if PlayerAnchorMenus is disabled.\n- Undo change to which transform to parent menu anchors.",
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r2/MenuScalePatch.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/",
"changelog": "- Menus are no longer forced closed on world load.",
"embedcolor": "363020"
}