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

@ -183,6 +183,7 @@ internal class DesktopVRIKSystem : MonoBehaviour
// Last Movement Parent Info
Vector3 _movementPosition;
Quaternion _movementRotation;
CVRMovementParent _currentParent;
DesktopVRIKSystem()
{
@ -377,14 +378,19 @@ internal class DesktopVRIKSystem : MonoBehaviour
// desktop pivots from playerlocal transform
var platformPivot = transform.position;
// Prevent targeting other parent position
if (_currentParent == currentParent)
{
// Add platform motion to IK solver
avatarIKSolver.AddPlatformMotion(deltaPosition, deltaRotation, platformPivot);
ResetDesktopVRIK();
}
// Store for next frame
_currentParent = currentParent;
_movementPosition = currentPosition;
_movementRotation = currentRotation;
ResetDesktopVRIK();
return true;
}

View file

@ -1,6 +1,7 @@
using ABI_RC.Core.Player;
using HarmonyLib;
using UnityEngine;
using ABI.CCK.Components;
/**

View file

@ -26,6 +26,6 @@ using System.Reflection;
namespace NAK.Melons.DesktopVRIK.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "4.1.7";
public const string Version = "4.1.8";
public const string Author = "NotAKidoS";
}

View file

@ -1,7 +1,7 @@
{
"_id": 117,
"name": "DesktopVRIK",
"modversion": "4.1.7",
"modversion": "4.1.8",
"gameversion": "2022r170",
"loaderversion": "0.5.7",
"modtype": "Mod",
@ -17,8 +17,8 @@
"requirements": [
"BTKUILib"
],
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r1/DesktopVRIK.dll",
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r2/DesktopVRIK.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/",
"changelog": "- Enable useAnimatedBendNormal when Locomotion tracking is disabled. This fixes some sitting animations that bend at unnatural angles.\n- Fix avatar root offset not being reset when entering/playing emotes.",
"changelog": "- Fixed feet targeting previous movement parent position for a frame.",
"embedcolor": "9b59b6"
}

View file

@ -7,7 +7,7 @@ using HarmonyLib;
using RootMotion.FinalIK;
using UnityEngine;
namespace NAK.Melons.IKFixes.HarmonyPatches;
namespace NAK.IKFixes.HarmonyPatches;
internal static class BodySystemPatches
{
@ -213,6 +213,7 @@ internal static class VRIKPatches
internal static class PlayerSetupPatches
{
// Last Movement Parent Info
static CVRMovementParent lastMovementParent;
static Vector3 lastMovementPosition;
static Quaternion lastMovementRotation;
@ -234,10 +235,15 @@ internal static class PlayerSetupPatches
Vector3 deltaPosition = currentPosition - lastMovementPosition;
Quaternion deltaRotation = Quaternion.Inverse(lastMovementRotation) * currentRotation;
// Prevent targeting other parent position
if (lastMovementParent == currentParent || lastMovementParent == null)
{
// Add platform motion to IK solver
IKSystem.vrik.solver.AddPlatformMotion(deltaPosition, deltaRotation, currentPosition);
}
// Store for next frame
lastMovementParent = currentParent;
lastMovementPosition = currentPosition;
lastMovementRotation = currentRotation;
return false;

View file

@ -1,6 +1,6 @@
using MelonLoader;
namespace NAK.Melons.IKFixes;
namespace NAK.IKFixes;
public class IKFixes : MelonMod
{

View file

@ -1,17 +1,17 @@
using MelonLoader;
using NAK.Melons.IKFixes.Properties;
using NAK.IKFixes.Properties;
using System.Reflection;
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyTitle(nameof(NAK.Melons.IKFixes))]
[assembly: AssemblyTitle(nameof(NAK.IKFixes))]
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
[assembly: AssemblyProduct(nameof(NAK.Melons.IKFixes))]
[assembly: AssemblyProduct(nameof(NAK.IKFixes))]
[assembly: MelonInfo(
typeof(NAK.Melons.IKFixes.IKFixes),
nameof(NAK.Melons.IKFixes),
typeof(NAK.IKFixes.IKFixes),
nameof(NAK.IKFixes),
AssemblyInfoParams.Version,
AssemblyInfoParams.Author,
downloadLink: "https://github.com/NotAKidOnSteam/IKFixes"
@ -22,9 +22,9 @@ using System.Reflection;
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
[assembly: HarmonyDontPatchAll]
namespace NAK.Melons.IKFixes.Properties;
namespace NAK.IKFixes.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "1.0.2";
public const string Version = "1.0.3";
public const string Author = "NotAKidoS";
}

View file

@ -1,7 +1,7 @@
{
"_id": 142,
"name": "IKFixes",
"modversion": "1.0.2",
"modversion": "1.0.3",
"gameversion": "2022r170",
"loaderversion": "0.5.7",
"modtype": "Mod",
@ -16,8 +16,8 @@
"requirements": [
"None"
],
"downloadlink": "https://github.com/NotAKidOnSteam/IKFixes/releases/download/v1.0.2/IKFixes.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/IKFixes/",
"changelog": "- Initial Release\n- Added FakeRootAngle fix for Halfbody. Feet will no longer only point in the direction of head while looking around/turning. This can be disabled in mod settings.",
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r2/IKFixes.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/",
"changelog": "- Fixed feet targeting previous movement parent position for a frame.",
"embedcolor": "f46e49"
}

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
@ -20,19 +23,12 @@ internal class HarmonyPatches
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), "Start")]
private static void Postfix_PlayerSetup_Start()
{
try
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
MenuScalePatch.UpdateAllSettings();
MenuScalePatch.UpdateSettings();
QuickMenuHelper.Instance.CreateWorldAnchors();
MainMenuHelper.Instance.CreateWorldAnchors();
}
catch (System.Exception e)
{
MenuScalePatch.Logger.Error(e);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CVR_MenuManager), "SetScale")]
@ -82,32 +78,18 @@ internal class HarmonyPatches
[HarmonyPostfix]
[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);
}
}
//Set MM stuff
[HarmonyPostfix]
[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);
}
}
//hook quickmenu open/close
[HarmonyPrefix]
@ -177,14 +159,29 @@ internal class HarmonyPatches
[HarmonyPostfix]
[HarmonyPatch(typeof(CVRTools), "ConfigureHudAffinity")]
private static void Postfix_CVRTools_ConfigureHudAffinity()
{
try
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
}
catch (System.Exception e)
// 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)
{
MenuScalePatch.Logger.Error(e);
}
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"
}

View file

@ -1,5 +1,6 @@
using ABI.CCK.Components;
using UnityEngine;
using ABI_RC.Core.Player;
namespace NAK.CCK.CustomComponents;
@ -16,6 +17,7 @@ public class NAKPointerTracker : MonoBehaviour
public string parameterName;
// Internal stuff
bool isLocal;
float initialAngle;
CVRPointer trackedPointer;
@ -46,6 +48,7 @@ public class NAKPointerTracker : MonoBehaviour
Vector3 direction = (transform.TransformPoint(offset) - referenceTransform.position);
Vector3 projectedDirection = Vector3.ProjectOnPlane(direction, referenceTransform.up);
initialAngle = Vector3.SignedAngle(referenceTransform.forward, projectedDirection, referenceTransform.up);
isLocal = gameObject.layer == 8;
}
void OnDrawGizmosSelected()
@ -88,8 +91,13 @@ public class NAKPointerTracker : MonoBehaviour
{
if (animator != null)
{
float angle = GetAngleFromPosition(trackedPointer.transform.position, initialAngle);
animator.SetFloat(parameterName + "_Angle", angle / 360);
float angle = GetAngleFromPosition(trackedPointer.transform.position, initialAngle) / 360;
if (!isLocal)
{
animator.SetFloat(parameterName + "_Angle", angle);
return;
}
PlayerSetup.Instance.changeAnimatorParam(parameterName + "_Angle", angle);
}
}

View file

@ -9,7 +9,7 @@ public class CustomComponents : MelonMod
public override void OnInitializeMelon()
{
// Add our CCK component to the prop whitelist
var propWhitelist = SharedFilter._spawnableWhitelist;
var propWhitelist = SharedFilter._avatarWhitelist;
propWhitelist.Add(typeof(NAKPointerTracker));
}
}

182
ThirdPerson/CameraLogic.cs Normal file
View file

@ -0,0 +1,182 @@
using ABI_RC.Core.Base;
using ABI_RC.Core.Player;
using ABI_RC.Core.Util.Object_Behaviour;
using Aura2API;
using BeautifyEffect;
using System.Collections;
using System.Reflection;
using UnityEngine;
using UnityEngine.AzureSky;
using UnityEngine.Rendering.PostProcessing;
namespace ThirdPerson;
internal static class CameraLogic
{
private static float _dist;
private static GameObject _ourCam;
private static GameObject _desktopCam;
private static CameraFovClone _cameraFovClone;
internal static CameraLocation CurrentLocation = CameraLocation.Default;
internal enum CameraLocation
{
Default,
FrontView,
RightSide,
LeftSide
}
private static bool _state;
internal static bool State
{
get => _state;
set
{
_state = value;
_ourCam.SetActive(_state);
}
}
private static bool _setupPostProcessing;
private static readonly FieldInfo _ppResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_Resources", BindingFlags.NonPublic | BindingFlags.Instance);
private static readonly FieldInfo _ppOldResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_OldResources", BindingFlags.NonPublic | BindingFlags.Instance);
internal static IEnumerator SetupCamera()
{
yield return new WaitUntil(() => PlayerSetup.Instance);
_ourCam = new GameObject("ThirdPersonCameraObj") { };
_ourCam.AddComponent<Camera>();
_cameraFovClone = _ourCam.AddComponent<CameraFovClone>();
_desktopCam = PlayerSetup.Instance.desktopCamera;
_cameraFovClone.targetCamera = _desktopCam.GetComponent<Camera>();
_ourCam.transform.SetParent(_desktopCam.transform);
RelocateCam(CameraLocation.Default);
_ourCam.gameObject.SetActive(false);
ThirdPerson.Logger.Msg("Finished setting up third person camera.");
}
internal static void CopyFromPlayerCam()
{
Camera ourCamComponent = _ourCam.GetComponent<Camera>();
Camera playerCamComponent = _desktopCam.GetComponent<Camera>();
if (ourCamComponent == null || playerCamComponent == null) return;
ThirdPerson.Logger.Msg("Copying active camera settings & components.");
//steal basic settings
ourCamComponent.farClipPlane = playerCamComponent.farClipPlane;
ourCamComponent.nearClipPlane = playerCamComponent.nearClipPlane;
ourCamComponent.cullingMask = playerCamComponent.cullingMask;
ourCamComponent.depthTextureMode = playerCamComponent.depthTextureMode;
//steal post processing if added
PostProcessLayer ppLayerPlayerCam = playerCamComponent.GetComponent<PostProcessLayer>();
PostProcessLayer ppLayerThirdPerson = ourCamComponent.AddComponentIfMissing<PostProcessLayer>();
if (ppLayerPlayerCam != null && ppLayerThirdPerson != null)
{
ppLayerThirdPerson.enabled = ppLayerPlayerCam.enabled;
ppLayerThirdPerson.volumeLayer = ppLayerPlayerCam.volumeLayer;
//need to copy these via reflection, otherwise post processing will error
if (!_setupPostProcessing)
{
_setupPostProcessing = true;
PostProcessResources resources = (PostProcessResources)_ppResourcesFieldInfo.GetValue(ppLayerPlayerCam);
PostProcessResources oldResources = (PostProcessResources)_ppOldResourcesFieldInfo.GetValue(ppLayerPlayerCam);
_ppResourcesFieldInfo.SetValue(ppLayerThirdPerson, resources);
_ppResourcesFieldInfo.SetValue(ppLayerThirdPerson, oldResources);
}
}
//what even is this aura camera stuff
AuraCamera auraPlayerCam = playerCamComponent.GetComponent<AuraCamera>();
AuraCamera auraThirdPerson = ourCamComponent.AddComponentIfMissing<AuraCamera>();
if (auraPlayerCam != null && auraThirdPerson != null)
{
auraThirdPerson.enabled = auraPlayerCam.enabled;
auraThirdPerson.frustumSettings = auraPlayerCam.frustumSettings;
}
else
{
auraThirdPerson.enabled = false;
}
//flare layer thing? the sun :_:_:_:_:_:
FlareLayer flarePlayerCam = playerCamComponent.GetComponent<FlareLayer>();
FlareLayer flareThirdPerson = ourCamComponent.AddComponentIfMissing<FlareLayer>();
if (flarePlayerCam != null && flareThirdPerson != null)
{
flareThirdPerson.enabled = flarePlayerCam.enabled;
}
else
{
flareThirdPerson.enabled = false;
}
//and now what the fuck is fog scattering
AzureFogScattering azureFogPlayerCam = playerCamComponent.GetComponent<AzureFogScattering>();
AzureFogScattering azureFogThirdPerson = ourCamComponent.AddComponentIfMissing<AzureFogScattering>();
if (azureFogPlayerCam != null && azureFogThirdPerson != null)
{
azureFogThirdPerson.fogScatteringMaterial = azureFogPlayerCam.fogScatteringMaterial;
}
else
{
Object.Destroy(ourCamComponent.GetComponent<AzureFogScattering>());
}
//why is there so many thingsssssssss
Beautify beautifyPlayerCam = playerCamComponent.GetComponent<Beautify>();
Beautify beautifyThirdPerson = ourCamComponent.AddComponentIfMissing<Beautify>();
if (beautifyPlayerCam != null && beautifyThirdPerson != null)
{
beautifyThirdPerson.quality = beautifyPlayerCam.quality;
beautifyThirdPerson.profile = beautifyPlayerCam.profile;
}
else
{
Object.Destroy(ourCamComponent.gameObject.GetComponent<Beautify>());
}
}
internal static void RelocateCam(CameraLocation location, bool resetDist = false)
{
_ourCam.transform.rotation = _desktopCam.transform.rotation;
if (resetDist) ResetDist();
switch (location)
{
case CameraLocation.FrontView:
_ourCam.transform.localPosition = new Vector3(0, 0.015f, 0.55f + _dist);
_ourCam.transform.localRotation = new Quaternion(0, 180, 0, 0);
CurrentLocation = CameraLocation.FrontView;
break;
case CameraLocation.RightSide:
_ourCam.transform.localPosition = new Vector3(0.3f, 0.015f, -0.55f + _dist);
_ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0);
CurrentLocation = CameraLocation.RightSide;
break;
case CameraLocation.LeftSide:
_ourCam.transform.localPosition = new Vector3(-0.3f, 0.015f, -0.55f + _dist);
_ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0);
CurrentLocation = CameraLocation.LeftSide;
break;
case CameraLocation.Default:
default:
_ourCam.transform.localPosition = new Vector3(0, 0.015f, -0.55f + _dist);
_ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0);
CurrentLocation = CameraLocation.Default;
break;
}
}
private static void ResetDist() => _dist = 0;
internal static void IncrementDist() { _dist += 0.25f; RelocateCam(CurrentLocation); }
internal static void DecrementDist() { _dist -= 0.25f; RelocateCam(CurrentLocation); }
}

27
ThirdPerson/Patches.cs Normal file
View file

@ -0,0 +1,27 @@
using ABI.CCK.Components;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using MelonLoader;
using System.Linq;
using System.Reflection;
using static ThirdPerson.CameraLogic;
namespace ThirdPerson;
internal static class Patches
{
internal static void Apply(HarmonyLib.Harmony harmony)
{
harmony.Patch(
typeof(CVRWorld).GetMethod("SetDefaultCamValues", BindingFlags.NonPublic | BindingFlags.Instance),
postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod()
);
harmony.Patch(
typeof(CVRWorld).GetMethod("CopyRefCamValues", BindingFlags.NonPublic | BindingFlags.Instance),
postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod()
);
}
//Copy camera settings & postprocessing components
private static void OnWorldStart() => CopyFromPlayerCam();
}

View file

@ -0,0 +1,48 @@
using MelonLoader;
using System;
using System.Reflection;
using UnityEngine;
using static ThirdPerson.CameraLogic;
using BuildInfo = ThirdPerson.BuildInfo;
[assembly: AssemblyCopyright("Created by " + BuildInfo.Author)]
[assembly: MelonInfo(typeof(ThirdPerson.ThirdPerson), BuildInfo.Name, BuildInfo.Version, BuildInfo.Author)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
namespace ThirdPerson;
public static class BuildInfo
{
public const string Name = "ThirdPerson";
public const string Author = "Davi & NotAKidoS";
public const string Version = "1.0.1";
}
public class ThirdPerson : MelonMod
{
internal static MelonLogger.Instance Logger;
public override void OnInitializeMelon()
{
Logger = LoggerInstance;
MelonCoroutines.Start(SetupCamera());
Patches.Apply(HarmonyInstance);
}
public override void OnUpdate()
{
if (State)
{
if (Input.GetAxis("Mouse ScrollWheel") > 0f) IncrementDist();
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) DecrementDist();
}
if (!Input.GetKey(KeyCode.LeftControl)) return;
if (Input.GetKeyDown(KeyCode.T)) State = !State;
if (!State || !Input.GetKeyDown(KeyCode.Y)) return;
RelocateCam((CameraLocation)(((int)CurrentLocation + 1) % Enum.GetValues(typeof(CameraLocation)).Length), true);
}
}

View file

@ -0,0 +1,54 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<CVRReferences>true</CVRReferences>
<CopyToMods>true</CopyToMods>
<LangVersion>latest</LangVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\_ManagedLibs\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\_ManagedLibs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\_ManagedLibs\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Aura2_Core">
<HintPath>..\_ManagedLibs\Aura2_Core.dll</HintPath>
</Reference>
<Reference Include="Cohtml.Runtime">
<HintPath>..\_ManagedLibs\Cohtml.Runtime.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>..\_ManagedLibs\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="Unity.Postprocessing.Runtime">
<HintPath>..\_ManagedLibs\Unity.Postprocessing.Runtime.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\_ManagedLibs\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>..\_ManagedLibs\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\_ManagedLibs\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\_ManagedLibs\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\_ManagedLibs\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="Deploy" AfterTargets="Build">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" />
<Message Text="Copied $(TargetPath) to C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" Importance="high" />
</Target>
</Project>

View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThirdPerson", "ThirdPerson.csproj", "{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B44A1184-3AC9-4ABD-8603-6B13ECDA5CA9}
EndGlobalSection
EndGlobal

22
ThirdPerson/format.json Normal file
View file

@ -0,0 +1,22 @@
[
{
"_id": 16,
"name": "ThirdPerson",
"modversion": "1.0.1",
"gameversion": "2022r170",
"loaderversion": "0.5.7",
"modtype": "Mod",
"author": "Davi & NotAKidoS",
"description": "Allows you to go into third person view by pressing Ctrl + T to toggle and Ctrl + Y to change the mode",
"searchtags": [
"third person view",
"3rd person",
"third person"
],
"requirements": [],
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/tag/r2/ThirdPerson.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/",
"changelog": "- Made thirdperson camera parent to Desktop camera instead of active camera.\n- Copy postprocessing settings from player camera on world start.\n - This fixed HUD rendering twice in thirdperson due to game update.\n- Added CameraFovClone component to copy zoom from desktop camera.\n- Removed logic that disabled thirdperson when opening a menu, as Game UI renders on top anyways.",
"embedcolor": "F61961"
}
]