using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BreedForLove")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BreedForLove")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f21d2e46-cdd4-4fd7-a5d7-5925aff75ab7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class AedenthornUtils
{
public static bool IgnoreKeyPresses(bool extra = false)
{
if (!extra)
{
int result;
if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
{
Chat instance = Chat.instance;
result = ((instance != null && instance.HasFocus()) ? 1 : 0);
}
else
{
result = 1;
}
return (byte)result != 0;
}
int result2;
if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
{
Chat instance2 = Chat.instance;
if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
{
TextViewer instance3 = TextViewer.instance;
result2 = ((instance3 != null && instance3.IsVisible()) ? 1 : 0);
goto IL_00d2;
}
}
result2 = 1;
goto IL_00d2;
IL_00d2:
return (byte)result2 != 0;
}
public static bool CheckKeyDown(string value)
{
try
{
return Input.GetKeyDown(value.ToLower());
}
catch
{
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
namespace BreedForLove;
[BepInPlugin("gizmorphium.BreedForLove", "Breed For Love", "0.1.1")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Procreation), "Procreate")]
private static class Procreate_Patch
{
private static void Prefix(ref int __state, Procreation __instance, ZNetView ___m_nview, Character ___m_character, Tameable ___m_tameable, BaseAI ___m_baseAI, GameObject ___m_myPrefab, GameObject ___m_offspringPrefab)
{
__state = ___m_nview.GetZDO().GetInt("lovePoints", 0);
}
private static void Postfix(int __state, Procreation __instance, ZNetView ___m_nview, Character ___m_character, Tameable ___m_tameable, BaseAI ___m_baseAI, GameObject ___m_myPrefab, GameObject ___m_offspringPrefab)
{
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
if (!modEnabled.Value || !isOn.Value || (Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance) || !___m_nview.IsValid() || !___m_nview.IsOwner() || !Object.op_Implicit((Object)(object)___m_character) || (Object)(object)___m_myPrefab == (Object)null || !Object.op_Implicit((Object)(object)___m_myPrefab) || !Object.op_Implicit((Object)(object)___m_offspringPrefab) || !___m_character.IsTamed() || ___m_baseAI.IsAlerted() || (Object)(object)___m_tameable == (Object)null || !Object.op_Implicit((Object)(object)___m_tameable) || ___m_tameable.IsHungry())
{
return;
}
Dbgl(((Object)___m_myPrefab).name + " checked for breeding.");
if (__state != ___m_nview.GetZDO().GetInt("lovePoints", 0))
{
MethodInfo method = typeof(Procreation).GetMethod("IsPregnant", BindingFlags.Instance | BindingFlags.NonPublic);
bool flag = false;
if (method != null)
{
flag = (bool)method.Invoke(__instance, null);
}
if (flag)
{
Dbgl(((Object)___m_myPrefab).name + " is pregnant.");
Dbgl($"{((Object)___m_myPrefab).name} Previous love points: {__state}");
Dbgl(string.Format("{0} Current love points: {1}", ((Object)___m_myPrefab).name, ___m_nview.GetZDO().GetInt("lovePoints", 0)));
Dbgl($"{((Object)___m_myPrefab).name} Required love points: {__instance.m_requiredLovePoints}");
int num = ((__state >= __instance.m_requiredLovePoints) ? (__state - __instance.m_requiredLovePoints + 1) : 0);
Dbgl($"{((Object)___m_myPrefab).name} Setting love points to {num}");
___m_nview.GetZDO().Set("lovePoints", num);
}
return;
}
Dbgl(" --- ");
Dbgl(((Object)___m_myPrefab).name + " didn't breed in vanilla code.");
int nrOfInstances = SpawnSystem.GetNrOfInstances(___m_myPrefab, ((Component)___m_baseAI).transform.position, __instance.m_totalCheckRange, false, false);
int nrOfInstances2 = SpawnSystem.GetNrOfInstances(___m_offspringPrefab, ((Component)___m_baseAI).transform.position, __instance.m_totalCheckRange, false, false);
if (nrOfInstances + nrOfInstances2 < __instance.m_maxCreatures)
{
Dbgl("There is enough room in this space.");
}
if (SpawnSystem.GetNrOfInstances(___m_myPrefab, ((Component)___m_baseAI).transform.position, __instance.m_partnerCheckRange, false, true) < 2)
{
Dbgl("Mating pair not found.");
return;
}
Dbgl("No lovepoint change and there is a mating pair.");
int @int = ___m_nview.GetZDO().GetInt("lovePoints", 0);
Dbgl($"lovePoints: {@int}");
Dbgl($"requiredLovePoints: {__instance.m_requiredLovePoints}");
int num2 = 2 * __instance.m_requiredLovePoints - 2;
if (@int < num2)
{
float num3 = ((@int < num2 / 2) ? (0.5f + (float)@int) : ((@int == num2 / 2) ? ((float)(num2 / 2) - 0.25f) : ((float)Math.Abs(@int - num2) + 0.5f)));
num3 = num3 / (float)num2 * 2f;
Dbgl($"chanceForLoveBreed: {num3}");
float value = Random.value;
Dbgl($"randomRoll: {value}");
if (value <= num3)
{
Dbgl($"Setting lovePoints to {@int + 1}");
__instance.m_loveEffects.Create(((Component)___m_baseAI).transform.position, ((Component)___m_baseAI).transform.rotation, (Transform)null, 1f, -1);
___m_nview.GetZDO().Set("lovePoints", @int + 1);
}
}
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
{
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
__instance.AddString(text);
__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
return false;
}
return true;
}
}
public static ConfigEntry<bool> isDebug;
public static ConfigEntry<string> toggleKey;
public static ConfigEntry<string> toggleString;
public static ConfigEntry<bool> isOn;
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<int> nexusID;
private static BepInExPlugin context;
public static ManualLogSource MyLogger = Logger.CreateLogSource(Assembly.GetExecutingAssembly().GetName().Name);
private Harmony _harmony;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug.Value)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
context = this;
toggleKey = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ToggleKey", "", "Key to toggle behaviour. Leave blank to disable the toggle key. Use https://docs.unity3d.com/Manual/ConventionalGameInput.html");
toggleString = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ToggleString", "Breed for Love: {0}", "Text to show on toggle. {0} is replaced with true/false");
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
isDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IsDebug", false, "Show debug logs");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 985, "Nexus mod ID for updates");
isOn = ((BaseUnityPlugin)this).Config.Bind<bool>("ZAuto", "IsOn", true, "Behaviour is currently on or not");
if (modEnabled.Value)
{
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
}
private void Update()
{
if (AedenthornUtils.CheckKeyDown(toggleKey.Value) && !AedenthornUtils.IgnoreKeyPresses(extra: true))
{
isOn.Value = !isOn.Value;
((BaseUnityPlugin)this).Config.Save();
((Character)Player.m_localPlayer).Message((MessageType)2, string.Format(toggleString.Value, isOn.Value), 0, (Sprite)null);
}
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}