From 4072bad68a7aac3e4039ac15423ea488ee27bd70 Mon Sep 17 00:00:00 2001
From: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Date: Fri, 5 Nov 2021 23:24:38 +0100
Subject: [PATCH] Final KKS fixes
---
.../Data/PregnancyDataUtils.cs | 9 +-
src/Core_Pregnancy_KK/LactationController.cs | 13 +-
.../PregnancyPlugin.Hooks.cs | 25 +-
.../GUI/PregnancyGui.StatusIcons.cs | 272 +++++-------------
src/KKS_Pregnancy/KKS_Pregnancy.csproj | 6 +-
5 files changed, 98 insertions(+), 227 deletions(-)
diff --git a/src/Core_Pregnancy_KK/Data/PregnancyDataUtils.cs b/src/Core_Pregnancy_KK/Data/PregnancyDataUtils.cs
index efeca0f..e1fd1d0 100644
--- a/src/Core_Pregnancy_KK/Data/PregnancyDataUtils.cs
+++ b/src/Core_Pregnancy_KK/Data/PregnancyDataUtils.cs
@@ -54,11 +54,18 @@ public static HeroineStatus GetCharaStatus(this SaveData.CharaData chara, Pregna
if (pregData == null) pregData = heroine.GetPregnancyData();
// Check if she wants to tell //todo need to ask in talk scene
- if (heroine.intimacy >= 80 || //todo what is relation in kks
+#if KK
+ if (heroine.intimacy >= 80 ||
heroine.hCount >= 5 ||
heroine.parameter.attribute.bitch && heroine.favor > 50 ||
(heroine.isGirlfriend || heroine.favor >= 90) &&
(!heroine.isVirgin || heroine.hCount >= 2 || heroine.intimacy >= 40))
+#else
+ if (heroine.relation >= 3 ||
+ heroine.hCount >= 5 ||
+ heroine.parameter.attribute.bitch && heroine.favor > 50 ||
+ heroine.isGirlfriend && (heroine.favor >= 90 || heroine.hCount >= 2))
+#endif
{
var pregnancyWeek = pregData.Week;
if (pregnancyWeek > 0)
diff --git a/src/Core_Pregnancy_KK/LactationController.cs b/src/Core_Pregnancy_KK/LactationController.cs
index 8340378..680e694 100644
--- a/src/Core_Pregnancy_KK/LactationController.cs
+++ b/src/Core_Pregnancy_KK/LactationController.cs
@@ -285,9 +285,14 @@ private void InitializeParticles()
PregnancyPlugin.Logger.LogDebug("Adding particles to heroine: " + ChaControl.fileParam.fullname);
+#if KK
+ const string assetFilePath = @"h/common/00_00.unity3d";
+#elif KKS
+ const string assetFilePath = @"h/common/01.unity3d";
+#endif
_partHeavyR = new HParticleCtrl.ParticleInfo
{
- assetPath = @"h/common/00_00.unity3d",
+ assetPath = assetFilePath,
file = "LiquidSiru",
numParent = 1,
nameParent = "a_n_nip_R",
@@ -296,7 +301,7 @@ private void InitializeParticles()
};
_partLightR = new HParticleCtrl.ParticleInfo
{
- assetPath = @"h/common/00_00.unity3d",
+ assetPath = assetFilePath,
file = "LiquidSio",
numParent = 1,
nameParent = "a_n_nip_R",
@@ -305,7 +310,7 @@ private void InitializeParticles()
};
_partHeavyL = new HParticleCtrl.ParticleInfo
{
- assetPath = @"h/common/00_00.unity3d",
+ assetPath = assetFilePath,
file = "LiquidSiru",
numParent = 1,
nameParent = "a_n_nip_L",
@@ -314,7 +319,7 @@ private void InitializeParticles()
};
_partLightL = new HParticleCtrl.ParticleInfo
{
- assetPath = @"h/common/00_00.unity3d",
+ assetPath = assetFilePath,
file = "LiquidSio",
numParent = 1,
nameParent = "a_n_nip_L",
diff --git a/src/Core_Pregnancy_KK/PregnancyPlugin.Hooks.cs b/src/Core_Pregnancy_KK/PregnancyPlugin.Hooks.cs
index 855940a..c7470f9 100644
--- a/src/Core_Pregnancy_KK/PregnancyPlugin.Hooks.cs
+++ b/src/Core_Pregnancy_KK/PregnancyPlugin.Hooks.cs
@@ -1,11 +1,9 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using System.Reflection;
using System.Reflection.Emit;
using ExtensibleSaveFormat;
using HarmonyLib;
-using KKAPI.MainGame;
+using KKAPI.Utilities;
using Manager;
using UnityEngine;
@@ -19,17 +17,14 @@ public static void InitHooks(Harmony harmonyInstance)
{
harmonyInstance.PatchAll(typeof(Hooks));
- PatchNPCLoadAll(harmonyInstance, new HarmonyMethod(typeof(Hooks), nameof(NPCLoadAllTpl)));
+ PatchNPCLoadAll(harmonyInstance);
}
- private static bool _lastPullProc;
-
#region Custom safe day schedule
private static SaveData.Heroine _lastHeroine;
private static byte[] _menstruationsBackup;
-
[HarmonyPostfix]
[HarmonyPatch(typeof(SaveData.Heroine), nameof(SaveData.Heroine.MenstruationDay), MethodType.Getter)]
private static void LastAccessedHeroinePatch(SaveData.Heroine __instance)
@@ -71,17 +66,21 @@ private static void GetMenstruationOverridePostfix()
///
/// Needed for preventing characters from going to school when on leave after pregnancy
///
- private static void PatchNPCLoadAll(Harmony instance, HarmonyMethod transpiler)
+ private static void PatchNPCLoadAll(Harmony instance)
{
- var t = typeof(ActionScene).GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Single(x => x.Name.StartsWith("c__Iterator"));
- var m = t.GetMethod("MoveNext");
- instance.Patch(m, null, null, transpiler);
+ var transpiler = new HarmonyMethod(typeof(Hooks), nameof(NPCLoadAllTpl));
+ foreach (var target in typeof(ActionScene).GetMethods(AccessTools.all).Where(x => x.Name == nameof(ActionScene.NPCLoadAll)))
+ {
+ Logger.LogDebug("Patching " + target.FullDescription());
+ instance.PatchMoveNext(target, null, null, transpiler);
+ }
}
private static IEnumerable NPCLoadAllTpl(IEnumerable instructions)
{
var target = AccessTools.Property(typeof(Game), nameof(Game.HeroineList)).GetGetMethod();
var customFilterM = AccessTools.Method(typeof(Hooks), nameof(GetFilteredHeroines));
+ var count = 0;
foreach (var instruction in instructions)
{
yield return instruction;
@@ -90,8 +89,10 @@ private static IEnumerable NPCLoadAllTpl(IEnumerable> _currentHeroine = new List>();
+ private static CharaData _currentHeroine;
internal static void Init(Harmony hi, Sprite unknownSprite, Sprite pregSprite, Sprite safeSprite, Sprite riskySprite, Sprite leaveSprite)
{
@@ -35,13 +32,6 @@ internal static void Init(Harmony hi, Sprite unknownSprite, Sprite pregSprite, S
_safeSprite = safeSprite ? safeSprite : throw new ArgumentNullException(nameof(safeSprite));
_leaveSprite = leaveSprite ? leaveSprite : throw new ArgumentNullException(nameof(leaveSprite));
- SceneManager.sceneLoaded += SceneManager_sceneLoaded;
- SceneManager.sceneUnloaded += s =>
- {
- if (_currentHeroine.Count > 0)
- SceneManager_sceneLoaded(s, LoadSceneMode.Additive);
- };
-
hi.PatchAll(typeof(StatusIcons));
}
@@ -49,108 +39,39 @@ internal static void Init(Harmony hi, Sprite unknownSprite, Sprite pregSprite, S
/// Handle class roster
///
[HarmonyPostfix]
- [HarmonyPatch(typeof(ClassRoomList), "PreviewUpdate")]
- public static void ClassroomPreviewUpdateHook(ClassRoomList __instance)
+ [HarmonyPatch(typeof(Passport), nameof(Passport.Set))]
+ private static void ClassroomPreviewUpdateHook(Passport __instance, CharaData charaData)
{
- IEnumerator ClassroomPreviewUpdateCo()
+ try
{
- yield return new WaitForEndOfFrame();
-
- _currentHeroine.Clear();
- SpawnGUI();
-
- var entries = Traverse.Create(__instance).Property("charaPreviewList")
- .GetValue>();
-
- foreach (var chaEntry in entries)
- {
- // Need to call this every time in case characters get transferred/edited
- SetHeart(chaEntry.rootObj, chaEntry.data, true);
- }
+ SetHeart(__instance, charaData);
}
-
- _pluginInstance.StartCoroutine(ClassroomPreviewUpdateCo());
- }
-
- ///
- /// Handle character list in roaming mode
- ///
- private static void SceneManager_sceneLoaded(Scene scene, LoadSceneMode mode)
- {
- if (mode == LoadSceneMode.Single || _pluginInstance == null)
- return;
-
- _currentHeroine.Clear();
-
- var chaStatusScene = FindObjectOfType();
- if (chaStatusScene != null)
+ catch (Exception e)
{
- SpawnGUI();
-
- IEnumerator CreatePregnancyIconCo()
- {
- yield return new WaitForEndOfFrame();
-
- foreach (var chaStatusComponent in chaStatusScene.transform.GetComponentsInChildren())
- {
- var chara = (SaveData.CharaData)chaStatusComponent.heroine ??
- (chaStatusComponent.name == "status_m" ? Manager.Game.Player : null);
- SetHeart(chaStatusComponent.gameObject, chara, false);
- }
- }
-
- _pluginInstance.StartCoroutine(CreatePregnancyIconCo());
- }
- }
-
- ///
- /// Handle char icon for top left quick status popup during roaming mode
- ///
- [HarmonyPostfix]
- [HarmonyPatch(typeof(ParamUI), "SetHeroine", typeof(SaveData.Heroine))]
- private static void ParamUI_SetHeroine(ParamUI __instance, SaveData.Heroine _heroine)
- {
- var objFemaleRoot = Traverse.Create(__instance).Field("objFemaleRoot").GetValue();
- if (objFemaleRoot == null) return;
-
- SpawnGUI();
-
- IEnumerator HeroineCanvasPreviewUpdateCo()
- {
- yield return new WaitForEndOfFrame();
-
- _currentHeroine.Clear();
- SetQuickStatusIcon(objFemaleRoot, _heroine, -214f, -26f);
+ UnityEngine.Debug.LogException(e);
}
-
- _pluginInstance.StartCoroutine(HeroineCanvasPreviewUpdateCo());
}
- private static void SpawnGUI()
+ [HarmonyPrefix]
+ [HarmonyPatch(typeof(ActionScene), nameof(ActionScene.Start))]
+ private static void ClassRoomListStartHook(ClassRoomList __instance)
{
- if (!GameObject.Find("PregnancyGUI"))
- new GameObject("PregnancyGUI").AddComponent();
+ _currentHeroine = null;
+ __instance.OnGUIAsObservable().Subscribe(_ => OnGUI());
}
- private void OnGUI()
+ private static void OnGUI()
{
- if (_currentHeroine.Count == 0) return;
-
- var pos = new Vector2(Input.mousePosition.x, -(Input.mousePosition.y - Screen.height));
- var heroineRect = _currentHeroine.FirstOrDefault(x =>
- {
- if (x.Value == null) return false;
- return GetOccupiedScreenRect(x).Contains(pos);
- });
- var chara = heroineRect.Key;
- if (chara == null) return;
+ if (_currentHeroine == null) return;
+ var chara = _currentHeroine;
var pregData = chara.GetPregnancyData();
var status = chara.GetCharaStatus(pregData);
- var heroine = chara as SaveData.Heroine;
+ var heroine = chara as Heroine;
var windowHeight = status == HeroineStatus.Unknown ? 100 : status == HeroineStatus.Pregnant || status == HeroineStatus.OnLeave ? 180 : 370;
+ var pos = new Vector2(Input.mousePosition.x, -(Input.mousePosition.y - Screen.height));
var screenRect = new Rect((int)pos.x + 30, (int)pos.y - windowHeight / 2, 180, windowHeight);
IMGUIUtils.DrawSolidBox(screenRect);
GUILayout.BeginArea(screenRect, GUI.skin.box);
@@ -235,126 +156,63 @@ private void OnGUI()
///
/// Enable/disable pregnancy icon
///
- private static void SetHeart(GameObject rootObj, SaveData.CharaData chara, bool classRoster)
+ private static void SetHeart(Passport passport, CharaData chara)
{
- var pregIconTr = rootObj.transform.Find(ICON_NAME);
+ if (passport == null) throw new ArgumentNullException(nameof(passport));
- if (chara == null)
- {
- if (pregIconTr != null)
- Destroy(pregIconTr.gameObject);
- }
- else
- {
- if (pregIconTr == null)
- {
- pregIconTr = new GameObject(ICON_NAME, typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).transform;
- pregIconTr.SetParent(rootObj.transform, false);
- var rt = pregIconTr.GetComponent();
- if (classRoster)
- {
- rt.anchorMax = rt.anchorMin = rt.pivot = new Vector2(0, 1);
- rt.offsetMin = Vector2.zero;
- rt.offsetMax = new Vector2(48, 48);
- rt.localScale = Vector3.one;
- rt.localPosition = new Vector3(4, -115, 0);
- }
- else // status screen during roaming mode
- {
- rt.anchorMax = rt.anchorMin = rt.pivot = new Vector2(0.5f, 0.5f);
- rt.offsetMin = Vector2.zero;
- rt.offsetMax = new Vector2(48, 48);
- rt.localScale = Vector3.one;
- rt.localPosition = new Vector3(-273, -85, 0);
- }
- }
+ // This is needed because Atach has an image that covers our image, blocking pointer events. To fix this, change parent of our icon to the atach object
+ var atachTr = passport.transform.parent.Find("Atach");
- AddPregIcon(pregIconTr, chara);
- }
- }
+ var passpParentTr = passport._emptyImage.transform.parent;
+ var pregIconTr = (atachTr ?? passpParentTr).Find(ICON_NAME);
- ///
- /// Enable/disable pregnancy icon on quick status container
- ///
- /// The heroine image object
- /// Is the preg icon shown
- /// Offset from the character image
- /// Offset from the character image
- private static void SetQuickStatusIcon(GameObject characterImageObj, SaveData.Heroine heroine, float xOffset, float yOffset)
- {
- var existing = characterImageObj.transform.Find(ICON_NAME);
+ if (pregIconTr != null)
+ Destroy(pregIconTr.gameObject);
- if (heroine == null)
- {
- if (existing != null)
- Destroy(existing.gameObject);
- }
- else
- {
- if (existing == null)
- {
- var newChildIcon = new GameObject();
- newChildIcon.AddComponent();
- newChildIcon.AddComponent();
-
- var copy = Instantiate(newChildIcon, characterImageObj.transform);
- copy.name = ICON_NAME;
- copy.SetActive(true);
-
- var charRt = characterImageObj.GetComponent();
- var rt = copy.GetComponent();
- rt.anchoredPosition = new Vector2(charRt.anchoredPosition.x + xOffset, charRt.anchoredPosition.y + yOffset);
- rt.sizeDelta = new Vector2(48, 48);
+ if (chara == null) return;
- existing = copy.transform;
- }
+ var status = chara.GetCharaStatus(chara.GetPregnancyData());
+ if (chara is Heroine || status == HeroineStatus.Pregnant)
+ {
+ pregIconTr = new GameObject(ICON_NAME, typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).transform;
+ pregIconTr.SetParent(passpParentTr, false);
- AddPregIcon(existing, heroine);
- }
- }
+ var rt = pregIconTr.GetComponent();
+ rt.anchorMax = rt.anchorMin = rt.pivot = new Vector2(0.5f, 0.5f);
+ rt.offsetMin = Vector2.zero;
+ rt.offsetMax = new Vector2(48, 48);
+ rt.localScale = Vector3.one;
+ rt.localPosition = new Vector3(27f, -163f, 0);
- private static readonly Vector3[] _worldCornersBuffer = new Vector3[4];
+ var image = pregIconTr.GetComponent();
- private static void AddPregIcon(Transform pregIconTransform, SaveData.CharaData chara)
- {
- var image = pregIconTransform.GetComponent();
+ image.OnPointerEnterAsObservable().Subscribe(_ => _currentHeroine = chara);
+ image.OnPointerExitAsObservable().Subscribe(_ => _currentHeroine = null);
- _currentHeroine.Add(new KeyValuePair(chara, image.GetComponent()));
+ switch (status)
+ {
+ case HeroineStatus.Unknown:
+ image.sprite = _unknownSprite;
+ break;
+ case HeroineStatus.OnLeave:
+ image.sprite = _leaveSprite;
+ break;
+ case HeroineStatus.Safe:
+ image.sprite = _safeSprite;
+ break;
+ case HeroineStatus.Risky:
+ image.sprite = _riskySprite;
+ break;
+ case HeroineStatus.Pregnant:
+ image.sprite = _pregSprite;
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
- var status = chara.GetCharaStatus(chara.GetPregnancyData());
- switch (status)
- {
- case HeroineStatus.Unknown:
- image.sprite = _unknownSprite;
- break;
- case HeroineStatus.OnLeave:
- image.sprite = _leaveSprite;
- break;
- case HeroineStatus.Safe:
- image.sprite = _safeSprite;
- break;
- case HeroineStatus.Risky:
- image.sprite = _riskySprite;
- break;
- case HeroineStatus.Pregnant:
- image.sprite = _pregSprite;
- break;
- default:
- throw new ArgumentOutOfRangeException();
+ if (atachTr != null)
+ pregIconTr.SetParent(atachTr);
}
-
- pregIconTransform.gameObject.SetActiveIfDifferent(chara is SaveData.Heroine || status == HeroineStatus.Pregnant);
- }
-
- private static Rect GetOccupiedScreenRect(KeyValuePair x)
- {
- x.Value.GetWorldCorners(_worldCornersBuffer);
- var screenPos = new Rect(
- _worldCornersBuffer[0].x,
- Screen.height - _worldCornersBuffer[2].y,
- _worldCornersBuffer[2].x - _worldCornersBuffer[0].x,
- _worldCornersBuffer[2].y - _worldCornersBuffer[0].y);
- return screenPos;
}
}
}
diff --git a/src/KKS_Pregnancy/KKS_Pregnancy.csproj b/src/KKS_Pregnancy/KKS_Pregnancy.csproj
index e13fb7c..f161842 100644
--- a/src/KKS_Pregnancy/KKS_Pregnancy.csproj
+++ b/src/KKS_Pregnancy/KKS_Pregnancy.csproj
@@ -180,9 +180,9 @@
-
-
-
+
+
+