Skip to content

Commit

Permalink
added GameCustomFunctionController and debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thojmr committed Jan 9, 2021
1 parent f0a28c7 commit 277e2d9
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 11 deletions.
5 changes: 5 additions & 0 deletions KK_VREnhancement/KK_VREnhancement.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<HintPath>..\packages\IllusionLibs.Koikatu.UnityEngine.UI.5.6.2\lib\net35\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="KKAPI, Version=1.12.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IllusionModdingAPI.KKAPI.1.12.3\lib\net35\KKAPI.dll</HintPath>
<Private>False</Private>
</Reference>


<Reference Include="VRGIN, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand All @@ -76,6 +80,7 @@
<Compile Include="VREnhancementPlugin.cs" />
<Compile Include="VRCamera.Hooks.cs" />
<Compile Include="VRCamera.cs" />
<Compile Include="VRCamera.GameCustomFunctionController.cs" />
<Compile Include="VRCamera.Helper.cs" />
<Compile Include="VRControllerCollider.Hooks.cs" />
<Compile Include="VRControllerCollider.Helper.cs" />
Expand Down
40 changes: 40 additions & 0 deletions KK_VREnhancement/VRCamera.GameCustomFunctionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using UnityEngine;
using VRGIN.Helpers;
using VRGIN.Core;
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)
{
}

protected override void OnPeriodChange(Cycle.Type period)
{
if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" OnPeriodChange ");
VRCameraController.ClearLastPosition();
}
}
}
59 changes: 50 additions & 9 deletions KK_VREnhancement/VRCamera.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;
using ADV;
using System.Collections.Generic;
using KKAPI.MainGame;

namespace KK_VREnhancement
{
Expand Down Expand Up @@ -42,6 +43,7 @@ internal static void ADVScene_Update(ADVScene __instance)
internal static void TalkScene_OnDestroy(TalkScene __instance)
{
if (!VRPlugin.MoveWithTalkScene.Value) return;
if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" TalkScene_OnDestroy ");

VRCameraController.ClearLastPosition();
}
Expand All @@ -52,6 +54,7 @@ internal static void TalkScene_OnDestroy(TalkScene __instance)
internal static void HSceneProc_SetLocalPosition(HSceneProc __instance)
{
if (!VRPlugin.VREnabled || !VRPlugin.MoveWithTalkScene.Value) return;
if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" SetLocalPosition ");

List<ChaControl> lstFemale = Traverse.Create(__instance).Field("lstFemale").GetValue<List<ChaControl>>();
if (lstFemale == null || lstFemale[0] == null) return;
Expand All @@ -66,15 +69,53 @@ internal static void HSceneProc_SetLocalPosition(HSceneProc __instance)
VRCameraController.MoveToFaceHeroine_HScene(femaleTransform.position, femaleTransform.rotation);
}

//When the HScene is done clear the last position
[HarmonyPostfix]
[HarmonyPatch(typeof(HSceneProc), "OnDestroy")]
internal static void HSceneProc_OnDestroy(HSceneProc __instance)
{
if (!VRPlugin.VREnabled || !VRPlugin.MoveWithTalkScene.Value) return;

VRCameraController.ClearLastPosition();
}

// /// <summary>
// /// Triggers when changing location in h scenes
// /// </summary>
// [HarmonyPostfix]
// [HarmonyPatch(typeof(HSceneProc), nameof(HSceneProc.ChangeCategory))]
// private static void HLocationChangeHook(List<ChaControl> ___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;


// /// <summary>
// /// Something that happens at the end of H scene loading, good enough place to initialize stuff
// /// </summary>
// [HarmonyPrefix, HarmonyPatch(typeof(HSceneProc), "MapSameObjectDisable")]
// private static void MapSameObjectDisable(HSceneProc __instance)
// {


// /// <summary>
// /// Set the new original position when changing positions via the H point picker scene
// /// </summary>
// /// <param name="__instance"></param>
// [HarmonyPostfix, HarmonyPatch(typeof(HSceneProc), "ChangeCategory")]
// private static void ChangeCategory(HSceneProc __instance)
// {

}
}
14 changes: 14 additions & 0 deletions KK_VREnhancement/VRControllerCollider.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ internal static void ADVScene_Update(ADVScene __instance)
internal static void NPC_Create(bool isShuffle)
{
if (!VRPlugin.VREnabled || !VRPlugin.EnableControllerColliders.Value) return;
if (VRPlugin.debugLog) VRPlugin.Logger.LogInfo($" NPCLoadAll ");

VRControllerColliderHelper.TriggerHelperCoroutine(_pluginInstance);
}




// private void Awake()
// {
// SceneManager.sceneLoaded += new UnityAction<Scene, LoadSceneMode>(this.SceneManager_sceneLoaded);
// this.SceneManager_sceneLoaded(SceneManager.GetActiveScene(), 0);
// }

// // Token: 0x06000002 RID: 2 RVA: 0x00002074 File Offset: 0x00000274
// private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode lsm)
// {

}
}
15 changes: 13 additions & 2 deletions KK_VREnhancement/VREnhancementPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using HarmonyLib;
using System;
using VRGIN.Helpers;
using KKAPI.MainGame;

namespace KK_VREnhancement
{
[BepInPlugin(GUID, GUID, Version)]
public partial class VRPlugin : BaseUnityPlugin
public class VRPlugin : BaseUnityPlugin
{
public const string GUID = "KK_VREnhancement";
public const string Version = "0.1";
Expand All @@ -18,12 +19,18 @@ public partial class VRPlugin : BaseUnityPlugin
internal static new ManualLogSource Logger { get; private set; }
internal static bool VREnabled = false;

#if DEBUG
internal static bool debugLog = true;
#else
internal static bool debugLog = false;
#endif

internal void Start()
{
Logger = base.Logger;

MoveWithTalkScene = Config.Bind<bool>("", "Enable move with scene", true,
"Will move the VR camera view in front of the heroine as they move around during TalkScene/HScene\n\nWhen disabled, you stay put as the heroine moves around.");
"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<bool>("", "Enable VR controller colliders", true,
Expand All @@ -35,9 +42,13 @@ internal void Start()
bool vrFlag = Environment.CommandLine.Contains("--novr");
VREnabled = !noVrFlag && (vrFlag || SteamVRDetector.IsRunning);

if (debugLog) VRPlugin.Logger.Log(LogLevel.Info, $" VREnabled {VREnabled}");

//IF not VR dont bother with VR hooks
if (!VREnabled) return;

GameAPI.RegisterExtraBehaviour<VRCameraGameController>(GUID);

//Harmony init. It's magic!
Harmony harmony = new Harmony(GUID);

Expand Down
1 change: 1 addition & 0 deletions KK_VREnhancement/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<package id="IllusionLibs.Koikatu.Sirenix.Serialization" version="2019.4.27" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.Koikatu.UnityEngine" version="5.6.2" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.Koikatu.UnityEngine.UI" version="5.6.2" targetFramework="net35" developmentDependency="true" />
<package id="IllusionModdingAPI.KKAPI" version="1.12.3" targetFramework="net35" developmentDependency="true" />
</packages>

0 comments on commit 277e2d9

Please sign in to comment.