Skip to content

Commit

Permalink
[RealPOV][KK/KKS] Fix crashing after leaving H scene with POV enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Mar 16, 2023
1 parent 1cb6ea8 commit a7b82fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
22 changes: 13 additions & 9 deletions src/RealPOV.Core.Koikatu/RealPOV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace RealPOV.Koikatu
[BepInDependency(KKAPI.KoikatuAPI.GUID)]
public class RealPOV : RealPOVCore
{
public const string Version = "1.3.1." + BuildNumber.Version;
public const string Version = "1.3.2." + BuildNumber.Version;

private ConfigEntry<bool> HideHead { get; set; }

Expand Down Expand Up @@ -107,7 +107,7 @@ Queue<ChaControl> CreateQueue()
{
return new Queue<ChaControl>(FindObjectsOfType<ChaControl>());
}

ChaControl GetCurrentChara()
{
for(int i = 0; i < charaQueue.Count; i++)
Expand Down Expand Up @@ -149,7 +149,7 @@ ChaControl GetCurrentChara()
GameCamera = Camera.main;
var cc = (MonoBehaviour)GameCamera.GetComponent<CameraControl_Ver2>() ?? GameCamera.GetComponent<Studio.CameraControl>();
if(cc) cc.enabled = false;

// Fix depth of field being completely out of focus
var depthOfField = GameCamera.GetComponent<UnityStandardAssets.ImageEffects.DepthOfField>();
dofOrigSize = depthOfField.focalSize;
Expand Down Expand Up @@ -190,16 +190,20 @@ protected override void DisablePov()
currentChara = null;
currentCharaId = -1;

var cc = (MonoBehaviour)GameCamera.GetComponent<CameraControl_Ver2>() ?? GameCamera.GetComponent<Studio.CameraControl>();
if(cc) cc.enabled = true;
if(GameCamera != null)
{
var cc = (MonoBehaviour)GameCamera.GetComponent<CameraControl_Ver2>() ?? GameCamera.GetComponent<Studio.CameraControl>();
if(cc) cc.enabled = true;

var depthOfField = GameCamera.GetComponent<UnityStandardAssets.ImageEffects.DepthOfField>();
depthOfField.focalSize = dofOrigSize;
depthOfField.aperture = dofOrigAperature;
var depthOfField = GameCamera.GetComponent<UnityStandardAssets.ImageEffects.DepthOfField>();
depthOfField.focalSize = dofOrigSize;
depthOfField.aperture = dofOrigAperature;
}

base.DisablePov();

GameCamera.gameObject.layer = backupLayer;
if(GameCamera != null)
GameCamera.gameObject.layer = backupLayer;
}

[HarmonyPrefix, HarmonyPatch(typeof(NeckLookControllerVer2), nameof(NeckLookControllerVer2.LateUpdate))]
Expand Down
13 changes: 9 additions & 4 deletions src/RealPOV.Core/RealPOVCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,15 @@ protected virtual void DisablePov()
{
currentCharaGo = null;
POVEnabled = false;
GameCamera.fieldOfView = backupFOV;
GameCamera.nearClipPlane = backupNearClip;
if(GameCursor.IsInstance())
GameCursor.Instance.SetCursorLock(false);

if(GameCamera != null)
{
GameCamera.fieldOfView = backupFOV;
GameCamera.nearClipPlane = backupNearClip;

if(GameCursor.IsInstance())
GameCursor.Instance.SetCursorLock(false);
}
}
}
}

0 comments on commit a7b82fc

Please sign in to comment.