using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Math;
using Pigeon.Movement;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 KillingSpreeMod
{
[BepInPlugin("com.coloron.killingspree", "Killing Spree", "1.0.2")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class KillingSpreePlugin : BaseUnityPlugin
{
public const string PluginGUID = "com.coloron.killingspree";
public const string PluginName = "Killing Spree";
public const string PluginVersion = "1.0.2";
public const int ModUpgradeID = 88888;
public const string TARGET_PROPERTY_CLASS = "UpgradeProperty_Bruiser_NoseDiveDamage";
public static KillingSpreePlugin Instance;
public static Upgrade CustomUpgradeInstance;
public static IUpgradable BruiserRef;
public static Sprite AbilityIcon;
private void Awake()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading Killing Spree...");
LoadExternalIcon();
new Harmony("com.coloron.killingspree").PatchAll();
PlayerData.AddRegisterUpgradesCallback((Action)InitializeUpgrades);
}
private void LoadExternalIcon()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "killingspree.png");
if (!File.Exists(path))
{
return;
}
try
{
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(2, 2);
MethodInfo methodInfo = typeof(Texture2D).GetMethod("LoadImage", new Type[1] { typeof(byte[]) });
if (methodInfo == null)
{
methodInfo = Assembly.Load("UnityEngine.ImageConversionModule")?.GetType("UnityEngine.ImageConversion")?.GetMethod("LoadImage", new Type[2]
{
typeof(Texture2D),
typeof(byte[])
});
}
methodInfo?.Invoke(val, new object[2] { val, array });
AbilityIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Icon Load Failed: " + ex.Message));
}
}
private static void InitializeUpgrades()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
BruiserRef = PlayerData.FindGear("Bruiser");
if (BruiserRef != null)
{
CustomUpgradeParams val = CustomUpgradeParams.Create(BruiserRef, 88888, "Killing Spree", "Increases damage and radius of the nose dive. Kills refund nose dive charge.", (Rarity)3, (Sprite)null);
if ((Object)(object)AbilityIcon != (Object)null)
{
val.icon = AbilityIcon;
}
ref UpgradeFlags flags = ref val.flags;
flags = (UpgradeFlags)((uint)flags | 0x2008u);
CustomUpgradeInstance = PlayerData.CreateUpgrade("com.coloron.killingspree", val, (UpgradeProperty[])(object)new UpgradeProperty[1]
{
new UpgradeProperty_KillingSpree()
});
ApplyCustomPattern(CustomUpgradeInstance);
}
}
private static void ApplyCustomPattern(Upgrade upgrade)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)upgrade == (Object)null))
{
HexMap val = new HexMap(3, 3);
val[0, 1].enabled = true;
val[0, 1].connections = (Direction)10;
val[0, 2].enabled = true;
val[0, 2].connections = (Direction)4;
val[1, 0].enabled = true;
val[1, 1].enabled = true;
val[1, 1].connections = (Direction)57;
val[1, 2].enabled = true;
SetPrivateField(upgrade, "pattern", val);
}
}
public static float GetTotalBonus(int count, float baseValue)
{
float num = 0f;
for (int i = 1; i <= count; i++)
{
num = ((i > 2) ? (num + baseValue / Mathf.Pow(2f, (float)(i - 2))) : (num + baseValue));
}
return num;
}
public static int GetStackCount(IUpgradable gear)
{
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
if (gear == null || (Object)(object)CustomUpgradeInstance == (Object)null)
{
return 0;
}
GearData gearData = PlayerData.GetGearData(gear);
if (gearData == null)
{
return 0;
}
try
{
IEnumerable enumerable = (IEnumerable)(typeof(GearData).GetField("equippedUpgrades", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(gearData));
if (enumerable == null)
{
return 0;
}
int num = 0;
foreach (object item in enumerable)
{
int num2 = (int)item.GetType().GetField("upgradeID").GetValue(item);
UpgradeInstance upgradeInstanceFromID = PlayerData.GetUpgradeInstanceFromID(num2);
UpgradeID? obj;
if (upgradeInstanceFromID == null)
{
obj = null;
}
else
{
Upgrade upgrade = upgradeInstanceFromID.Upgrade;
obj = ((upgrade != null) ? new UpgradeID?(upgrade.ID) : null);
}
UpgradeID? val = obj;
UpgradeID iD = CustomUpgradeInstance.ID;
if (val.HasValue && val.GetValueOrDefault() == iD)
{
num++;
}
}
return num;
}
catch
{
return 0;
}
}
public static bool IsTurboActive(IUpgradable gear)
{
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
if (gear == null || (Object)(object)CustomUpgradeInstance == (Object)null)
{
return false;
}
try
{
GearData gearData = PlayerData.GetGearData(gear);
IEnumerable enumerable = (IEnumerable)(typeof(GearData).GetField("equippedUpgrades", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(gearData));
if (enumerable == null)
{
return false;
}
foreach (object item in enumerable)
{
int num = (int)item.GetType().GetField("upgradeID").GetValue(item);
UpgradeInstance upgradeInstanceFromID = PlayerData.GetUpgradeInstanceFromID(num);
UpgradeID? obj;
if (upgradeInstanceFromID == null)
{
obj = null;
}
else
{
Upgrade upgrade = upgradeInstanceFromID.Upgrade;
obj = ((upgrade != null) ? new UpgradeID?(upgrade.ID) : null);
}
UpgradeID? val = obj;
UpgradeID iD = CustomUpgradeInstance.ID;
if (val.HasValue && val.GetValueOrDefault() == iD && upgradeInstanceFromID.IsTurbocharged)
{
return true;
}
}
}
catch
{
}
return false;
}
public static bool IsKneeDiveEquipped(IUpgradable gear)
{
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
if (gear == null)
{
return false;
}
try
{
GearData gearData = PlayerData.GetGearData(gear);
IEnumerable enumerable = (IEnumerable)(typeof(GearData).GetField("equippedUpgrades", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(gearData));
if (enumerable == null)
{
return false;
}
foreach (object item in enumerable)
{
int num = (int)item.GetType().GetField("upgradeID").GetValue(item);
UpgradeInstance upgradeInstanceFromID = PlayerData.GetUpgradeInstanceFromID(num);
if ((Object)(object)((upgradeInstanceFromID != null) ? upgradeInstanceFromID.Upgrade : null) == (Object)null)
{
continue;
}
UpgradePropertyList properties = upgradeInstanceFromID.Upgrade.Properties;
foreach (UpgradeProperty item2 in (UpgradePropertyList)(ref properties))
{
if (((object)item2)?.GetType().Name == "UpgradeProperty_Bruiser_NoseDiveDamage" && (((Object)upgradeInstanceFromID.Upgrade).name.Contains("Knee") || upgradeInstanceFromID.Upgrade.GetInstanceName(0).Contains("Knee")))
{
return true;
}
}
}
}
catch
{
}
return false;
}
public static void ApplyOverhealth(Player p, float amount)
{
if ((Object)(object)p == (Object)null)
{
return;
}
try
{
Type typeFromHandle = typeof(Player);
FieldInfo field = typeFromHandle.GetField("health", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo field2 = typeFromHandle.GetField("maxHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo field3 = typeFromHandle.GetField("lastOverhealthGainTime", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
float num = (float)field.GetValue(p);
float num2 = (float)field2.GetValue(p);
float num3 = num2 + 100f;
float num4 = Mathf.Min(num + amount, num3);
field.SetValue(p, num4);
field3?.SetValue(p, Time.time);
}
catch (Exception ex)
{
KillingSpreePlugin instance = Instance;
if (instance != null)
{
((BaseUnityPlugin)instance).Logger.LogWarning((object)("ApplyOverhealth failed: " + ex.Message));
}
}
}
public static bool SetPrivateField(object target, string name, object value)
{
Type type = target.GetType();
FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
while (field == null && type.BaseType != null)
{
type = type.BaseType;
field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
if (field != null)
{
field.SetValue(target, value);
return true;
}
return false;
}
}
[HarmonyPatch(typeof(NoseDiveUpgrade), "EndDiveSlam")]
public static class NoseDivePatch
{
private static float _origDmg;
private static float _origRad;
private static int _killsStart;
private static int _activeStacks;
private static void Prefix(NoseDiveUpgrade __instance, ref bool __state)
{
__state = false;
if (!((Object)(object)Player.LocalPlayer == (Object)null) && KillingSpreePlugin.BruiserRef != null && !((Object)(object)KillingSpreePlugin.CustomUpgradeInstance == (Object)null))
{
_activeStacks = KillingSpreePlugin.GetStackCount(KillingSpreePlugin.BruiserRef);
if (_activeStacks > 0)
{
ref Data noseDiveData = ref __instance.NoseDiveData;
_origDmg = noseDiveData.landDamage.damage;
_origRad = noseDiveData.landDamageRadius;
_killsStart = PlayerData.Instance.targetsKilled;
bool flag = KillingSpreePlugin.IsKneeDiveEquipped(KillingSpreePlugin.BruiserRef);
noseDiveData.landDamage.damage *= 1f + KillingSpreePlugin.GetTotalBonus(_activeStacks, flag ? 0.25f : 0.5f);
noseDiveData.landDamageRadius *= 1f + KillingSpreePlugin.GetTotalBonus(_activeStacks, flag ? 1.5f : 0.5f);
__state = true;
}
}
}
private static void Postfix(NoseDiveUpgrade __instance, bool __state)
{
if (!__state)
{
return;
}
__instance.NoseDiveData.landDamage.damage = _origDmg;
__instance.NoseDiveData.landDamageRadius = _origRad;
if (PlayerData.Instance.targetsKilled > _killsStart && __instance.Cooldown != null)
{
__instance.Cooldown.AddCharge(Mathf.Min(1f, 0.25f * (float)_activeStacks));
PlayerLook instance = PlayerLook.Instance;
if (instance != null)
{
instance.GetRechargeUI((IActivatedAbility)(object)__instance.Cooldown).UpdateBackgroundColor();
}
}
if (KillingSpreePlugin.IsTurboActive(KillingSpreePlugin.BruiserRef))
{
KillingSpreePlugin.ApplyOverhealth(Player.LocalPlayer, 10f);
}
}
}
[Serializable]
public class UpgradeProperty_KillingSpree : UpgradeProperty
{
[CompilerGenerated]
private sealed class <GetStatData>d__0 : IEnumerator<StatData>, IDisposable, IEnumerator
{
private int <>1__state;
private StatData <>2__current;
public Random rand;
public IUpgradable gear;
public UpgradeInstance upgrade;
public UpgradeProperty_KillingSpree <>4__this;
private int <stacks>5__1;
private int <dispStacks>5__2;
private bool <hasSynergy>5__3;
private float <baseDmg>5__4;
private float <totalDmgVal>5__5;
private string <dmgStackInfo>5__6;
private string <dmgSynergyText>5__7;
private float <baseSize>5__8;
private float <totalSizeVal>5__9;
private string <sizeStackInfo>5__10;
private string <sizeSynergyText>5__11;
private string <refStackInfo>5__12;
StatData IEnumerator<StatData>.Current
{
[DebuggerHidden]
get
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return <>2__current;
}
}
[DebuggerHidden]
public <GetStatData>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<dmgStackInfo>5__6 = null;
<dmgSynergyText>5__7 = null;
<sizeStackInfo>5__10 = null;
<sizeSynergyText>5__11 = null;
<refStackInfo>5__12 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<stacks>5__1 = KillingSpreePlugin.GetStackCount(gear);
<dispStacks>5__2 = ((<stacks>5__1 == 0) ? 1 : <stacks>5__1);
<hasSynergy>5__3 = KillingSpreePlugin.IsKneeDiveEquipped(gear);
<baseDmg>5__4 = (<hasSynergy>5__3 ? 0.25f : 0.5f);
<totalDmgVal>5__5 = KillingSpreePlugin.GetTotalBonus(<dispStacks>5__2, <baseDmg>5__4) * 100f;
<dmgStackInfo>5__6 = ((<dispStacks>5__2 > 1) ? $" <color=#888888>(x{<dispStacks>5__2}: <b>+{<totalDmgVal>5__5:0.##}%</b>)</color>" : "");
<dmgSynergyText>5__7 = (<hasSynergy>5__3 ? " <color=#fffb2e>(Low Efficiency)</color>" : "");
<>2__current = new StatData($"Damage: <b>+{<baseDmg>5__4 * 100f}%</b>{<dmgStackInfo>5__6}{<dmgSynergyText>5__7}");
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<baseSize>5__8 = (<hasSynergy>5__3 ? 1.5f : 0.5f);
<totalSizeVal>5__9 = KillingSpreePlugin.GetTotalBonus(<dispStacks>5__2, <baseSize>5__8) * 100f;
<sizeStackInfo>5__10 = ((<dispStacks>5__2 > 1) ? $" <color=#888888>(x{<dispStacks>5__2}: <b>+{<totalSizeVal>5__9:0.##}%</b>)</color>" : "");
<sizeSynergyText>5__11 = (<hasSynergy>5__3 ? " <color=green>(Knee-Dive Bonus)</color>" : " <color=grey>(Base: 50% | Synergy: 200%)</color>");
<>2__current = new StatData($"Size: <b>+{<baseSize>5__8 * 100f}%</b>{<sizeStackInfo>5__10}{<sizeSynergyText>5__11}");
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<refStackInfo>5__12 = ((<dispStacks>5__2 > 1) ? $" <color=#888888>(x{<dispStacks>5__2}: <b>{Mathf.Min(100, 25 * <dispStacks>5__2)}%</b>)</color>" : "");
<>2__current = new StatData("Refund/Kill: <b>25%</b>" + <refStackInfo>5__12);
<>1__state = 3;
return true;
case 3:
<>1__state = -1;
if (upgrade != null && upgrade.IsTurbocharged)
{
<>2__current = new StatData("\n<color=red><b>Turbocharged</b></color>\nOverhealth: <b>+10</b>\n");
<>1__state = 4;
return true;
}
break;
case 4:
<>1__state = -1;
break;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[IteratorStateMachine(typeof(<GetStatData>d__0))]
public override IEnumerator<StatData> GetStatData(Random rand, IUpgradable gear, UpgradeInstance upgrade)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GetStatData>d__0(0)
{
<>4__this = this,
rand = rand,
gear = gear,
upgrade = upgrade
};
}
public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade)
{
return "<color=red>Turbocharged</color>\nOverhealth: <b>+10</b>";
}
public override void Apply(Player p, UpgradeInstance u, ref Random r)
{
}
public override void Remove(Player p, Player pf, UpgradeInstance i, ref Random r)
{
}
}
}