using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppFemur;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WeakerNpcGB;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::WeakerNpcGB.WeakerNpcGB), "WeakerNpcGB", "1.0.0", "zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WeakerNPCsGB")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WeakerNPCsGB")]
[assembly: AssemblyTitle("WeakerNPCsGB")]
[assembly: AssemblyVersion("1.0.0.0")]
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 WeakerNpcGB
{
public class ActorBases
{
public float liftStrength;
public float punchDamage;
public float punchForce;
public float health;
public float knockoutTime;
}
public class WeakerNpcGB : MelonMod
{
public const float LiftStrengthMult = 0.5f;
public const float PunchDamageMult = 0.5f;
public const float PunchForceMult = 0.2f;
public const float HealthMult = 0.1f;
public const float KnockoutTimeMult = 3f;
public static Dictionary<int, ActorBases> BaseStats = new Dictionary<int, ActorBases>();
private object? _pollCoroutine = null;
public override void OnInitializeMelon()
{
MelonLogger.Msg("WeakerNpcGB loaded.");
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
BaseStats.Clear();
if (_pollCoroutine != null)
{
MelonCoroutines.Stop(_pollCoroutine);
}
_pollCoroutine = MelonCoroutines.Start(PollForAIs());
}
private IEnumerator PollForAIs()
{
yield return (object)new WaitForSeconds(3f);
while (true)
{
yield return (object)new WaitForSeconds(2.2f);
Actor[] allActors = Il2CppArrayBase<Actor>.op_Implicit(Object.FindObjectsOfType<Actor>());
if (allActors == null || allActors.Length == 0)
{
continue;
}
Actor[] array = allActors;
foreach (Actor actor in array)
{
if (!((Object)(object)actor == (Object)null))
{
Traverse trv = Traverse.Create((object)actor);
if (IsDefinitelyAI(trv))
{
RefreshDebuffs(actor, trv);
}
}
}
}
}
private void RefreshDebuffs(Actor actor, Traverse trv)
{
int instanceID = ((Object)actor).GetInstanceID();
if (!BaseStats.TryGetValue(instanceID, out ActorBases value))
{
value = new ActorBases();
BaseStats[instanceID] = value;
}
float value2 = trv.Property("liftStrength", (object[])null).GetValue<float>();
if (value2 > value.liftStrength)
{
value.liftStrength = value2;
}
trv.Property("liftStrength", (object[])null).SetValue((object)(value.liftStrength * 0.5f));
float value3 = trv.Property("_punchDamageModifer", (object[])null).GetValue<float>();
if (value3 > value.punchDamage)
{
value.punchDamage = value3;
}
trv.Property("_punchDamageModifer", (object[])null).SetValue((object)(value.punchDamage * 0.5f));
float value4 = trv.Property("_punchForceModifer", (object[])null).GetValue<float>();
if (value4 > value.punchForce)
{
value.punchForce = value4;
}
trv.Property("_punchForceModifer", (object[])null).SetValue((object)(value.punchForce * 0.2f));
Traverse obj = trv.Property("statusHandeler", (object[])null);
object obj2 = ((obj != null) ? obj.GetValue() : null);
Traverse obj3 = trv.Property("bodyHandeler", (object[])null);
object obj4 = ((obj3 != null) ? obj3.GetValue() : null);
float maxStat = GetMaxStat(obj2, obj4, "health", "maxHealth", "hp", "maxHp");
if (maxStat > value.health)
{
value.health = maxStat;
}
if (value.health > 0f)
{
SetStatValue(obj2, value.health * 0.1f, "health", "maxHealth", "hp", "maxHp");
SetStatValue(obj4, value.health * 0.1f, "health", "maxHealth", "hp", "maxHp");
}
float maxStat2 = GetMaxStat(obj2, obj4, "knockoutTime", "koTime", "downTime", "recoveryTime", "getUpTime");
if (maxStat2 > value.knockoutTime)
{
value.knockoutTime = maxStat2;
}
if (value.knockoutTime > 0f)
{
SetStatValue(obj2, value.knockoutTime * 3f, "knockoutTime", "koTime", "downTime", "recoveryTime", "getUpTime");
SetStatValue(obj4, value.knockoutTime * 3f, "knockoutTime", "koTime", "downTime", "recoveryTime", "getUpTime");
}
}
private bool IsDefinitelyAI(Traverse trv)
{
Traverse val = trv.Property("isTrackedByCamera", (object[])null);
if (val.PropertyExists() && val.GetValue<bool>())
{
return false;
}
Traverse val2 = trv.Property("IsAI", (object[])null);
if (val2.PropertyExists() && val2.GetValue<bool>())
{
return true;
}
Traverse val3 = trv.Property("isAI", (object[])null);
if (val3.PropertyExists() && val3.GetValue<bool>())
{
return true;
}
Traverse val4 = trv.Property("_aiMember", (object[])null);
if (val4.PropertyExists() && val4.GetValue<bool>())
{
return true;
}
Traverse val5 = trv.Property("_controlledBy", (object[])null);
if (val5.PropertyExists())
{
string text = val5.GetValue<object>()?.ToString()?.ToLower() ?? "";
if (text == "ai" || text == "cpu" || text == "bot")
{
return true;
}
}
Traverse val6 = trv.Property("_aiProfile", (object[])null);
if (val6.PropertyExists() && val6.GetValue() != null)
{
return true;
}
return false;
}
private float GetMaxStat(object? target1, object? target2, params string[] names)
{
float statValue = GetStatValue(target1, names);
float statValue2 = GetStatValue(target2, names);
return Mathf.Max(statValue, statValue2);
}
private float GetStatValue(object? target, params string[] names)
{
if (target == null)
{
return 0f;
}
Traverse val = Traverse.Create(target);
foreach (string text in names)
{
Traverse val2 = val.Field(text);
if (val2.FieldExists())
{
return val2.GetValue<float>();
}
Traverse val3 = val.Property(text, (object[])null);
if (val3.PropertyExists())
{
return val3.GetValue<float>();
}
}
return 0f;
}
private void SetStatValue(object? target, float value, params string[] names)
{
if (target == null)
{
return;
}
Traverse val = Traverse.Create(target);
foreach (string text in names)
{
Traverse val2 = val.Field(text);
if (val2.FieldExists())
{
val2.SetValue((object)value);
break;
}
Traverse val3 = val.Property(text, (object[])null);
if (val3.PropertyExists())
{
val3.SetValue((object)value);
break;
}
}
}
}
}