using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GTFO.API;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using SNetwork;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MotherBirthFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MotherBirthFix")]
[assembly: AssemblyTitle("MotherBirthFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace MotherBirthFix
{
[BepInPlugin("sourmonkis.MotherBirthFix", "MotherBirthFix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
public const string GUID = "sourmonkis.MotherBirthFix";
public const string NAME = "MotherBirthFix";
public const string VERSION = "1.0.0";
internal static ManualLogSource L;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> ReplayAnimation;
public override void Load()
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
L = ((BasePlugin)this).Log;
Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "A Mother that is staggered (or glued) while babies are still coming out goes back to standing still until the birth is done, instead of running around while they spawn. Only the host's mod changes this.");
ReplayAnimation = ((BasePlugin)this).Config.Bind<bool>("General", "ReplayBirthAnimation", true, "Play the give-birth animation again when she goes back to giving birth after the stagger. Host only: clients see her stand still, but may not see the animation.");
LevelAPI.OnLevelCleanup += BirthResume.Clear;
bool flag = default(bool);
try
{
new Harmony("sourmonkis.MotherBirthFix").PatchAll(typeof(Plugin).Assembly);
}
catch (Exception ex)
{
ManualLogSource log = ((BasePlugin)this).Log;
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Patching failed, ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MotherBirthFix");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is inactive: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
return;
}
ManualLogSource log2 = ((BasePlugin)this).Log;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("MotherBirthFix");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded");
}
log2.LogInfo(val2);
}
}
internal static class BirthResume
{
private const float FreshStartWindow = 1f;
private static readonly Dictionary<IntPtr, float> s_lastStart = new Dictionary<IntPtr, float>();
internal static void Clear()
{
s_lastStart.Clear();
}
internal static void MarkStart(ES_BirtherGiveBirth state)
{
s_lastStart[((Il2CppObjectBase)state).Pointer] = Time.time;
}
private static bool IsFreshStart(ES_BirtherGiveBirth state)
{
if (s_lastStart.TryGetValue(((Il2CppObjectBase)state).Pointer, out var value))
{
return Time.time - value < 1f;
}
return false;
}
internal static bool ShouldResume(EnemyLocomotion loco, ES_StateEnum newState)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Invalid comparison between Unknown and I4
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Invalid comparison between Unknown and I4
if (!Plugin.Enabled.Value || (int)newState != 2 || !SNet.IsMaster)
{
return false;
}
ES_BirtherGiveBirth birtherGiveBirth = loco.BirtherGiveBirth;
if (birtherGiveBirth == null)
{
return false;
}
ES_StateEnum currentStateEnum = loco.CurrentStateEnum;
if ((int)currentStateEnum == 26 || (int)currentStateEnum == 11)
{
return false;
}
EAB_Birthing triggeringAbility = birtherGiveBirth.m_triggeringAbility;
if ((Object)(object)triggeringAbility != (Object)null)
{
return triggeringAbility.IsBirthing();
}
return false;
}
internal static void ReplayAnimation(ES_BirtherGiveBirth state)
{
if (Plugin.Enabled.Value && Plugin.ReplayAnimation.Value && !IsFreshStart(state))
{
EnemyLocomotion locomotion = ((ES_Base)state).m_locomotion;
EnemyAgent enemyAgent = ((ES_Base)state).m_enemyAgent;
if (!((Object)(object)locomotion == (Object)null) && !((Object)(object)locomotion.m_animator == (Object)null) && !((Object)(object)enemyAgent == (Object)null) && enemyAgent.EnemyMovementData != null)
{
locomotion.m_animator.applyRootMotion = true;
locomotion.m_animator.CrossFadeInFixedTime(EnemyLocomotion.s_hashGiveBirth, enemyAgent.EnemyMovementData.BlendIntoAttackAnim);
}
}
}
}
[HarmonyPatch(typeof(EnemyLocomotion), "ChangeState")]
internal static class Patch_ChangeState
{
private static void Prefix(EnemyLocomotion __instance, ref ES_StateEnum state)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
try
{
if (BirthResume.ShouldResume(__instance, state))
{
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(55, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Mother left ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ES_StateEnum>(__instance.CurrentStateEnum);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" while still birthing, back to giving birth");
}
l.LogDebug(val);
state = (ES_StateEnum)26;
}
}
catch (Exception ex)
{
Plugin.L.LogError((object)ex);
}
}
}
[HarmonyPatch(typeof(ES_BirtherGiveBirth), "DoStartGiveBirth")]
internal static class Patch_DoStartGiveBirth
{
private static void Prefix(ES_BirtherGiveBirth __instance)
{
try
{
BirthResume.MarkStart(__instance);
}
catch (Exception ex)
{
Plugin.L.LogError((object)ex);
}
}
}
[HarmonyPatch(typeof(ES_BirtherGiveBirth), "Enter")]
internal static class Patch_Enter
{
private static void Postfix(ES_BirtherGiveBirth __instance)
{
try
{
BirthResume.ReplayAnimation(__instance);
}
catch (Exception ex)
{
Plugin.L.LogError((object)ex);
}
}
}
}