Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hefty rework/extra features/fixes #53

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 15 additions & 1 deletion CharaStudioVR/CharaStudioVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8</LangVersion>
<LangVersion>Preview</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>embedded</DebugType>
Expand All @@ -36,6 +36,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8</LangVersion>
<DebugSymbols>true</DebugSymbols>
<LangVersion>Preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.9.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -66,6 +67,12 @@
<HintPath>..\packages\ExtensibleSaveFormat.KoikatsuSunshine.16.8.1\lib\net46\KKS_ExtensibleSaveFormat.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="KK_FinalIK">
<HintPath>..\..\KK_SensibleH\Libs\KK_FinalIK.dll</HintPath>
</Reference>
<Reference Include="Obi">
<HintPath>..\Libs\Obi.dll</HintPath>
</Reference>
<Reference Include="Sirenix.Serialization, Version=2.1.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IllusionLibs.KoikatsuSunshine.UnityEngine.CoreModule.2019.4.9\lib\net46\Sirenix.Serialization.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -184,6 +191,11 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\BetterMenuTool.cs" />
<Compile Include="Controls\BetterWarpTool.cs" />
<Compile Include="Features\VRBoop.cs" />
<Compile Include="Fixes\OpenVRHelperTempfixHook.cs" />
<Compile Include="Fixes\TopmostToolIcons.cs" />
<Compile Include="Settings\CharaStudioContext.cs" />
<Compile Include="Settings\StudioSettings.cs" />
<Compile Include="StudioStandingMode.cs" />
Expand All @@ -204,6 +216,8 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Util\ColorZOrderShader" />
<None Include="Fixes\topmostgui.shader" />
<None Include="Fixes\topmostguishader" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@
using VRGIN.Visuals;
using Object = UnityEngine.Object;

namespace KKS_VR.Controls

namespace KK_VR.Controls
{
/// <summary>
/// MenuTool that supports right clicks by pressing the trackpad
/// </summary>
internal class BetterMenuTool : MenuTool
{
public override List<HelpText> GetHelpTexts()
{
return new List<HelpText>(new[]
{
ToolUtil.HelpTrackpadCenter(Owner, "Press to Right Click"),
ToolUtil.HelpTrackpadUp(Owner, "Slide to Move Cursor"),
ToolUtil.HelpTrigger(Owner, "Left Click"),
ToolUtil.HelpGrip(Owner, "Take/release screen")
}.Where(x => x != null));
}
//public override List<HelpText> GetHelpTexts()
//{
// return new List<HelpText>(new[]
// {
// ToolUtil.HelpTrackpadCenter(Owner, "Press to Right Click"),
// ToolUtil.HelpTrackpadUp(Owner, "Slide to Move Cursor"),
// ToolUtil.HelpTrigger(Owner, "Left Click"),
// ToolUtil.HelpGrip(Owner, "Take/release screen")
// }.Where(x => x != null));
//}

#region Override base functionality to add right clicks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using VRGIN.Controls;
using VRGIN.Controls.Tools;

namespace KKS_VR.Controls

// MainGame doesn't have warp tool no more.
namespace KK_VR.Controls
{
/// <summary>
/// WarpTool version that cancels teleporting when user tries grab moving
Expand All @@ -32,13 +34,13 @@ protected override void OnUpdate()
base.OnUpdate();
}

public override List<HelpText> GetHelpTexts()
{
return new List<HelpText>(new[]
{
ToolUtil.HelpTrackpadCenter(Owner, "Press to teleport"),
ToolUtil.HelpGrip(Owner, "Hold to move"),
}.Where(x => x != null));
}
//public override List<HelpText> GetHelpTexts()
//{
// return new List<HelpText>(new[]
// {
// ToolUtil.HelpTrackpadCenter(Owner, "Press to teleport"),
// ToolUtil.HelpGrip(Owner, "Hold to move"),
// }.Where(x => x != null));
//}
}
}
4 changes: 2 additions & 2 deletions CharaStudioVR/Controls/GripMenuHandler.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Linq;
using KKS_VR.Settings;
using KK_VR.Settings;
using UnityEngine;
using Valve.VR;
using VRGIN.Controls;
using VRGIN.Core;
using VRGIN.Native;
using VRGIN.Visuals;

namespace KKS_VR.Controls
namespace KK_VR.Controls
{
public class GripMenuHandler : ProtectedBehaviour
{
Expand Down
8 changes: 4 additions & 4 deletions CharaStudioVR/Controls/GripMoveStudioNEOV2Tool.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using KKS_VR.Settings;
using KKS_VR.Util;
using KK_VR.Settings;
using KK_VR.Util;
using Studio;
using UnityEngine;
using UnityEngine.Rendering;
Expand All @@ -15,7 +15,7 @@
using VRGIN.Helpers;
using VRGIN.Visuals;

namespace KKS_VR.Controls
namespace KK_VR.Controls
{
internal class GripMoveStudioNEOV2Tool : Tool
{
Expand Down Expand Up @@ -89,7 +89,7 @@ private void CreatePointer()
}
}

protected override void OnDestroy()
private void OnDestroy()
{
if (marker != null) Destroy(marker);
if (mirror1 != null) Destroy(mirror1);
Expand Down
4 changes: 2 additions & 2 deletions CharaStudioVR/Controls/IKTool.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections;
using KKS_VR.Util;
using KK_VR.Util;
using Studio;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

namespace KKS_VR.Controls
namespace KK_VR.Controls
{
public class IKTool : MonoBehaviour
{
Expand Down
2 changes: 1 addition & 1 deletion CharaStudioVR/Controls/ObjMoveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Studio;
using UnityEngine;

namespace KKS_VR.Controls
namespace KK_VR.Controls
{
internal class ObjMoveHelper
{
Expand Down
2 changes: 1 addition & 1 deletion CharaStudioVR/Controls/VRCameraMoveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using UnityEngine.UI;
using VRGIN.Core;

namespace KKS_VR.Controls
namespace KK_VR.Controls
{
public class VRCameraMoveHelper : MonoBehaviour
{
Expand Down
2 changes: 1 addition & 1 deletion CharaStudioVR/Controls/VRItemObjMoveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using VRGIN.Core;
using VRGIN.Helpers;

namespace KKS_VR.Controls
namespace KK_VR.Controls
{
public class VRItemObjMoveHelper : MonoBehaviour
{
Expand Down
131 changes: 131 additions & 0 deletions CharaStudioVR/Features/VRBoop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using UnityEngine;
using UnityEngine.XR;
using VRGIN.Controls;

// MainGame uses a bit different implementation.
namespace KK_VR.Features
{
/// <summary>
/// Adds colliders to the controllers so you can boop things
/// Based on a feature in KK_VREnhancement by thojmr
/// https://github.com/thojmr/KK_VREnhancement/blob/5e46bc9a89bf2517c5482bc9df097c7f0274730f/KK_VREnhancement/VRController.Collider.cs
/// </summary>
public static class VRBoopStudio
{
internal const string LeftColliderName = "Left_Boop_Collider";
internal const string RightColliderName = "Right_Boop_Collider";

private static DynamicBoneCollider _leftCollider;
private static DynamicBoneCollider _rightCollider;

public static void Initialize(Controller controller, EyeSide controllerSide)
{
// Hooks in here don't get patched by the whole assembly PatchAll since the class has no HarmonyPatch attribute
Harmony.CreateAndPatchAll(typeof(VRBoop), typeof(VRBoop).FullName);

switch (controllerSide)
{
case EyeSide.Left:
_leftCollider = GetOrAttachCollider(controller.gameObject, LeftColliderName);
break;
case EyeSide.Right:
_rightCollider = GetOrAttachCollider(controller.gameObject, RightColliderName);
break;
default:
throw new ArgumentOutOfRangeException(nameof(controllerSide), controllerSide, null);
}
}

[HarmonyPostfix]
[HarmonyWrapSafe]
[HarmonyPatch(typeof(DynamicBone), nameof(DynamicBone.SetupParticles))]
[HarmonyPatch(typeof(DynamicBone_Ver01), nameof(DynamicBone_Ver01.SetupParticles))]
[HarmonyPatch(typeof(DynamicBone_Ver02), nameof(DynamicBone_Ver02.SetupParticles))]
private static void OnDynamicBoneInit(MonoBehaviour __instance)
{
AttachControllerColliders(__instance);
}

[HarmonyPrefix]
[HarmonyWrapSafe]
[HarmonyPatch(typeof(ChaControl), nameof(ChaControl.LoadCharaFbxDataAsync))]
// [HarmonyPatch(typeof(ChaControl), nameof(ChaControl.LoadCharaFbxDataNoAsync))] // unnecessary, the collider array is reset before the SetupParticles hook
private static void OnClothesChanged(ref Action<GameObject> actObj)
{
// This action is called with the loaded object after the colliders on it are set up
// This needs to be done despite the SetupParticles hook because LoadCharaFbxData resets the collider list
actObj += newObj =>
{
if (newObj == null) return;
foreach (var newBone in newObj.GetComponentsInChildren<DynamicBone>())
{
var colliders = newBone.m_Colliders;
if (colliders != null)
AttachControllerColliders(colliders);
}
};
}

private static void AttachControllerColliders(MonoBehaviour dynamicBone)
{
var colliderList = GetColliderList(dynamicBone);
if (colliderList == null) return;
AttachControllerColliders(colliderList);
}

private static void AttachControllerColliders(List<DynamicBoneCollider> colliderList)
{
if (colliderList == null) throw new ArgumentNullException(nameof(colliderList));

if (_leftCollider && !colliderList.Contains(_leftCollider))
colliderList.Add(_leftCollider);
if (_rightCollider && !colliderList.Contains(_rightCollider))
colliderList.Add(_rightCollider);
}

private static List<DynamicBoneCollider> GetColliderList(MonoBehaviour dynamicBone)
{
return dynamicBone switch
{
DynamicBone d => d.m_Colliders,
DynamicBone_Ver01 d => d.m_Colliders,
DynamicBone_Ver02 d => d.Colliders,
null => throw new ArgumentNullException(nameof(dynamicBone)),
_ => throw new ArgumentException(@"Not a DynamicBone - " + dynamicBone.GetType(), nameof(dynamicBone)),
};
}

private static DynamicBoneCollider GetOrAttachCollider(GameObject controllerGameObject, string colliderName)
{
if (controllerGameObject == null) throw new ArgumentNullException(nameof(controllerGameObject));
if (colliderName == null) throw new ArgumentNullException(nameof(colliderName));

//Check for existing DB collider that may have been attached earlier
var existingCollider = controllerGameObject.GetComponentInChildren<DynamicBoneCollider>();
if (existingCollider == null)
{
//Add a DB collider to the controller
return AddDbCollider(controllerGameObject, colliderName);
}

return existingCollider;
}

private static DynamicBoneCollider AddDbCollider(GameObject controllerGameObject, string colliderName,
float colliderRadius = 0.05f, float collierHeight = 0f, Vector3 colliderCenter = new Vector3(), DynamicBoneCollider.Direction colliderDirection = default)
{
//Build the dynamic bone collider
var colliderObject = new GameObject(colliderName);
var collider = colliderObject.AddComponent<DynamicBoneCollider>();
collider.m_Radius = colliderRadius;
collider.m_Height = collierHeight;
collider.m_Center = colliderCenter;
collider.m_Direction = colliderDirection;
colliderObject.transform.SetParent(controllerGameObject.transform, false);
return collider;
}
}
}
4 changes: 2 additions & 2 deletions CharaStudioVR/Fixes/LoadFixHook.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using BepInEx.Logging;
using HarmonyLib;
using KKS_VR.Interpreters;
using KK_VR.Interpreters;
using Studio;
using VRGIN.Core;

namespace KKS_VR.Fixes
namespace KK_VR.Fixes
{
public static class LoadFixHook
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using HarmonyLib;
using Unity.XR.OpenVR;

namespace KKS_VR.Fixes
// Will break haptic feedback in KKS if enabled.
namespace KK_VR.Fixes
{
/// <summary>
/// No idea what exactly it does but it doesn't seem to hurt anything. Originally a part of KKS_CharaStudioVR
Expand Down
Loading