using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AIGraph;
using Agents;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using Enemies;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Player;
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("OldTumorDamage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OldTumorDamage")]
[assembly: AssemblyTitle("OldTumorDamage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace OldTumorDamage
{
[BepInPlugin("OldTumorDamage", "OldTumorDamage", "0.0.8")]
public class Plugin : BasePlugin
{
[HarmonyPatch(typeof(EnemyAllocator), "SpawnEnemy")]
internal class OldTumorDamage_Patch1
{
[HarmonyPostfix]
public static void Postfix(EnemyAllocator __instance, uint persistantID, AIG_CourseNode courseNode, AgentMode mode, Vector3 position, Quaternion rotation, EnemyGroup group = null, int placementIndex = -1)
{
Il2CppArrayBase<Dam_EnemyDamageLimb_Custom> componentsInChildren = ((Component)__instance.m_spawnedEnemyAgent).gameObject.GetComponentsInChildren<Dam_EnemyDamageLimb_Custom>();
if (componentsInChildren == null)
{
return;
}
foreach (Dam_EnemyDamageLimb_Custom item in componentsInChildren)
{
Dam_EnemyDamageLimb_Custom val = ((Il2CppObjectBase)item).TryCast<Dam_EnemyDamageLimb_Custom>();
if ((Object)(object)val != (Object)null)
{
val.m_clampDamageToLimbHealth = true;
}
}
}
}
[HarmonyPatch(typeof(Dam_EnemyDamageBase), "ReceiveBulletDamage")]
internal class OldTumorDamage_Patch2
{
[HarmonyPrefix]
public static bool Prefix(Dam_EnemyDamageBase __instance, ref pBulletDamageData data)
{
Agent val = default(Agent);
((pAgent)(ref data.source)).TryGet(ref val);
if ((Object)(object)((Il2CppObjectBase)val).TryCast<PlayerAgent>() != (Object)null && data.limbID > 0)
{
Dam_EnemyDamageLimb_Custom val2 = ((Il2CppObjectBase)((Il2CppArrayBase<Dam_EnemyDamageLimb>)(object)__instance.DamageLimbs)[(int)data.limbID]).TryCast<Dam_EnemyDamageLimb_Custom>();
if ((Object)(object)val2 != (Object)null)
{
float num = ((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).HealthMax);
float num2 = AgentModifierManager.ApplyModifier((Agent)(object)__instance.Owner, (AgentModifier)7, num);
float num3 = num2 / num;
if (num2 > ((Dam_EnemyDamageLimb)val2).m_health && !_oldDamage)
{
((UFloat16)(ref data.damage)).Set(((Dam_EnemyDamageLimb)val2).m_health / num3 + 1.5259022E-05f * ((Dam_SyncedDamageBase)__instance).HealthMax, ((Dam_SyncedDamageBase)__instance).HealthMax);
Debug.Log(Object.op_Implicit("capped damage to enemy tumor remaining health"));
}
if (num2 > ((Dam_EnemyDamageLimb)val2).m_health && _oldDamage)
{
if (num2 > ((Dam_EnemyDamageLimb)val2).m_healthMax)
{
((UFloat16)(ref data.damage)).Set(((Dam_EnemyDamageLimb)val2).m_healthMax, ((Dam_SyncedDamageBase)__instance).HealthMax);
}
Debug.Log(Object.op_Implicit($"applied {((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).HealthMax)} instead of {num2} to tumor due to old damage model"));
}
}
}
return true;
}
}
public static bool _oldDamage;
public override void Load()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_003a: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Expected O, but got Unknown
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Expected O, but got Unknown
ConfigEntry<bool> val = new ConfigFile(Path.Combine(Paths.ConfigPath, "OldTumorDamage.cfg"), true).Bind<bool>(new ConfigDefinition("General", "Use_Old_Damage_Model"), false, new ConfigDescription("Use the pre-R8 damage model? (damaged tumor can be inflicted up to MaxHealth worth of damage", (AcceptableValueBase)null, Array.Empty<object>()));
_oldDamage = val.Value;
Harmony val2 = new Harmony("OldTumorDamage");
MethodInfo method = typeof(EnemyAllocator).GetMethod("SpawnEnemy");
MethodInfo method2 = typeof(Dam_EnemyDamageBase).GetMethod("ReceiveBulletDamage");
MethodInfo method3 = typeof(OldTumorDamage_Patch1).GetMethod("Postfix");
MethodInfo method4 = typeof(OldTumorDamage_Patch2).GetMethod("Prefix");
Debug.Log(Object.op_Implicit($"OldTumorDamage configuration old tumor damage: {val.Value}"));
if (!((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("Endskill.EndskApi", out var _))
{
val2.Patch((MethodBase)method2, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Debug.Log(Object.op_Implicit("we have patched receivebulletdamage, Endskill.EndskApi is absent"));
}
if (!val.Value)
{
val2.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
if (!val.Value)
{
Debug.Log(Object.op_Implicit("OldTumorDamage: patched SpawnEnemy, tumor damage clamping applied"));
}
if (val.Value)
{
Debug.Log(Object.op_Implicit("OldTumorDamage: we are not patching SpawnEnemy tumor damage clamping due to old damage model"));
}
if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("Endskill.EndskApi", out var _) && val.Value)
{
Debug.Log(Object.op_Implicit("THIS MOD IS DISABLED DUE TO OLD DAMAGE MODEL AND GTFUCKINGXP PRESENT"));
}
}
}
[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
[CompilerGenerated]
internal static class VersionInfo
{
public const string RootNamespace = "OldTumorDamage";
public const string Version = "1.0.0";
public const string VersionPrerelease = null;
public const string VersionMetadata = null;
public const string SemVer = "1.0.0";
public const string GitRevShort = null;
public const string GitRevLong = null;
public const string GitBranch = null;
public const string GitTag = null;
public const bool GitIsDirty = false;
}
}