diff --git a/KK_VREnhancement/GUI/VREnhancementPlugin.Config.cs b/KK_VREnhancement/GUI/VREnhancementPlugin.Config.cs index e494167..4b2fdd3 100644 --- a/KK_VREnhancement/GUI/VREnhancementPlugin.Config.cs +++ b/KK_VREnhancement/GUI/VREnhancementPlugin.Config.cs @@ -5,7 +5,6 @@ namespace KK_VREnhancement { public partial class VRPlugin { - public static ConfigEntry MoveWithTalkScene { get; private set; } public static ConfigEntry EnableControllerColliders { get; private set; } public static ConfigEntry SqueezeToTurn { get; private set; } @@ -15,10 +14,6 @@ public partial class VRPlugin /// public void PluginConfigInit() { - MoveWithTalkScene = Config.Bind("VR General", "Enable move with scene", true, - "Will move the VR camera view in front of the heroine as they move around during TalkScene/HScene. This mimics the default KK behavior. \n\nWhen disabled, you stay put as the heroine moves around."); - MoveWithTalkScene.SettingChanged += MoveWithTalkScene_SettingsChanged; - EnableControllerColliders = Config.Bind("VR General", "Enable VR controller collision (boop!)", true, "Allows collision of VR controllers with all dynamic bones.\n\nBoop!"); EnableControllerColliders.SettingChanged += EnableControllerColliders_SettingsChanged; @@ -29,20 +24,6 @@ public void PluginConfigInit() } - internal void MoveWithTalkScene_SettingsChanged(object sender, System.EventArgs e) - { - if (!MoveWithTalkScene.Value) - { - VRCameraController.ClearLastPosition(); - VRCameraHooks.UnInitHooks(GUID + "_camera"); - } - else - { - VRCameraHooks.InitHooks(); - } - } - - internal void EnableControllerColliders_SettingsChanged(object sender, System.EventArgs e) { if (!EnableControllerColliders.Value) diff --git a/KK_VREnhancement/KK_VREnhancement.csproj b/KK_VREnhancement/KK_VREnhancement.csproj index c2cec6b..ec65815 100644 --- a/KK_VREnhancement/KK_VREnhancement.csproj +++ b/KK_VREnhancement/KK_VREnhancement.csproj @@ -81,15 +81,10 @@ - - - - - diff --git a/KK_VREnhancement/VRCamera.GameCustomFunctionController.cs b/KK_VREnhancement/VRCamera.GameCustomFunctionController.cs deleted file mode 100644 index 74ac561..0000000 --- a/KK_VREnhancement/VRCamera.GameCustomFunctionController.cs +++ /dev/null @@ -1,37 +0,0 @@ -using ActionGame; -using KKAPI.MainGame; - -namespace KK_VREnhancement -{ - public class VRCameraGameController : GameCustomFunctionController - { - protected override void OnDayChange(Cycle.Week day) - { - if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" OnDayChange {day}"); - VRCameraController.ClearLastPosition(); - } - - protected override void OnStartH(HSceneProc proc, bool freeH) - { - if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" OnStartH "); - VRCameraController.ClearLastPosition(); - } - - protected override void OnEndH(HSceneProc proc, bool freeH) - { - if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" OnEndH "); - VRCameraController.ClearLastPosition(); - } - - protected override void OnGameLoad(GameSaveLoadEventArgs args) - { - VRCameraController.OnGameLoad(); - } - - protected override void OnPeriodChange(Cycle.Type period) - { - if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" OnPeriodChange "); - VRCameraController.ClearLastPosition(); - } - } -} \ No newline at end of file diff --git a/KK_VREnhancement/VRCamera.Helper.cs b/KK_VREnhancement/VRCamera.Helper.cs deleted file mode 100644 index 9378b1b..0000000 --- a/KK_VREnhancement/VRCamera.Helper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using UnityEngine; - -namespace KK_VREnhancement -{ - public static class VRCameraHelper - { - //If the new position is 0, or < minDistance from the last position, the position hasn't changed - internal static Boolean IsNewPosition(Vector3 oldPosition, Vector3 newPosition, float minDistance = 0.3f) - { - if (oldPosition == null) return true; - bool notAtZero = Math.Abs(Vector3.Distance(newPosition, new Vector3(0, 0, 0))) > minDistance; - bool hasMoved = Math.Abs(Vector3.Distance(newPosition, oldPosition)) > minDistance; - - return (hasMoved && notAtZero); - } - - internal static Transform ConvertPositionToTransform(Vector3 position, Quaternion rotation) - { - //TODO does this add up over time? - GameObject camGameObject = new GameObject(); - Transform newTransform = camGameObject.transform; - newTransform.position = position; - newTransform.rotation = rotation; - - return newTransform; - } - } - -} \ No newline at end of file diff --git a/KK_VREnhancement/VRCamera.Hooks.cs b/KK_VREnhancement/VRCamera.Hooks.cs deleted file mode 100644 index d95f3f1..0000000 --- a/KK_VREnhancement/VRCamera.Hooks.cs +++ /dev/null @@ -1,133 +0,0 @@ -using HarmonyLib; -using UnityEngine; -using ADV; -using System.Collections.Generic; -using KKAPI.MainGame; - -namespace KK_VREnhancement -{ - public static class VRCameraHooks - { - public static Harmony harmonyInstance; - - internal static void InitHooks(Harmony _harmonyInstance = null) - { - if (_harmonyInstance != null) harmonyInstance = _harmonyInstance; - - if (harmonyInstance == null) return; - harmonyInstance.PatchAll(typeof(VRCameraHooks)); - } - - internal static void UnInitHooks(string harmonyGUID) - { - if (harmonyInstance == null) return; - harmonyInstance.UnpatchAll(harmonyGUID); - } - - // Implemented by KK_MainGameVR 0.9.0 - // //When the heroine changes location (ADVScene like Going to lunch, exercising, Date) - // [HarmonyPostfix] - // [HarmonyPatch(typeof(ADVScene), "Update")] - // internal static void ADVScene_Update(ADVScene __instance) - // { - // if (!VRPlugin.VREnabled || !VRPlugin.MoveWithTalkScene.Value) return; - - // MainScenario scenario = Traverse.Create(__instance).Field("scenario").GetValue(); - // if (scenario == null || scenario.commandController == null) return; - - // System.Collections.Generic.Dictionary characters = scenario.commandController.Characters; - // if (characters == null || characters.Count <= 0 || characters[0] == null) return; - - // //Get the main heroine (is it always at index 0, probably not)? - // ChaControl charCtrl = characters[0].chaCtrl; - // if (charCtrl == null || charCtrl.objHead == null) return; - - // //Gets heroines head position. Will place the user facing this position - // Transform heroineTransform = charCtrl.objHead.transform; - // if (heroineTransform == null) return; - - // VRCameraController.MoveToFaceHeroine_ADVScene(heroineTransform.position, heroineTransform.rotation); - // } - - //When the ADV scene (TalkScene) is done clear the last ADVScene position - [HarmonyPostfix] - [HarmonyPatch(typeof(TalkScene), "OnDestroy")] - internal static void TalkScene_OnDestroy(TalkScene __instance) - { - if (!VRPlugin.MoveWithTalkScene.Value) return; - if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" TalkScene_OnDestroy "); - - VRCameraController.ClearLastPosition(); - } - - //When heroine changes to a new location after user selects pink location pin (ActionScene, HScene) - [HarmonyPostfix] - [HarmonyPatch(typeof(HSceneProc), "SetLocalPosition", typeof(HSceneProc.AnimationListInfo))] - internal static void HSceneProc_SetLocalPosition(HSceneProc __instance) - { - if (!VRPlugin.VREnabled || !VRPlugin.MoveWithTalkScene.Value) return; - if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" SetLocalPosition "); - - List lstFemale = Traverse.Create(__instance).Field("lstFemale").GetValue>(); - if (lstFemale == null || lstFemale[0] == null) return; - - ChaControl female = lstFemale[0]; - if (female == null || female.objHead == null) return; - - //Gets heroines head position. Will place the user facing this position - Transform femaleTransform = female.objHead.transform; - if (femaleTransform == null) return; - - VRCameraController.MoveToFaceHeroine_HScene(femaleTransform.position, femaleTransform.rotation); - } - - - // /// - // /// Triggers when changing location in h scenes - // /// - // [HarmonyPostfix] - // [HarmonyPatch(typeof(HSceneProc), nameof(HSceneProc.ChangeCategory))] - // private static void HLocationChangeHook(List ___lstFemale) - // { - // try - // { - // var hsceneCenterPoint = ___lstFemale[0].transform.position; - // MobManager.GatherMobsAroundPoint(hsceneCenterPoint); - // } - // catch (Exception ex) - // { - // UnityEngine.Debug.LogException(ex); - // } - // } - - - // [HarmonyPostfix] - // [HarmonyPatch(typeof(ChaStatusScene), "Start")] - // private static void CreateButtons(ChaStatusScene __instance, ChaStatusComponent ___cmpMale) - - - // [HarmonyPrefix, HarmonyPatch(typeof(ChaControl), nameof(ChaControl.ChangeClothesShorts))] - // private static void ChangeClothesShorts(ChaControl __instance) => chaControl = __instance; - - // [HarmonyPostfix, HarmonyPatch(typeof(Info), "Init")] - // private static void InfoInit(Info __instance) => ActionGameInfoInstance = __instance; - - - // /// - // /// Something that happens at the end of H scene loading, good enough place to initialize stuff - // /// - // [HarmonyPrefix, HarmonyPatch(typeof(HSceneProc), "MapSameObjectDisable")] - // private static void MapSameObjectDisable(HSceneProc __instance) - // { - - - // /// - // /// Set the new original position when changing positions via the H point picker scene - // /// - // /// - // [HarmonyPostfix, HarmonyPatch(typeof(HSceneProc), "ChangeCategory")] - // private static void ChangeCategory(HSceneProc __instance) - // { - - } -} \ No newline at end of file diff --git a/KK_VREnhancement/VRCamera.cs b/KK_VREnhancement/VRCamera.cs deleted file mode 100644 index 30d1a17..0000000 --- a/KK_VREnhancement/VRCamera.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using UnityEngine; -using VRGIN.Helpers; -using VRGIN.Core; - -namespace KK_VREnhancement -{ - public static class VRCameraController - { - //To keep track of the last heroine location - internal static Vector3 lastIncommingPosition; - internal static Quaternion lastIncommingRotation; - - internal static void OnGameLoad() - { - } - - internal static void SetVRCamPosition(Transform advCam) - { - float y = advCam.position.y; - float y2 = VRCamera.Instance.SteamCam.head.position.y - 0.1f;//To match head height (plus a little extra) - Vector3 newPosition = new Vector3(advCam.position.x, y, advCam.position.z); - Vector3 steamCamPos = new Vector3(VRCamera.Instance.SteamCam.head.position.x, y2, VRCamera.Instance.SteamCam.head.position.z); - VRCamera.Instance.SteamCam.origin.position += newPosition - steamCamPos; - } - - internal static void SetVRCamRotation(Transform advCam, Boolean reverseRotate = false) - { - Vector3 forwardVector = Calculator.GetForwardVector(advCam.rotation); - Vector3 forwardVector2 = Calculator.GetForwardVector(VRCamera.Instance.SteamCam.head.rotation); - VRCamera.Instance.SteamCam.origin.rotation *= Quaternion.FromToRotation(forwardVector2, forwardVector); - - if (reverseRotate) - { - ReverseRotate(VRCamera.Instance.SteamCam.origin); - } - } - - // Move the VR view to a new position and rotation (In front of the heroine) - internal static void MoveToFaceHeroine_ADVScene(Vector3 position, Quaternion rotation) - { - //Only move VR view when distance is greater than x (meters?) Don't need to move VR view when heroine is just standing/sitting. - if (VRCameraHelper.IsNewPosition(lastIncommingPosition, position) == false) return; - - lastIncommingPosition = position; - lastIncommingRotation = rotation; - - Transform newTransform = VRCameraHelper.ConvertPositionToTransform(position, rotation); - - SetVRCamRotation(newTransform, true); - SetVRCamPosition(newTransform); - VRCamera.Instance.SteamCam.origin.Translate(new Vector3(-1f, 0f, 0f));//Make some personal space - } - - - // Move the VR view to a new position and rotation (In front of the heroine you are defiling) - internal static void MoveToFaceHeroine_HScene(Vector3 position, Quaternion rotation) - { - //Only move VR view when distance is greater than xf (meters?) Don't need to move VR view when heroine is just standing/sitting. - if (VRCameraHelper.IsNewPosition(VRCamera.Instance.SteamCam.origin.position, position, 2f) == false) return; - - lastIncommingPosition = position; - lastIncommingRotation = rotation; - - Transform actSceCamTransform = VRCameraHelper.ConvertPositionToTransform(position, rotation); - SetVRCamRotation(actSceCamTransform, true); - SetVRCamPosition(actSceCamTransform); - - //Move camera back from character, otherwise you get to see their insides :) - VRCamera.Instance.SteamCam.origin.Translate(new Vector3(-1f, 0f, 0f)); - } - - internal static void ReverseRotate(Transform camTransform) - { - camTransform.Rotate(Vector3.up * -180); - } - - internal static void ClearLastPosition() - { - lastIncommingPosition = new Vector3(); - lastIncommingRotation = new Quaternion(); - } - - - - - - - - - //****Test methods***** - //Move VR camera to a specific Vector3 position - internal static void MoveToPositionOnly(Vector3 position) - { - GameObject camGameObject = new GameObject(); - Transform newTransform = camGameObject.transform; - newTransform.position = position; - - if (VRCameraHelper.IsNewPosition(lastIncommingPosition, position) == false) return; - - SetVRCamPosition(newTransform); - } - - } -} \ No newline at end of file diff --git a/KK_VREnhancement/VRController.Collider.GameCustomFunctionController.cs b/KK_VREnhancement/VRController.Collider.GameCustomFunctionController.cs index e1455cd..98e3abe 100644 --- a/KK_VREnhancement/VRController.Collider.GameCustomFunctionController.cs +++ b/KK_VREnhancement/VRController.Collider.GameCustomFunctionController.cs @@ -10,7 +10,6 @@ protected override void OnGameLoad(GameSaveLoadEventArgs args) //Set up controller colliders when main game starts VRControllerColliderHelper.TriggerHelperCoroutine(); - VRControllerInput.OnGameLoad(); } } } \ No newline at end of file diff --git a/KK_VREnhancement/VRController.Input.cs b/KK_VREnhancement/VRController.Input.cs deleted file mode 100644 index 7b803af..0000000 --- a/KK_VREnhancement/VRController.Input.cs +++ /dev/null @@ -1,46 +0,0 @@ -using UnityEngine; -using Valve.VR; -using VRGIN.Core; -using VRGIN.Controls; - -namespace KK_VREnhancement -{ - public static class VRControllerInput - { - - internal static void OnGameLoad() - { - // //Make vr origin same as head position's x,z - // // VRCamera.Instance.SteamCam.head.position = new Vector3(VRCamera.Instance.SteamCam.head.position.x, VRCamera.Instance.SteamCam.origin.position.y , VRCamera.Instance.SteamCam.head.position.z); - // DebugTools.DrawSphereAndAttach(VRCamera.Instance.SteamCam.origin, 0.1f); - // DebugTools.DrawLineAndAttach(VRCamera.Instance.SteamCam.origin, 0.1f); - } - - /// - /// When user squeezes the grip, turn the camera via wrists angular veolcity - /// - internal static void CheckInputForSqueezeTurn() - { - if (VRPlugin.SqueezeToTurn == null || !VRPlugin.SqueezeToTurn.Value) return; - - //Right hand - var rCtrl = GameObject.FindObjectOfType(); - //Detect grip squeeze - if (rCtrl != null && rCtrl.Input.GetPress(EVRButtonId.k_EButton_Grip)) - { - var aVelocity = rCtrl.Input.angularVelocity; - //Turn head based on angular veolcity - VRCamera.Instance.SteamCam.origin.RotateAround(VRCamera.Instance.SteamCam.head.position, new Vector3(0, 1, 0), -(aVelocity.y * Time.deltaTime * 100)/4); - } - - var lCtrl = GameObject.FindObjectOfType(); - if (lCtrl != null && lCtrl.Input.GetPress(EVRButtonId.k_EButton_Grip)) - { - var aVelocity = lCtrl.Input.angularVelocity; - //Turn head based on angular veolcity - VRCamera.Instance.SteamCam.origin.RotateAround(VRCamera.Instance.SteamCam.head.position, new Vector3(0, 1, 0), -(aVelocity.y * Time.deltaTime * 100)/4); - } - - } - } -} \ No newline at end of file diff --git a/KK_VREnhancement/VREnhancementPlugin.cs b/KK_VREnhancement/VREnhancementPlugin.cs index 211a0d7..877e95c 100644 --- a/KK_VREnhancement/VREnhancementPlugin.cs +++ b/KK_VREnhancement/VREnhancementPlugin.cs @@ -42,22 +42,16 @@ internal void Start() if (!VREnabled) return; //Set up game mode detectors to start certain logic when loading into main game - GameAPI.RegisterExtraBehaviour(GUID + "_camera"); GameAPI.RegisterExtraBehaviour(GUID + "_controller"); //Harmony init. It's magic! - Harmony harmonyCamera = new Harmony(GUID + "_camera"); - Harmony harmonyController = new Harmony(GUID + "_controller"); - VRCameraHooks.InitHooks(harmonyCamera); - // VRControllerHooks.InitHooks(harmonyController); Implemented by KK_MainGameVR 0.9.0 } //Check for controller input changes internal void Update() { - //When the user squeezes the controller, apply hand rotation to headset - // VRControllerInput.CheckInputForSqueezeTurn(); Implemented by KK_MainGameVR 0.9.0 + } }