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] [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 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) : ((UpgradeID?)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) : ((UpgradeID?)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; int num = PlayerData.Instance.targetsKilled - _killsStart; if (num > 0 && __instance.Cooldown != null) { __instance.Cooldown.AddCharge(Mathf.Min(1f, 0.25f * (float)_activeStacks * (float)num)); 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 { public override IEnumerator 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) int stacks = KillingSpreePlugin.GetStackCount(gear); int dispStacks = ((stacks == 0) ? 1 : stacks); bool hasSynergy = KillingSpreePlugin.IsKneeDiveEquipped(gear); float baseDmg = (hasSynergy ? 0.25f : 0.5f); float totalDmgVal = KillingSpreePlugin.GetTotalBonus(dispStacks, baseDmg) * 100f; string dmgStackInfo = ((dispStacks > 1) ? $" (x{dispStacks}: +{totalDmgVal:0.##}%)" : ""); string dmgSynergyText = (hasSynergy ? " (Low Efficiency)" : ""); yield return new StatData($"Damage: +{baseDmg * 100f}%{dmgStackInfo}{dmgSynergyText}"); float baseSize = (hasSynergy ? 1.5f : 0.5f); float totalSizeVal = KillingSpreePlugin.GetTotalBonus(dispStacks, baseSize) * 100f; string sizeStackInfo = ((dispStacks > 1) ? $" (x{dispStacks}: +{totalSizeVal:0.##}%)" : ""); string sizeSynergyText = (hasSynergy ? " (Knee-Dive Bonus)" : " (Base: 50% | Synergy: 200%)"); yield return new StatData($"Size: +{baseSize * 100f}%{sizeStackInfo}{sizeSynergyText}"); string refStackInfo = ((dispStacks > 1) ? $" (x{dispStacks}: {Mathf.Min(100, 25 * dispStacks)}%)" : ""); yield return new StatData("Refund/Kill: 25%" + refStackInfo); if (upgrade != null && upgrade.IsTurbocharged) { yield return new StatData("\nTurbocharged\nOverhealth: +10\n"); } } public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade) { return "Turbocharged\nOverhealth: +10"; } public override void Apply(Player p, UpgradeInstance u, ref Random r) { } public override void Remove(Player p, Player pf, UpgradeInstance i, ref Random r) { } } }