i want no life

This commit is contained in:
NotAKidoS 2023-02-02 22:25:35 -06:00
parent 73bbc2a7c5
commit 5d4b7e354a
8 changed files with 208 additions and 62 deletions

View file

@ -3,6 +3,8 @@ using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using HarmonyLib;
using NAK.Melons.MenuScalePatch.Helpers;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
namespace NAK.Melons.MenuScalePatch.HarmonyPatches;
@ -20,43 +22,64 @@ namespace NAK.Melons.MenuScalePatch.HarmonyPatches;
[HarmonyPatch]
internal class HarmonyPatches
{
//stuff needed on start
[HarmonyPostfix]
[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);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CVR_MenuManager), "SetScale")]
private static void Prefix_CVR_MenuManager_SetScale(float avatarHeight, ref float ____scaleFactor, out bool __runOriginal)
private static bool Prefix_CVR_MenuManager_SetScale(float avatarHeight, ref float ____scaleFactor)
{
____scaleFactor = avatarHeight / 1.8f;
if (MetaPort.Instance.isUsingVr) ____scaleFactor *= 0.5f;
MSP_MenuInfo.ScaleFactor = ____scaleFactor;
__runOriginal = false;
if (!MSP_MenuInfo.PlayerAnchorMenus)
{
QuickMenuHelper.Instance.NeedsPositionUpdate = true;
MainMenuHelper.Instance.NeedsPositionUpdate = true;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ViewManager), "SetScale")]
private static void Prefix_ViewManager_SetScale(out bool __runOriginal)
private static bool Prefix_ViewManager_SetScale()
{
//bitch
__runOriginal = false;
return false;
}
//nuke UpdateMenuPosition methods
//there are 2 Jobs calling this each second, which is fucking my shit
[HarmonyPrefix]
[HarmonyPatch(typeof(CVR_MenuManager), "UpdateMenuPosition")]
private static void Prefix_CVR_MenuManager_UpdateMenuPosition(out bool __runOriginal)
private static bool Prefix_CVR_MenuManager_UpdateMenuPosition()
{
//fuck u
__runOriginal = false;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ViewManager), "UpdateMenuPosition")]
private static void Prefix_ViewManager_UpdateMenuPosition(ref float ___cachedScreenAspectRatio, out bool __runOriginal)
private static bool Prefix_ViewManager_UpdateMenuPosition(ref float ___cachedScreenAspectRatio)
{
//this is called once a second, so ill fix their dumb aspect ratio shit
float ratio = (float)Screen.width / (float)Screen.height;
float clamp = Mathf.Clamp(ratio, 0f, 1.8f);
MSP_MenuInfo.AspectRatio = 1.7777779f / clamp;
__runOriginal = false;
return false;
}
//Set QM stuff
@ -64,8 +87,16 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(CVR_MenuManager), "Start")]
private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref GameObject ____leftVrAnchor)
{
QuickMenuHelper helper = __instance.quickMenu.gameObject.AddComponent<QuickMenuHelper>();
helper.handAnchor = ____leftVrAnchor.transform;
try
{
QuickMenuHelper helper = __instance.quickMenu.gameObject.AddComponent<QuickMenuHelper>();
helper.handAnchor = ____leftVrAnchor.transform;
helper.enabled = false;
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
}
//Set MM stuff
@ -73,35 +104,71 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(ViewManager), "Start")]
private static void Postfix_ViewManager_Start(ref ViewManager __instance)
{
__instance.gameObject.AddComponent<MainMenuHelper>();
try
{
MainMenuHelper helper = __instance.gameObject.AddComponent<MainMenuHelper>();
helper.enabled = false;
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
}
//hook quickmenu open/close
[HarmonyPrefix]
[HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })]
private static void Prefix_CVR_MenuManager_ToggleQuickMenu(bool show, ref bool ____quickMenuOpen)
private static bool Prefix_CVR_MenuManager_ToggleQuickMenu(bool show, ref CVR_MenuManager __instance, ref bool ____quickMenuOpen)
{
if (QuickMenuHelper.Instance == null) return;
if (QuickMenuHelper.Instance == null) return true;
if (show != ____quickMenuOpen)
{
QuickMenuHelper.Instance.UpdateWorldAnchors();
____quickMenuOpen = show;
__instance.quickMenu.enabled = show;
__instance.quickMenuAnimator.SetBool("Open", show);
QuickMenuHelper.Instance.enabled = show;
QuickMenuHelper.Instance.UpdateWorldAnchors(show);
//shouldnt run if switching menus on desktop
if (!MetaPort.Instance.isUsingVr)
{
if (!show && MainMenuHelper.Instance.enabled)
{
return false;
}
ViewManager.Instance.UiStateToggle(false);
}
MSP_MenuInfo.ToggleDesktopInputMethod(show);
CVRPlayerManager.Instance.ReloadAllNameplates();
}
QuickMenuHelper.Instance.enabled = show;
return false;
}
//hook menu open/close
[HarmonyPrefix]
[HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })]
private static void Postfix_ViewManager_UiStateToggle(bool show, ref bool ____gameMenuOpen)
private static bool Postfix_ViewManager_UiStateToggle(bool show, ref ViewManager __instance, ref bool ____gameMenuOpen)
{
if (MainMenuHelper.Instance == null) return;
if (MainMenuHelper.Instance == null) return true;
if (show != ____gameMenuOpen)
{
MainMenuHelper.Instance.UpdateWorldAnchors();
____gameMenuOpen = show;
__instance.gameMenuView.enabled = show;
__instance.uiMenuAnimator.SetBool("Open", show);
MainMenuHelper.Instance.enabled = show;
MainMenuHelper.Instance.UpdateWorldAnchors(show);
//shouldnt run if switching menus on desktop
if (!MetaPort.Instance.isUsingVr)
{
if (!show && QuickMenuHelper.Instance.enabled)
{
return false;
}
CVR_MenuManager.Instance.ToggleQuickMenu(false);
}
MSP_MenuInfo.ToggleDesktopInputMethod(show);
CVRPlayerManager.Instance.ReloadAllNameplates();
}
MainMenuHelper.Instance.enabled = show;
return false;
}
//add independent head movement to important input
@ -117,6 +184,57 @@ internal class HarmonyPatches
[HarmonyPatch(typeof(PlayerSetup), "CalibrateAvatar")]
private static void Postfix_PlayerSetup_CalibrateAvatar()
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
try
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
}
//[HarmonyTranspiler]
//[HarmonyPatch(typeof(ControllerRay), "LateUpdate")]
private static IEnumerable<CodeInstruction> Transpiler_ControllerRay_UpdateInput(
IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
// Stop calling move mouse events on the menus, the ones that instantiate and the send the event (easy)
// Makes this: "component.View.MouseEvent(mouseEventData1);" go POOF
instructions = new CodeMatcher(instructions)
.MatchForward(false,
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(i => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo { Name: "get_View" }),
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(i => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo { Name: "MouseEvent" }))
.Repeat(matcher => matcher
.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop))
.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop))
.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop))
.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop))
)
.InstructionEnumeration();
// Look for the if flag2 and replace flag 2 with false, for the ones that create the event and send inline (hard ;_;)
// Makes this: "if (flag2 && this._mouseDownOnMenu != ControllerRay.Menu.None || ..." into:
// this: "if (false && this._mouseDownOnMenu != ControllerRay.Menu.None || ..."
instructions = new CodeMatcher(instructions)
.MatchForward(false,
new CodeMatch(OpCodes.Ldloc_2),
new CodeMatch(OpCodes.Brfalse),
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(i =>
i.opcode == OpCodes.Ldfld && i.operand is FieldInfo { Name: "_mouseDownOnMenu" }),
new CodeMatch(OpCodes.Brtrue),
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(i =>
i.opcode == OpCodes.Ldfld && i.operand is FieldInfo { Name: "_mouseDownOnMenu" }),
new CodeMatch(OpCodes.Ldc_I4_1),
new CodeMatch(OpCodes.Bne_Un))
.SetOpcodeAndAdvance(OpCodes.Ldc_I4_0) // replace flag2 with false
.InstructionEnumeration();
return instructions;
}
}