Skip to content

Commit

Permalink
[Crest] Add new crest with gameplay effect - Broodmother
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Sep 20, 2022
1 parent ff49170 commit 1060d8c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/Core_LewdCrestX/CrestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum CrestType
triggered,
vibrancy,
violove,
wombgasm
broodmother
}

public partial class LewdCrestXPlugin
Expand All @@ -61,6 +61,7 @@ public partial class LewdCrestXPlugin
CrestType.triggered,
CrestType.vibrancy,
CrestType.violove,
CrestType.broodmother
};
}
}
5 changes: 5 additions & 0 deletions src/Core_LewdCrestX/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@ public static void SaveToData<T>(this object settingContainer, PluginData data,
if (!Equals(defaultValue, value))
data.data.Add(propName, value);
}

public static string GetFullname(this SaveData.CharaData character)
{
return character.charFile?.parameter?.fullname ?? "???";
}
}
}
107 changes: 83 additions & 24 deletions src/Core_LewdCrestX/Hooks/PreggersHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using HarmonyLib;
using KKAPI.Chara;
using UnityEngine;

namespace KK_LewdCrestX
{
Expand All @@ -13,37 +14,95 @@ internal static class PreggersHooks

public static bool TryPatchPreggers(Harmony hi)
{
// Lactation patches
{
#if KK
var lactType = Type.GetType("KK_Pregnancy.LactationController, KK_Pregnancy", false);
var lactType = Type.GetType("KK_Pregnancy.LactationController, KK_Pregnancy", false);
#elif KKS
var lactType = Type.GetType("KK_Pregnancy.LactationController, KKS_Pregnancy", false);
var lactType = Type.GetType("KK_Pregnancy.LactationController, KKS_Pregnancy", false);
#endif
if (lactType != null)
{
if (lactType == null)
{
LewdCrestXPlugin.Logger.LogWarning("Could not find KK_Pregnancy.LactationController, some features might not work until you install KK_Pregnancy (please report this if you do have latest version of KK_Pregnancy installed)");
return false;
}

var lactDataType = lactType.GetNestedType("CharaData", AccessTools.all);
if (lactDataType != null)
if (lactDataType == null)
{
LewdCrestXPlugin.Logger.LogWarning("Could not find KK_Pregnancy.LactationController.CharaData - something isn't right, please report this");
return false;
}

var milkAmountMethod = lactDataType.GetMethod("GetMilkAmount", AccessTools.all);
if (milkAmountMethod == null)
{
LewdCrestXPlugin.Logger.LogWarning("Could not find KK_Pregnancy.LactationController.CharaData.GetMilkAmount - something isn't right, please report this");
return false;
}

hi.Patch(milkAmountMethod, postfix: new HarmonyMethod(typeof(PreggersHooks), nameof(GetMilkAmountPatch)));
}

// Stat patches, needs newer version of the preggers plugin than Lactation patches
try
{
#if KK
var utilsType = Type.GetType("KK_Pregnancy.PregnancyDataUtils, KK_Pregnancy", true);
#elif KKS
var utilsType = Type.GetType("KK_Pregnancy.PregnancyDataUtils, KKS_Pregnancy", true);
#endif
hi.Patch(utilsType.GetMethod(nameof(KK_Pregnancy.PregnancyDataUtils.GetFertility), AccessTools.allDeclared), postfix: new HarmonyMethod(typeof(PreggersHooks), nameof(GetFertilityHook)));
hi.Patch(utilsType.GetMethod(nameof(KK_Pregnancy.PregnancyDataUtils.GetMenstruation), AccessTools.allDeclared), postfix: new HarmonyMethod(typeof(PreggersHooks), nameof(GetMenstruationHook)));
hi.Patch(utilsType.GetMethod(nameof(KK_Pregnancy.PregnancyDataUtils.GetPregnancyProgressionSpeed), AccessTools.allDeclared), postfix: new HarmonyMethod(typeof(PreggersHooks), nameof(GetPregnancyProgressionSpeedHook)));
}
catch (Exception ex)
{
LewdCrestXPlugin.Logger.LogWarning("Could not patch KK_Pregnancy.PregnancyDataUtils, some features might not work until you install the latest version of KK_Pregnancy. Details: " + ex);
}

_patched = true;
return true;
}

public static void GetFertilityHook(SaveData.CharaData character, ref float __result)
{
if (character is SaveData.Heroine heroine)
{
Console.WriteLine("GetFertilityHook");
if (heroine.GetCurrentCrest() == CrestType.broodmother)
{
var milkAmountMethod = lactDataType.GetMethod("GetMilkAmount", AccessTools.all);
if (milkAmountMethod != null)
{
hi.Patch(milkAmountMethod,
postfix: new HarmonyMethod(typeof(PreggersHooks), nameof(PreggersHooks.GetMilkAmountPatch)));
_patched = true;
return true;
}
else
LewdCrestXPlugin.Logger.LogWarning(
"Could not find KK_Pregnancy.LactationController.CharaData.GetMilkAmount - something isn't right, please report this");
// result is 0-1 range
__result = Mathf.Max(__result, 0.96f);
LewdCrestXPlugin.Logger.LogDebug($"Overriding GetFertility for {character.GetFullname()} to {__result} because of broodmother crest");
}
else
LewdCrestXPlugin.Logger.LogWarning(
"Could not find KK_Pregnancy.LactationController.CharaData - something isn't right, please report this");
}
else
LewdCrestXPlugin.Logger.LogWarning(
"Could not find KK_Pregnancy.LactationController, some features might not work until you install KK_Pregnancy (please report this if you do have latest version of KK_Pregnancy installed)");
}

return false;
public static void GetMenstruationHook(SaveData.CharaData character, ref object __result)
{
if (character is SaveData.Heroine heroine)
{
if (heroine.GetCurrentCrest() == CrestType.broodmother)
{
// result is actually enum MenstruationSchedule
__result = KK_Pregnancy.MenstruationSchedule.AlwaysRisky;
LewdCrestXPlugin.Logger.LogDebug($"Overriding GetMenstruation for {character.GetFullname()} to {__result} because of broodmother crest");
}
}
}

public static void GetPregnancyProgressionSpeedHook(SaveData.CharaData character, ref int __result)
{
if (character is SaveData.Heroine heroine)
{
if (heroine.GetCurrentCrest() == CrestType.broodmother)
{
// todo Only max 20 for 2 weeks? If it worked on days instead of whole weeks it could be more granular
__result = Mathf.Min(20, __result * 5);
LewdCrestXPlugin.Logger.LogDebug($"Overriding GetPregnancyProgression for {character.GetFullname()} to {__result} because of broodmother crest");
}
}
}

private static void GetMilkAmountPatch(CharaCustomFunctionController controller, ref float __result)
Expand All @@ -60,7 +119,7 @@ public static void ApplyTempPreggers(SaveData.Heroine heroine)
if (!_patched) return;

if (_tempPreggers.Add(heroine))
LewdCrestXPlugin.Logger.LogInfo("Triggering temporary pregnancy because of breedgasm crest: " + heroine.charFile?.parameter?.fullname);
LewdCrestXPlugin.Logger.LogInfo($"Triggering temporary pregnancy because of breedgasm crest for {heroine.GetFullname()}");
}

public static void OnPeriodChanged()
Expand Down
4 changes: 2 additions & 2 deletions src/Core_LewdCrestX/LewdCrestXGameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void Update()
{
if (Vector3.Distance(player.position, npc.position) > 3)
{
LewdCrestXPlugin.Logger.LogInfo("Chasing player because of mantraction crest: " + controller.Heroine.charFile?.parameter?.fullname);
LewdCrestXPlugin.Logger.LogInfo("Chasing player because of mantraction crest: " + controller.Heroine.GetFullname());
npc.ItemClear();
npc.AI.ChaseAction();
// Need to replace this from the default chase id because that disables the talk to bubble
Expand Down Expand Up @@ -209,7 +209,7 @@ protected override void OnDayChange(Cycle.Week day)
case CrestType.restore:
if (!heroine.isVirgin)
{
LewdCrestXPlugin.Logger.LogInfo("Resetting heroine to virgin because of restore crest: " + heroine.charFile?.parameter?.fullname);
LewdCrestXPlugin.Logger.LogInfo("Resetting heroine to virgin because of restore crest: " + heroine.GetFullname());
heroine.isVirgin = true;
heroine.hCount = 0;
}
Expand Down
Binary file modified src/Core_LewdCrestX/crests
Binary file not shown.

0 comments on commit 1060d8c

Please sign in to comment.