Skip to content

Commit

Permalink
KKS port (#3)
Browse files Browse the repository at this point in the history
* Add cursor lock when dragging

* Use KoikatuAPI.StudioProcessName
  • Loading branch information
ManlyMarco committed Jan 20, 2022
1 parent 2639eaa commit 6cb99a1
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 24 deletions.
6 changes: 6 additions & 0 deletions AI_StudioExtraMoveAxis/AI_StudioExtraMoveAxis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<HintPath>..\packages\IllusionLibs.BepInEx.Harmony.2.3.2\lib\net35\BepInEx.Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Cinemachine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IllusionLibs.AIGirl.Cinemachine.2018.2.21.4\lib\net46\Cinemachine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sirenix.Serialization, Version=2.0.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IllusionLibs.AIGirl.Sirenix.Serialization.2020.5.29.4\lib\net46\Sirenix.Serialization.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -105,10 +109,12 @@
<Error Condition="!Exists('..\packages\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.2020.5.29.4\build\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.2020.5.29.4\build\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.targets'))" />
<Error Condition="!Exists('..\packages\IllusionLibs.AIGirl.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.AIGirl.Sirenix.Serialization.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.AIGirl.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.AIGirl.Sirenix.Serialization.targets'))" />
<Error Condition="!Exists('..\packages\IllusionLibs.AIGirl.UniRx.2020.5.29.4\build\IllusionLibs.AIGirl.UniRx.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.AIGirl.UniRx.2020.5.29.4\build\IllusionLibs.AIGirl.UniRx.targets'))" />
<Error Condition="!Exists('..\packages\IllusionLibs.AIGirl.Cinemachine.2018.2.21.4\build\IllusionLibs.AIGirl.Cinemachine.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.AIGirl.Cinemachine.2018.2.21.4\build\IllusionLibs.AIGirl.Cinemachine.targets'))" />
</Target>
<Import Project="..\packages\IllusionLibs.AIGirl.UnityEngine.CoreModule.2018.2.21.4\build\IllusionLibs.AIGirl.UnityEngine.CoreModule.targets" Condition="Exists('..\packages\IllusionLibs.AIGirl.UnityEngine.CoreModule.2018.2.21.4\build\IllusionLibs.AIGirl.UnityEngine.CoreModule.targets')" />
<Import Project="..\packages\IllusionLibs.BepInEx.Harmony.2.3.2\build\IllusionLibs.BepInEx.Harmony.targets" Condition="Exists('..\packages\IllusionLibs.BepInEx.Harmony.2.3.2\build\IllusionLibs.BepInEx.Harmony.targets')" />
<Import Project="..\packages\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.2020.5.29.4\build\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.targets" Condition="Exists('..\packages\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.2020.5.29.4\build\IllusionLibs.AIGirl.Assembly-CSharp-firstpass.targets')" />
<Import Project="..\packages\IllusionLibs.AIGirl.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.AIGirl.Sirenix.Serialization.targets" Condition="Exists('..\packages\IllusionLibs.AIGirl.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.AIGirl.Sirenix.Serialization.targets')" />
<Import Project="..\packages\IllusionLibs.AIGirl.UniRx.2020.5.29.4\build\IllusionLibs.AIGirl.UniRx.targets" Condition="Exists('..\packages\IllusionLibs.AIGirl.UniRx.2020.5.29.4\build\IllusionLibs.AIGirl.UniRx.targets')" />
<Import Project="..\packages\IllusionLibs.AIGirl.Cinemachine.2018.2.21.4\build\IllusionLibs.AIGirl.Cinemachine.targets" Condition="Exists('..\packages\IllusionLibs.AIGirl.Cinemachine.2018.2.21.4\build\IllusionLibs.AIGirl.Cinemachine.targets')" />
</Project>
3 changes: 2 additions & 1 deletion AI_StudioExtraMoveAxis/AI_StudioExtraMoveAxisPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using BepInEx;
using KKAPI;

namespace StudioExtraMoveAxis
{
[BepInProcess("StudioNEOV2")]
[BepInProcess(KoikatuAPI.StudioProcessName)]
public partial class StudioExtraMoveAxisPlugin : BaseUnityPlugin
{
}
Expand Down
1 change: 1 addition & 0 deletions AI_StudioExtraMoveAxis/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="ExtensibleSaveFormat.AIGirl" version="16.3.1" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.Assembly-CSharp" version="2020.5.29.4" targetFramework="net46" />
<package id="IllusionLibs.AIGirl.Assembly-CSharp-firstpass" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.Cinemachine" version="2018.2.21.4" targetFramework="net46" />
<package id="IllusionLibs.AIGirl.Sirenix.Serialization" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.UniRx" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.UnityEngine.CoreModule" version="2018.2.21.4" targetFramework="net46" />
Expand Down
70 changes: 50 additions & 20 deletions Common_StudioExtraMoveAxis/StudioExtraMoveAxisPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Illusion.Extensions;
using KKAPI;
using KKAPI.Studio;
using KKAPI.Studio.UI;
using KKAPI.Utilities;
Expand All @@ -16,7 +16,7 @@
namespace StudioExtraMoveAxis
{
[BepInPlugin(GUID, Name, Version)]
[BepInDependency(KKAPI.KoikatuAPI.GUID, "1.10")]
[BepInDependency(KoikatuAPI.GUID, KoikatuAPI.VersionConst)]
public partial class StudioExtraMoveAxisPlugin : BaseUnityPlugin
{
public const string GUID = "StudioExtraMoveAxis";
Expand All @@ -35,9 +35,6 @@ public partial class StudioExtraMoveAxisPlugin : BaseUnityPlugin
private static GameObject _gizmoRoot;
private static GameObject _moveObj, _rotObj, _scaleObj;
private static GuideMove[] _guideMoves;
#if !PH
private static FieldInfo _fTransformRoot;
#endif

private static HashSet<GuideObject> _selectedObjects;
private static bool _lastAnySelected;
Expand Down Expand Up @@ -66,8 +63,7 @@ private void Awake()
}
else
{
var texRes = ResourceUtils.GetEmbeddedResource("toolbar_icon.png", typeof(StudioExtraMoveAxisPlugin).Assembly) ?? throw new ArgumentException("icon resource not found");
var buttonTex = texRes.LoadTexture(TextureFormat.DXT5, false) ?? throw new ArgumentException("failed to load icon texture");
var buttonTex = ResourceUtils.GetEmbeddedResource("toolbar_icon.png", typeof(StudioExtraMoveAxisPlugin).Assembly).LoadTexture(TextureFormat.DXT5, false);
var tgl = CustomToolbarButtons.AddLeftToolbarToggle(buttonTex, _showGizmo.Value, b => _showGizmo.Value = b);
_showGizmo.SettingChanged += (o, eventArgs) =>
{
Expand All @@ -79,12 +75,14 @@ private void Awake()
}
}

#if DEBUG
private void OnDestroy()
{
Destroy(_gizmoRoot);
_hi?.UnpatchAll(_hi.Id);
_selectedObjects = null;
}
#endif

private void Update()
{
Expand All @@ -108,16 +106,10 @@ private static void Initialize()
_camera = Camera.main;
if (_camera == null) throw new ArgumentException("Camera.main not found");

var origRoot = Traverse.Create(GuideObjectManager.Instance).Field<GameObject>("objectOriginal").Value;
var origRoot = GuideObjectManager.Instance.objectOriginal;
if (origRoot == null) throw new ArgumentException("origRoot not found");

#if !PH
_fTransformRoot = AccessTools.Field(typeof(GuideMove), "transformRoot") ??
throw new ArgumentException("Couldn't get transformRoot field");
#endif
_selectedObjects = Traverse.Create(Singleton<GuideObjectManager>.Instance)
.Field<HashSet<GuideObject>>("hashSelectObject").Value ??
throw new ArgumentException("Couldn't get hashSelectObject");
_selectedObjects = GuideObjectManager.Instance.hashSelectObject ?? throw new ArgumentException("Couldn't get hashSelectObject");

_gizmoRoot = Instantiate(origRoot, _camera.transform);
_gizmoRoot.gameObject.name = "CustomManipulatorGizmo";
Expand Down Expand Up @@ -193,7 +185,7 @@ private static void SetMoveRootTr(Transform rootTransform)
{
var guideMove = _guideMoves[i];
guideMove.moveCalc = GuideMove.MoveCalc.TYPE3;
_fTransformRoot.SetValue(guideMove, rootTransform);
guideMove.transformRoot = rootTransform;
// not working because cursor doesnt delta move
//guideMove.onDragAction = () => Cursor.lockState = CursorLockMode.Locked;
//guideMove.onEndDragAction = () => Cursor.lockState = CursorLockMode.None;
Expand Down Expand Up @@ -252,6 +244,44 @@ private static void SetVisibility(int value)

private static class Hooks
{
#region Cursor lock when dragging

private static bool _locked;

[HarmonyPostfix]
[HarmonyPatch(typeof(GuideBase), nameof(GuideBase.OnBeginDrag))]
private static void OnBeginDragHook(GuideBase __instance/*, PointerEventData eventData*/)
{
if (_gizmoRoot != null && __instance.transform.parent?.parent == _gizmoRoot.transform)
{
_locked = true;
var gc = GameCursor.Instance;
// Save current cursor position and lock it
gc.SetCursorLock(true);
// Stop the game resetting cursor position to the center of the screen on every frame, which breaks how gizmo dragging works
gc.enabled = false;
// Prevent camera script from unlocking the cursor on every frame
FindObjectOfType<Studio.CameraControl>().isCursorLock = false;
}
}

[HarmonyPostfix]
[HarmonyPatch(typeof(GuideBase), nameof(GuideBase.OnEndDrag))]
private static void OnEndDragHook(/*GuideBase __instance*/)
{
if (_locked)
{
GameCursor.Instance.SetCursorLock(false);
_locked = false;
GameCursor.Instance.enabled = true;
FindObjectOfType<Studio.CameraControl>().isCursorLock = true;
}
}

#endregion

#region Attaching our gizmo to stock gizmo code

[HarmonyPrefix]
[HarmonyPatch(typeof(GuideObjectManager), nameof(GuideObjectManager.mode), MethodType.Setter)]
private static void SetModeHook(int value, int ___m_Mode)
Expand All @@ -271,8 +301,8 @@ private static void SetVisibleTranslationHook()
}

[HarmonyPostfix]
[HarmonyPatch(typeof(GuideObjectManager), "AddObject")]
[HarmonyPatch(typeof(GuideObjectManager), "SetDeselectObject")]
[HarmonyPatch(typeof(GuideObjectManager), nameof(GuideObjectManager.AddObject))]
[HarmonyPatch(typeof(GuideObjectManager), nameof(GuideObjectManager.SetDeselectObject))]
private static void AddObjectHook(GuideObject _object)
{
if (_object == null || _selectedObjects == null) return;
Expand All @@ -284,7 +314,7 @@ private static void AddObjectHook(GuideObject _object)
SetVisibility();
}
#endif
#endregion
}

}
}
}
6 changes: 6 additions & 0 deletions HS2_StudioExtraMoveAxis/HS2_StudioExtraMoveAxis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
<HintPath>..\packages\IllusionLibs.BepInEx.Harmony.2.3.2\lib\net35\BepInEx.Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Cinemachine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IllusionLibs.HoneySelect2.Cinemachine.2018.4.11.4\lib\net46\Cinemachine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HS2API, Version=1.20.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IllusionModdingAPI.HS2API.1.20.3\lib\net46\HS2API.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -110,11 +114,13 @@
<Error Condition="!Exists('..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.4\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.4\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets'))" />
<Error Condition="!Exists('..\packages\IllusionLibs.HoneySelect2.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.HoneySelect2.Sirenix.Serialization.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.HoneySelect2.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.HoneySelect2.Sirenix.Serialization.targets'))" />
<Error Condition="!Exists('..\packages\IllusionLibs.HoneySelect2.UniRx.2020.5.29.4\build\IllusionLibs.HoneySelect2.UniRx.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.HoneySelect2.UniRx.2020.5.29.4\build\IllusionLibs.HoneySelect2.UniRx.targets'))" />
<Error Condition="!Exists('..\packages\IllusionLibs.HoneySelect2.Cinemachine.2018.4.11.4\build\IllusionLibs.HoneySelect2.Cinemachine.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\IllusionLibs.HoneySelect2.Cinemachine.2018.4.11.4\build\IllusionLibs.HoneySelect2.Cinemachine.targets'))" />
</Target>
<Import Project="..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp.2020.5.29.4\build\IllusionLibs.HoneySelect2.Assembly-CSharp.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp.2020.5.29.4\build\IllusionLibs.HoneySelect2.Assembly-CSharp.targets')" />
<Import Project="..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.4\build\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.4\build\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.targets')" />
<Import Project="..\packages\IllusionLibs.HoneySelect2.IL.2020.5.29.4\build\IllusionLibs.HoneySelect2.IL.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.IL.2020.5.29.4\build\IllusionLibs.HoneySelect2.IL.targets')" />
<Import Project="..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.4\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.4\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets')" />
<Import Project="..\packages\IllusionLibs.HoneySelect2.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.HoneySelect2.Sirenix.Serialization.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.Sirenix.Serialization.2020.5.29.4\build\IllusionLibs.HoneySelect2.Sirenix.Serialization.targets')" />
<Import Project="..\packages\IllusionLibs.HoneySelect2.UniRx.2020.5.29.4\build\IllusionLibs.HoneySelect2.UniRx.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.UniRx.2020.5.29.4\build\IllusionLibs.HoneySelect2.UniRx.targets')" />
<Import Project="..\packages\IllusionLibs.HoneySelect2.Cinemachine.2018.4.11.4\build\IllusionLibs.HoneySelect2.Cinemachine.targets" Condition="Exists('..\packages\IllusionLibs.HoneySelect2.Cinemachine.2018.4.11.4\build\IllusionLibs.HoneySelect2.Cinemachine.targets')" />
</Project>
3 changes: 2 additions & 1 deletion HS2_StudioExtraMoveAxis/HS2_StudioExtraMoveAxisPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using BepInEx;
using KKAPI;

namespace StudioExtraMoveAxis
{
[BepInProcess("StudioNEOV2")]
[BepInProcess(KoikatuAPI.StudioProcessName)]
public partial class StudioExtraMoveAxisPlugin : BaseUnityPlugin
{
}
Expand Down
1 change: 1 addition & 0 deletions HS2_StudioExtraMoveAxis/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<package id="IllusionLibs.BepInEx.Harmony" version="2.3.2" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.HoneySelect2.Assembly-CSharp" version="2020.5.29.4" targetFramework="net46" />
<package id="IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass" version="2020.5.29.4" targetFramework="net46" />
<package id="IllusionLibs.HoneySelect2.Cinemachine" version="2018.4.11.4" targetFramework="net46" />
<package id="IllusionLibs.HoneySelect2.IL" version="2020.5.29.4" targetFramework="net46" />
<package id="IllusionLibs.HoneySelect2.Sirenix.Serialization" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.HoneySelect2.UniRx" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
Expand Down
Loading

0 comments on commit 6cb99a1

Please sign in to comment.