diff --git a/NomaiVR/DebugCheats.cs b/NomaiVR/DebugCheats.cs index c7ca06e..3c56c8e 100644 --- a/NomaiVR/DebugCheats.cs +++ b/NomaiVR/DebugCheats.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System.Linq; +using UnityEngine; using Valve.VR; namespace NomaiVR @@ -19,13 +20,14 @@ namespace NomaiVR // Wake up in dream (requires invincibility). if (SteamVR_Actions.default_Interact.stateDown) { + var workingLantern = FindObjectsOfType().Where(x => x._lanternType == DreamLanternType.Functioning).FirstOrDefault(); var dreamWorldController = FindObjectOfType(); dreamWorldController._dreamCampfire = FindObjectOfType(); dreamWorldController._dreamArrivalPoint = FindObjectOfType(); dreamWorldController._relativeSleepLocation = new RelativeLocationData(new Vector3(0f, 1f, -2f), Quaternion.identity, Vector3.zero); - dreamWorldController._playerLantern = FindObjectOfType(); + dreamWorldController._playerLantern = workingLantern; dreamWorldController._enteringDream = true; - FindObjectOfType().MoveItemToCarrySocket(FindObjectOfType()); + FindObjectOfType().MoveItemToCarrySocket(workingLantern); } // Start mind projection. diff --git a/NomaiVR/EffectFixes/DreamFix.cs b/NomaiVR/EffectFixes/DreamFix.cs index ac86396..85b250c 100644 --- a/NomaiVR/EffectFixes/DreamFix.cs +++ b/NomaiVR/EffectFixes/DreamFix.cs @@ -10,6 +10,7 @@ namespace NomaiVR.EffectFixes protected override OWScene[] Scenes => PlayableScenes; private static float prePauseFovFactor = 1; private static bool isPaused; + internal static Material totemEyeMaterial; public class Patch : NomaiVRPatch { @@ -38,6 +39,9 @@ namespace NomaiVR.EffectFixes Postfix(nameof(SimulationCamera.DeallocateRenderTex), nameof(Post_SimulationCamera_DeallocateRenderTex)); Prefix(nameof(SimulationCamera.AllocateRenderTex), nameof(Pre_SimulationCamera_AllocateRenderTex)); Prefix(nameof(SimulationCamera.VerifyRenderTexResolution), nameof(Pre_SimulationCamera_VerifyRenderTexResolution)); + + //Hand materials + Postfix(nameof(AlarmTotem.Start), nameof(Post_AlarmTotem_Start)); } public static void DisableScreenSpaceReflections(PostProcessingGameplaySettings __instance) @@ -158,6 +162,7 @@ namespace NomaiVR.EffectFixes if (__instance._targetCamera != null && __instance._targetCamera.mainCamera.stereoEnabled) { __instance.GetComponentInChildren().enabled = true; + GraphicsHelper.SetCameraEyeProjectionMatrix(__instance._camera, Valve.VR.EVREye.Eye_Left); } GlobalMessenger.FireEvent("SimulationEnter"); @@ -179,7 +184,7 @@ namespace NomaiVR.EffectFixes { return; } - GraphicsHelper.ForceCameraToEye(__instance._camera, __instance._targetCamera.mainCamera, Valve.VR.EVREye.Eye_Left); + GraphicsHelper.ForceCameraToEye(__instance._camera, __instance._targetCamera.mainCamera.transform, Valve.VR.EVREye.Eye_Left); } private static void Pre_SimulationCamera_VerifyRenderTexResolution(SimulationCamera __instance) @@ -196,6 +201,12 @@ namespace NomaiVR.EffectFixes { __instance.GetComponentInChildren().DeallocateTexture(); } + + private static void Post_AlarmTotem_Start(AlarmTotem __instance) + { + if (totemEyeMaterial == null) + totemEyeMaterial = new Material(__instance._origSimEyeMaterial); + } } } } diff --git a/NomaiVR/Hands/Hand.cs b/NomaiVR/Hands/Hand.cs index 718c84f..8740098 100644 --- a/NomaiVR/Hands/Hand.cs +++ b/NomaiVR/Hands/Hand.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Linq; using NomaiVR.Assets; +using NomaiVR.EffectFixes; using NomaiVR.Helpers; using NomaiVR.ReusableBehaviours; using NomaiVR.Tools; @@ -33,6 +34,8 @@ namespace NomaiVR.Hands private Renderer handRenderer; private Renderer gloveRenderer; + private Material[] originalHandMaterials; + private Material[] originalGloveMaterials; private EHandState handState = EHandState.Free; private EHandState lastHandState = EHandState.Free; private NomaiVRHandSkeleton skeleton; @@ -130,16 +133,32 @@ namespace NomaiVR.Hands { handRenderer.gameObject.layer = LayerMask.NameToLayer("DreamSimulation"); gloveRenderer.gameObject.layer = LayerMask.NameToLayer("DreamSimulation"); - SetUpShaders(handRenderer, "Outer Wilds/Environment/Invisible Planet/Cyberspace", "Outer Wilds/Environment/Invisible Planet/Cyberspace"); - SetUpShaders(gloveRenderer, "Outer Wilds/Environment/Invisible Planet/Cyberspace"); + + if(originalHandMaterials == null) + originalHandMaterials = handRenderer.sharedMaterials; + if (originalGloveMaterials == null) + originalGloveMaterials = gloveRenderer.sharedMaterials; + + handRenderer.sharedMaterials = MakeSimulationMaterials(originalHandMaterials.Length); + gloveRenderer.sharedMaterials = MakeSimulationMaterials(originalGloveMaterials.Length); + } + + private Material[] MakeSimulationMaterials(int size) + { + Material[] mats = new Material[size]; + for (int i = 0; i < mats.Length; i++) + mats[i] = DreamFix.totemEyeMaterial; + return mats; } private void OnSimulationExit() { handRenderer.gameObject.layer = LayerMask.NameToLayer("Default"); gloveRenderer.gameObject.layer = LayerMask.NameToLayer("Default"); - SetUpShaders(handRenderer, "Outer Wilds/Character/Skin", "Outer Wilds/Character/Skin"); - SetUpShaders(gloveRenderer, "Outer Wilds/Character/Clothes"); + handRenderer.sharedMaterials = originalHandMaterials; + gloveRenderer.sharedMaterials = originalGloveMaterials; + originalHandMaterials = null; + originalGloveMaterials = null; } private void SetUpShaders(Renderer renderer, params string[] shader) diff --git a/NomaiVR/Helpers/GraphicsHelper.cs b/NomaiVR/Helpers/GraphicsHelper.cs index bae12ff..f4f8500 100644 --- a/NomaiVR/Helpers/GraphicsHelper.cs +++ b/NomaiVR/Helpers/GraphicsHelper.cs @@ -5,11 +5,16 @@ namespace NomaiVR.Helpers { public static class GraphicsHelper { - public static void ForceCameraToEye(Camera targetCamera, Camera monoCamera, EVREye eye) + private static readonly Matrix4x4 scaleBiasDXToGL = Matrix4x4.TRS(Vector3.back, Quaternion.identity, new Vector3(1, 1, 2)); + public static void ForceCameraToEye(Camera targetCamera, Transform headTransform, EVREye eye) { - targetCamera.transform.position = monoCamera.transform.TransformPoint(SteamVR.instance.eyes[(int)eye].pos); - targetCamera.transform.rotation = monoCamera.transform.rotation * SteamVR.instance.eyes[(int)eye].rot; - targetCamera.projectionMatrix = GetSteamVREyeProjection(monoCamera, eye); + targetCamera.transform.position = headTransform.TransformPoint(SteamVR.instance.eyes[(int)eye].pos); + targetCamera.transform.rotation = headTransform.rotation * SteamVR.instance.eyes[(int)eye].rot; + } + + public static void SetCameraEyeProjectionMatrix(Camera targetCamera, EVREye eye) + { + targetCamera.projectionMatrix = scaleBiasDXToGL * GetSteamVREyeProjection(targetCamera, eye); } public static Matrix4x4 GetSteamVREyeProjection(Camera cam, EVREye eye) diff --git a/NomaiVR/NomaiVR.cs b/NomaiVR/NomaiVR.cs index 86cdc20..2f6800e 100644 --- a/NomaiVR/NomaiVR.cs +++ b/NomaiVR/NomaiVR.cs @@ -66,6 +66,11 @@ namespace NomaiVR new VirtualKeyboard(); new Menus(); new FixProbeCannonVisibility(); + + //Load UnityExplorer if enabled +#if UNITYEXPLORER + UnityExplorer.ExplorerStandalone.CreateInstance(); +#endif } private static void InitSteamVR() diff --git a/NomaiVR/NomaiVR.csproj b/NomaiVR/NomaiVR.csproj index bd9a6ac..9cfa776 100644 --- a/NomaiVR/NomaiVR.csproj +++ b/NomaiVR/NomaiVR.csproj @@ -57,8 +57,8 @@ false - - $(GameDir)\OuterWilds_Data\Managed\netstandard.dll + + $(OwmlDir)\$(ModDir)\UnityExplorer.STANDALONE.Mono.dll False diff --git a/NomaiVR/ReusableBehaviours/Dream/SupportSimulationCamera.cs b/NomaiVR/ReusableBehaviours/Dream/SupportSimulationCamera.cs index 66e619b..8d96c8f 100644 --- a/NomaiVR/ReusableBehaviours/Dream/SupportSimulationCamera.cs +++ b/NomaiVR/ReusableBehaviours/Dream/SupportSimulationCamera.cs @@ -46,6 +46,7 @@ namespace NomaiVR.ReusableBehaviours.Dream private void OnEnable() { camera.enabled = true; + GraphicsHelper.SetCameraEyeProjectionMatrix(camera, Valve.VR.EVREye.Eye_Right); } private void OnDisable() @@ -97,7 +98,7 @@ namespace NomaiVR.ReusableBehaviours.Dream private void OnPreRender() { if (simulationCamera == null || simulationCamera._targetCamera == null) return; - GraphicsHelper.ForceCameraToEye(camera, simulationCamera._targetCamera.mainCamera, Valve.VR.EVREye.Eye_Right); + GraphicsHelper.ForceCameraToEye(camera, simulationCamera._targetCamera.mainCamera.transform, Valve.VR.EVREye.Eye_Right); } } } \ No newline at end of file diff --git a/NomaiVRPatcher/NomaiVREnabler.cs b/NomaiVRPatcher/NomaiVREnabler.cs index 5b39ec6..a42af26 100644 --- a/NomaiVRPatcher/NomaiVREnabler.cs +++ b/NomaiVRPatcher/NomaiVREnabler.cs @@ -110,11 +110,13 @@ namespace NomaiVRPatcher var replacers = new List(); + #if !UNITYEXPLORER var playerSettings = assetsFileTable.GetAssetInfo(1); var playerSettingsBase = assetsManager.GetTypeInstance(assetsFile, playerSettings).GetBaseField(); var disableOldInputManagerSupport = playerSettingsBase.Get("enableNativePlatformBackendsForNewInputSystem"); disableOldInputManagerSupport.value = new AssetTypeValue(EnumValueTypes.ValueType_Bool, false); replacers.Add(new AssetsReplacerFromMemory(0, playerSettings.index, (int)playerSettings.curFileType, 0xffff, playerSettingsBase.WriteToByteArray())); + #endif var buildSettings = assetsFileTable.GetAssetInfo(11);