using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;
using SuperFantasyKingdom;
using SuperFantasyKingdom.Projectile;
using SuperFantasyKingdom.Status;
using SuperFantasyKingdom.UI;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CursedEquipment")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.5.0")]
[assembly: AssemblyInformationalVersion("0.2.5+eb559428d1d81f6240a8aa5a187127c3dd9b4969")]
[assembly: AssemblyProduct("CursedEquipment")]
[assembly: AssemblyTitle("CursedEquipment")]
[assembly: AssemblyVersion("0.2.5.0")]
namespace CursedEquipment;
[HarmonyPatch]
internal static class Arsenal
{
private sealed class Wearer
{
internal MonsterBaseHealth PreviousTarget;
internal int Followups;
internal int EmberHits;
internal int HaloDay = -1;
internal float HaloBlockUntil;
internal float HaloPenaltyUntil;
}
private static ConditionalWeakTable<UnitBase, Wearer> wearers = new ConditionalWeakTable<UnitBase, Wearer>();
private static ConditionalWeakTable<MonsterBaseHealth, Dictionary<int, float>> recentHits = new ConditionalWeakTable<MonsterBaseHealth, Dictionary<int, float>>();
private static BurnStatusScriptableObject burn;
internal static float Now { get; set; }
internal static float ScaleHit(MonsterBaseHealth target, UnitBase source, bool status, float amount)
{
Wearer orCreateValue = wearers.GetOrCreateValue(source);
if (Catalog.Wears((Entity)(object)source, "GKJ_CE_BorrowedHalo") && Now < orCreateValue.HaloPenaltyUntil)
{
amount *= 0.5f;
}
if (status)
{
return amount;
}
Dictionary<int, float> orCreateValue2 = recentHits.GetOrCreateValue(target);
int id = ((Entity)source).GetIdentifier();
if (Catalog.Wears((Entity)(object)source, "GKJ_CE_GravediggersLantern"))
{
amount *= (orCreateValue2.Any((KeyValuePair<int, float> hit) => hit.Key != id && Now - hit.Value < 2f) ? 0.85f : 1.4f);
}
orCreateValue2[id] = Now;
float num = 1f;
if (orCreateValue.PreviousTarget == target)
{
orCreateValue.Followups = Math.Min(5, orCreateValue.Followups + 1);
num += (float)orCreateValue.Followups * 0.1f;
}
else
{
if (orCreateValue.PreviousTarget != null)
{
num = 0.7f;
}
orCreateValue.PreviousTarget = target;
orCreateValue.Followups = 0;
}
if (Catalog.Wears((Entity)(object)source, "GKJ_CE_DuelistsFang"))
{
amount *= num;
}
if (Catalog.Wears((Entity)(object)source, "GKJ_CE_HangmansQuarrel"))
{
amount *= ((((Health)target).GetHealthPercentageAbs() < 0.2f) ? 1.6f : 0.85f);
}
return amount;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Health), "TakeHealthDamage")]
private static bool ProtectWearer(Health __instance, ref float takeDamage, ref float __result)
{
UnitHealth val = (UnitHealth)(object)((__instance is UnitHealth) ? __instance : null);
if (val != null)
{
Entity entity = ((Health)val).GetEntity();
UnitBase val2 = (UnitBase)(object)((entity is UnitBase) ? entity : null);
if (val2 != null && !(((Health)val).GetHitpoints() <= 0f) && !(takeDamage <= 0f))
{
float hitpoints = ((Health)val).GetHitpoints();
takeDamage = ReduceHealthDamage(val2, val, hitpoints, takeDamage);
if (Catalog.Wears((Entity)(object)val2, "GKJ_CE_BorrowedHalo"))
{
int day = (((Object)(object)DaytimeManager.Instance == (Object)null) ? (-1) : DaytimeManager.Instance.CurrentDay());
bool inCombat = (Object)(object)CombatManager.Instance != (Object)null && CombatManager.Instance.IsCombat();
takeDamage = ApplyHalo(val2, hitpoints, takeDamage, day, inCombat);
}
if (takeDamage > 0f)
{
return true;
}
__result = 0f;
return false;
}
}
return true;
}
private static float ReduceHealthDamage(UnitBase wearer, UnitHealth health, float hp, float amount)
{
if (Catalog.Wears((Entity)(object)wearer, "GKJ_CE_MartyrsPlate"))
{
amount *= 0.7f;
}
if (Catalog.Wears((Entity)(object)wearer, "GKJ_CE_LeadheartLocket") && hp < ((Health)health).GetMaxHealth() * 0.5f)
{
amount *= 0.65f;
}
return amount;
}
internal static float ApplyHalo(UnitBase wearer, float hp, float amount, int day, bool inCombat)
{
Wearer orCreateValue = wearers.GetOrCreateValue(wearer);
if (Now < orCreateValue.HaloBlockUntil)
{
return 0f;
}
if (day < 0 || !inCombat || day == orCreateValue.HaloDay || amount < hp)
{
return amount;
}
orCreateValue.HaloDay = day;
orCreateValue.HaloBlockUntil = Now + 2f;
orCreateValue.HaloPenaltyUntil = Now + 8f;
return Math.Max(0f, hp - 1f);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Health), "ReceiveHeal")]
private static bool LimitHeal(Health __instance, ref Heal heal, ref float __result)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Invalid comparison between Unknown and I4
UnitHealth val = (UnitHealth)(object)((__instance is UnitHealth) ? __instance : null);
if (val == null || heal.healAmount <= 0f || ((int)heal.healType != 0 && (int)heal.healType != 1))
{
return true;
}
Entity entity = ((Health)val).GetEntity();
if (Catalog.Wears(entity, "GKJ_CE_MartyrsPlate"))
{
heal.healAmount *= 0.5f;
}
if (!Catalog.Wears(entity, "GKJ_CE_LeadheartLocket"))
{
return true;
}
heal.healAmount = CapHeal(((Health)val).GetHitpoints(), ((Health)val).GetMaxHealth(), heal.healAmount);
if (heal.healAmount > 0f)
{
return true;
}
__result = 0f;
return false;
}
internal static float CapHeal(float current, float maximum, float requested)
{
if (!(maximum <= 0f))
{
return Math.Min(requested, Math.Max(0f, maximum * 0.75f - current));
}
return requested;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Health), "TakeHealthDamage")]
private static void Emberwake(Health __instance, Damage dmg, float __result)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
MonsterBaseHealth val = (MonsterBaseHealth)(object)((__instance is MonsterBaseHealth) ? __instance : null);
if (val == null || __result <= 0f || !((Health)val).IsAlive() || dmg.isStatus)
{
return;
}
Entity origin = dmg.origin;
UnitBase val2 = (UnitBase)(object)((origin is UnitBase) ? origin : null);
if (val2 == null || !Catalog.Wears((Entity)(object)val2, "GKJ_CE_EmberwakeBlade"))
{
return;
}
IHealth health = ((Entity)val2).GetHealth();
if (health == null || !health.IsAlive() || health.GetHitpoints() <= 0f)
{
return;
}
Wearer orCreateValue = wearers.GetOrCreateValue(val2);
if (++orCreateValue.EmberHits != 4)
{
return;
}
orCreateValue.EmberHits = 0;
float hitpoints = health.GetHitpoints();
if (hitpoints > 1f)
{
health.SetHitPoints(Math.Max(1f, hitpoints - health.GetMaxHealth() * 0.05f));
health.SetCurrentHealth();
UnitManager instance = UnitManager.Instance;
if (instance != null)
{
instance.UnitChange(val2);
}
}
((Health)val).GetEntity().GetStatusManager().AddStatus((StatusScriptableObject)(object)BurnAsset(), 1f, 1f, ((Entity)val2).GetIdentifier(), (Entity)(object)val2);
}
private static BurnStatusScriptableObject BurnAsset()
{
if ((Object)(object)burn != (Object)null)
{
return burn;
}
burn = ScriptableObject.CreateInstance<BurnStatusScriptableObject>();
Traverse.Create((object)burn).Field("amount").SetValue((object)1f);
Traverse.Create((object)burn).Field("duration").SetValue((object)4f);
return burn;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameDataManager), "Load")]
private static void Clear()
{
wearers = new ConditionalWeakTable<UnitBase, Wearer>();
recentHits = new ConditionalWeakTable<MonsterBaseHealth, Dictionary<int, float>>();
}
}
[HarmonyPatch]
internal static class CardFrame
{
private sealed class Trim
{
internal Image Clip;
internal Image IconField;
internal Image Sigil;
internal Image Ribbon;
internal Image Banner;
internal Color BannerColor;
internal Vector4 DescriptionMargin;
}
private static readonly ConditionalWeakTable<UICardItem, Trim> trims = new ConditionalWeakTable<UICardItem, Trim>();
private static Sprite frame;
private static Sprite iconField;
private static Sprite sigil;
private static Sprite ribbon;
private static readonly Regex signedPercent = new Regex("[+-][0-9]+%");
[HarmonyPrefix]
[HarmonyPatch(typeof(UICardItem), "Init")]
private static void Reset(UICardItem __instance, TextMeshProUGUI ___description)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
if (trims.TryGetValue(__instance, out var value) && ((Component)value.Clip).gameObject.activeSelf)
{
((Component)value.Clip).gameObject.SetActive(false);
if (Object.op_Implicit((Object)(object)value.IconField))
{
((Component)value.IconField).gameObject.SetActive(false);
}
((Component)value.Sigil).gameObject.SetActive(false);
if (Object.op_Implicit((Object)(object)value.Ribbon))
{
((Component)value.Ribbon).gameObject.SetActive(false);
((Graphic)value.Banner).color = value.BannerColor;
}
((TMP_Text)___description).margin = value.DescriptionMargin;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UICardItem), "Init")]
private static void Apply(UICardItem __instance, Item item, Image ___card, TextMeshProUGUI ___title, TextMeshProUGUI ___description)
{
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
if (Catalog.IsCursed(item) && Object.op_Implicit((Object)(object)___card))
{
Trim value = trims.GetValue(__instance, (UICardItem _) => CreateTrim(___card, ___title));
if (Object.op_Implicit((Object)(object)value.IconField))
{
((Component)value.IconField).gameObject.SetActive(true);
}
((Component)value.Sigil).gameObject.SetActive(true);
if (Object.op_Implicit((Object)(object)value.Ribbon))
{
value.BannerColor = ((Graphic)value.Banner).color;
Image banner = value.Banner;
((Graphic)banner).color = ((Graphic)banner).color * new Color(0.67f, 0.68f, 0.92f, 1f);
((Component)value.Ribbon).gameObject.SetActive(true);
}
value.DescriptionMargin = ((TMP_Text)___description).margin;
Vector3 val = ((Transform)((TMP_Text)___description).rectTransform).InverseTransformVector(((Transform)((Graphic)___card).rectTransform).TransformVector(new Vector3(1f, 1f, 0f)));
((TMP_Text)___description).margin = ((TMP_Text)___description).margin + new Vector4(8f * val.x, 2f * val.y, 12f * val.x, 6f * val.y);
((TMP_Text)___description).text = signedPercent.Replace(((TMP_Text)___description).text, "<nobr>$0</nobr>");
CopyShape(___card, value.Clip);
((Component)value.Clip).gameObject.SetActive(true);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UICardItem), "OnEnter")]
private static void Hover(UICardItem __instance, Image ___card)
{
Change(__instance, ___card);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UICardItem), "OnSelect")]
private static void Select(UICardItem __instance, Image ___card)
{
Change(__instance, ___card);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UICardItem), "OnDeselect")]
private static void Deselect(UICardItem __instance, Image ___card)
{
Change(__instance, ___card);
}
private static void Change(UICardItem __instance, Image ___card)
{
if (trims.TryGetValue(__instance, out var value) && ((Component)value.Clip).gameObject.activeSelf)
{
CopyShape(___card, value.Clip);
}
}
private static void CopyShape(Image surface, Image clip)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
clip.sprite = surface.overrideSprite;
clip.type = surface.type;
clip.fillCenter = surface.fillCenter;
clip.pixelsPerUnitMultiplier = surface.pixelsPerUnitMultiplier;
clip.preserveAspect = surface.preserveAspect;
clip.useSpriteMesh = surface.useSpriteMesh;
clip.fillMethod = surface.fillMethod;
clip.fillOrigin = surface.fillOrigin;
clip.fillClockwise = surface.fillClockwise;
clip.fillAmount = surface.fillAmount;
}
private static Trim CreateTrim(Image surface, TextMeshProUGUI title)
{
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
Image val = CreateImage("Cursed Equipment Clip", ((Graphic)surface).rectTransform);
((Component)val).transform.SetAsFirstSibling();
((Component)val).gameObject.AddComponent<Mask>().showMaskGraphic = false;
CreateImage("Cursed Equipment Art", ((Graphic)val).rectTransform).sprite = frame ?? (frame = Catalog.LoadSprite("frames", "shared-trim"));
Trim trim = new Trim
{
Clip = val
};
Transform obj = ((Component)surface).transform.Find("BG");
RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
if (Object.op_Implicit((Object)(object)val2))
{
(trim.IconField = CreateImage("Cursed Equipment Icon Field", val2)).sprite = iconField ?? (iconField = Catalog.LoadSprite("frames", "shared-icon-field"));
}
trim.Sigil = CreateImage("Cursed Equipment Sigil", ((Graphic)surface).rectTransform, new Vector2(0.81f, 0.76f), new Vector2(0.9f, 0.85f));
trim.Sigil.sprite = sigil ?? (sigil = Catalog.LoadSprite("frames", "shared-sigil"));
RectTransform val3 = (RectTransform)(Object.op_Implicit((Object)(object)title) ? /*isinst with value type is only supported in some contexts*/: null);
if (Object.op_Implicit((Object)(object)val3) && ((Component)val3).TryGetComponent<Image>(ref trim.Banner))
{
trim.Ribbon = CreateImage("Cursed Equipment Ribbon", val3, new Vector2(0.025f, 0.355f), new Vector2(0.975f, 0.786f));
trim.Ribbon.sprite = ribbon ?? (ribbon = Catalog.LoadSprite("frames", "shared-banner"));
((Component)trim.Ribbon).transform.SetAsFirstSibling();
}
return trim;
}
private static Image CreateImage(string name, RectTransform parent)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
return CreateImage(name, parent, Vector2.zero, Vector2.one);
}
private static Image CreateImage(string name, RectTransform parent, Vector2 from, Vector2 to)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
Image component = new GameObject(name, new Type[2]
{
typeof(RectTransform),
typeof(Image)
}).GetComponent<Image>();
RectTransform rectTransform = ((Graphic)component).rectTransform;
((Transform)rectTransform).SetParent((Transform)(object)parent, false);
rectTransform.pivot = parent.pivot;
rectTransform.anchorMin = from;
rectTransform.anchorMax = to;
Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero);
rectTransform.offsetMin = offsetMin;
((Graphic)component).raycastTarget = false;
return component;
}
}
[HarmonyPatch]
internal static class Catalog
{
internal const string Glass = "GKJ_CE_CrackedSpellglass";
internal const string Cup = "GKJ_CE_BitterChalice";
internal const string Mirror = "GKJ_CE_CrackedDuelistsMirror";
internal const string Fang = "GKJ_CE_DuelistsFang";
internal const string Plate = "GKJ_CE_MartyrsPlate";
internal const string Lantern = "GKJ_CE_GravediggersLantern";
internal const string Quarrel = "GKJ_CE_HangmansQuarrel";
internal const string Blade = "GKJ_CE_EmberwakeBlade";
internal const string Locket = "GKJ_CE_LeadheartLocket";
internal const string Halo = "GKJ_CE_BorrowedHalo";
private static readonly Dictionary<string, (string title, string gift, string curse, string art)> Cards = new Dictionary<string, (string, string, string, string)>
{
["GKJ_CE_CrackedSpellglass"] = ("Cracked Spellglass", "Damaging circles gain 40% radius.", "Each target takes 20% less damage.", "glass"),
["GKJ_CE_BitterChalice"] = ("Bitter Chalice", "Receive 50% more healing.", "Heals arrive 3 seconds late.", "chalice"),
["GKJ_CE_CrackedDuelistsMirror"] = ("Cracked Duelist's Mirror", "Double the first hit to each monster's health.", "Later hits deal 25% less.", "mirror"),
["GKJ_CE_DuelistsFang"] = ("Duelist's Fang", "+10% damage per repeat hit, up to +50%.", "Switching targets costs 30% damage on that hit.", "fang"),
["GKJ_CE_MartyrsPlate"] = ("Martyr's Plate", "Take 30% less Health damage.", "Receive 50% less healing.", "plate"),
["GKJ_CE_GravediggersLantern"] = ("Gravedigger's Lantern", "+40% damage to lone targets.", "-15% if an ally hit the target in the last 2s.", "lantern"),
["GKJ_CE_HangmansQuarrel"] = ("Hangman's Quarrel", "+60% damage to foes below 20% Health.", "-15% against healthier foes.", "quarrel"),
["GKJ_CE_EmberwakeBlade"] = ("Emberwake Blade", "Every 4th hit on a surviving foe applies Burn.", "Each Burn costs 5% max Health, down to 1 HP.", "emberwake"),
["GKJ_CE_LeadheartLocket"] = ("Leadheart Locket", "Below half Health, take 35% less Health damage.", "Heals stop at 75% Health.", "locket"),
["GKJ_CE_BorrowedHalo"] = ("The Borrowed Halo", "Survive 1 lethal hit per battle. Block Health hits for 2s.", "Deal half damage for 8s.", "halo")
};
internal static bool Wears(Entity entity, string id)
{
if (entity is UnitBase)
{
return entity.GetItems()?.Contains(id) ?? false;
}
return false;
}
internal static bool IsCursed(Item item)
{
return Cards.ContainsKey(item.GetIdentifier() ?? "");
}
[HarmonyPatch(typeof(AddressablesManager), "Awake")]
[HarmonyPostfix]
internal static void Register(AddressablesManager __instance)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Expected O, but got Unknown
Dictionary<string, Item> allItems = __instance.GetAllItems();
List<string> allItemIdentifiers = __instance.GetAllItemIdentifiers();
foreach (KeyValuePair<string, (string, string, string, string)> card in Cards)
{
if (!allItems.ContainsKey(card.Key))
{
GameObject val = new GameObject(card.Key);
val.SetActive(false);
val.transform.SetParent(((Component)__instance).transform, false);
Item val2 = val.AddComponent<Item>();
Traverse obj = Traverse.Create((object)val2);
obj.Field("identifier").SetValue((object)card.Key);
obj.Field("icon").SetValue((object)LoadSprite("items", card.Value.Item4, 16f));
obj.Field("soldAtBlacksmith").SetValue((object)true);
obj.Field("rarity").SetValue((object)(Rarity)1);
obj.Field("kingdom").SetValue((object)(Races)11);
obj.Field("keywords").SetValue((object)Array.Empty<EffectKeywordType>());
obj.Field("attack").SetValue((object)new Attack
{
combatEffects = new List<CombatEffect>()
});
obj.Field("cooldown").SetValue((object)9999999f);
allItems.Add(card.Key, val2);
if (!allItemIdentifiers.Contains(card.Key))
{
allItemIdentifiers.Add(card.Key);
}
}
}
}
internal static Sprite LoadSprite(string group, string name, float pixelsPerUnit = 32f)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(group + "." + name + ".png");
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
Texture2D val = new Texture2D(2, 2)
{
filterMode = (FilterMode)0,
wrapMode = (TextureWrapMode)1
};
if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
{
throw new InvalidDataException(name);
}
Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), pixelsPerUnit, 0u, (SpriteMeshType)0);
((Object)obj).name = name;
return obj;
}
[HarmonyPatch(typeof(Item), "GetTitle")]
[HarmonyPrefix]
private static bool Title(Item __instance, ref string __result)
{
if (!Cards.TryGetValue(__instance.GetIdentifier() ?? "", out (string, string, string, string) value))
{
return true;
}
(__result, _, _, _) = value;
return false;
}
[HarmonyPatch(typeof(Item), "GetDescription")]
[HarmonyPrefix]
private static bool Description(Item __instance, ref string __result)
{
if (!Cards.TryGetValue(__instance.GetIdentifier() ?? "", out (string, string, string, string) value))
{
return true;
}
__result = "Gift: " + value.Item2 + "\n<color=#991F29>Curse: " + value.Item3 + "</color>";
return false;
}
}
[HarmonyPatch]
internal static class Chalice
{
private struct Pending
{
internal UnitHealth Health;
internal Heal Heal;
internal float Due;
}
private static readonly List<Pending> Queue = new List<Pending>();
private static UnitHealth delivering;
[HarmonyPrefix]
[HarmonyPatch(typeof(UnitHealth), "ReceiveHeal")]
private static bool Receive(UnitHealth __instance, Heal heal, ref float __result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return ReceiveAt(__instance, heal, Time.time, ref __result);
}
internal static bool ReceiveAt(UnitHealth health, Heal heal, float now, ref float result)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (delivering == health)
{
delivering = null;
return true;
}
if (!CanDelay(health, heal))
{
return true;
}
Enqueue(health, heal, now);
result = 0f;
return false;
}
internal static bool CanDelay(UnitHealth health, Heal heal)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
if (heal.healAmount > 0f && ((int)heal.healType == 0 || (int)heal.healType == 1) && ((Health)health).IsAlive() && ((Health)health).GetHitpoints() > 0f)
{
return Catalog.Wears(((Health)health).GetEntity(), "GKJ_CE_BitterChalice");
}
return false;
}
internal static void Enqueue(UnitHealth health, Heal heal, float now)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
heal.healAmount *= 1.5f;
Queue.Add(new Pending
{
Health = health,
Heal = heal,
Due = now + 3f
});
}
internal static void Tick(float now)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
while (Queue.Count > 0 && Queue[0].Due <= now)
{
Pending pending = Queue[0];
Queue.RemoveAt(0);
UnitHealth health = pending.Health;
Entity entity = ((Health)health).GetEntity();
if (!((Object)(object)entity == (Object)null) && (object)entity.GetHealth() == health && CanDelay(health, pending.Heal))
{
delivering = health;
try
{
((Health)health).ReceiveHeal(pending.Heal);
}
finally
{
delivering = null;
}
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UnitHealth), "Death")]
private static void Death(UnitHealth __instance)
{
Cancel((IHealth)(object)__instance);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UnitBase), "Unregister")]
private static void Unregister(UnitBase __instance)
{
Cancel(((Entity)__instance).GetHealth());
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Entity), "RemoveItem")]
private static void Remove(Entity __instance, int index)
{
List<string> items = __instance.GetItems();
if (items[index] == "GKJ_CE_BitterChalice" && items.IndexOf("GKJ_CE_BitterChalice") == items.LastIndexOf("GKJ_CE_BitterChalice"))
{
Cancel(__instance.GetHealth());
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Entity), "SetItems")]
private static void Replace(Entity __instance, List<string> items)
{
if (Queue.Count > 0 && (items == null || !items.Contains("GKJ_CE_BitterChalice")))
{
Cancel(__instance.GetHealth());
}
}
private static void Cancel(IHealth health)
{
if (Queue.Count != 0)
{
Queue.RemoveAll((Pending p) => (object)p.Health == health);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameDataManager), "Load")]
internal static void Clear()
{
Queue.Clear();
}
}
[HarmonyPatch(typeof(Health), "ReceiveDamage")]
internal static class Mirror
{
private static readonly ConditionalWeakTable<MonsterBaseHealth, HashSet<int>> History = new ConditionalWeakTable<MonsterBaseHealth, HashSet<int>>();
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> source)
{
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Expected O, but got Unknown
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Expected O, but got Unknown
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Expected O, but got Unknown
List<CodeInstruction> list = source.ToList();
MethodInfo identifier = AccessTools.Method(typeof(Entity), "GetIdentifier", (Type[])null, (Type[])null);
int num = list.FindIndex((CodeInstruction op) => CodeInstructionExtensions.Calls(op, identifier)) - 1;
if (num < 5 || list[num - 5].opcode != OpCodes.Ldloc_2 || list[num - 1].opcode != OpCodes.Ret || list[num - 3].opcode != OpCodes.Bgt_Un || list.Count((CodeInstruction op) => CodeInstructionExtensions.Calls(op, identifier)) != 1)
{
throw new InvalidOperationException("Unexpected health damage branch.");
}
list.InsertRange(num, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[5]
{
CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldarg_0, (object)null), list[num]),
new CodeInstruction(OpCodes.Ldarg_1, (object)null),
new CodeInstruction(OpCodes.Ldloc_2, (object)null),
CodeInstruction.Call(typeof(Mirror), "Scale", (Type[])null, (Type[])null),
new CodeInstruction(OpCodes.Stloc_2, (object)null)
});
return list;
}
internal static float Scale(Health health, Damage dmg, float takeDamage)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
MonsterBaseHealth val = (MonsterBaseHealth)(object)((health is MonsterBaseHealth) ? health : null);
if (val != null)
{
Entity origin = dmg.origin;
UnitBase val2 = (UnitBase)(object)((origin is UnitBase) ? origin : null);
if (val2 != null && !(takeDamage <= 0f) && ((Health)val).GetHitpoints() != 0f)
{
bool flag = History.GetOrCreateValue(val).Add(((Entity)val2).GetIdentifier());
float amount = (Catalog.Wears((Entity)(object)val2, "GKJ_CE_CrackedDuelistsMirror") ? (takeDamage * (flag ? 2f : 0.75f)) : takeDamage);
return Arsenal.ScaleHit(val, val2, dmg.isStatus, amount);
}
}
return takeDamage;
}
}
[BepInPlugin("gkj.sfk.cursedequipment", "Cursed Equipment", "0.2.5")]
public sealed class Plugin : BaseUnityPlugin
{
private Harmony patches;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
patches = new Harmony("gkj.sfk.cursedequipment");
try
{
patches.PatchAll(typeof(Plugin).Assembly);
if ((Object)(object)AddressablesManager.Instance != (Object)null)
{
Catalog.Register(AddressablesManager.Instance);
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Cursed Equipment 0.2.4 loaded.");
}
catch
{
patches.UnpatchSelf();
throw;
}
}
private void Update()
{
Arsenal.Now = Time.time;
Chalice.Tick(Arsenal.Now);
}
private void OnDestroy()
{
Chalice.Clear();
Harmony obj = patches;
if (obj != null)
{
obj.UnpatchSelf();
}
}
}
[HarmonyPatch(typeof(UIOverlayMerchant), "AddItem")]
internal sealed class ShopFocus : MonoBehaviour
{
private Transform purchases;
private static void Postfix(UIOverlayMerchant __instance, Item item, ResourceAmount[] costs)
{
if (costs != null && costs.Length != 0 && Catalog.IsCursed(item))
{
ShopFocus obj = ((Component)__instance).GetComponent<ShopFocus>() ?? ((Component)__instance).gameObject.AddComponent<ShopFocus>();
obj.purchases = ((Component)__instance).transform.Find("Panel/BuyButtons");
((Behaviour)obj).enabled = true;
}
}
private void LateUpdate()
{
GamepadManager instance = GamepadManager.Instance;
EventSystem current = EventSystem.current;
if (!Object.op_Implicit((Object)(object)instance) || !instance.IsGamepadInUse() || !Object.op_Implicit((Object)(object)current) || !Object.op_Implicit((Object)(object)purchases) || !((Component)purchases).gameObject.activeInHierarchy)
{
return;
}
GameObject gameObjectToSelect = instance.GetGameObjectToSelect();
if (!Object.op_Implicit((Object)(object)gameObjectToSelect) || !gameObjectToSelect.transform.IsChildOf(purchases))
{
return;
}
Button component = gameObjectToSelect.GetComponent<Button>();
if (Object.op_Implicit((Object)(object)component) && ((Behaviour)component).isActiveAndEnabled && ((Selectable)component).IsInteractable())
{
if (!Object.op_Implicit((Object)(object)current.currentSelectedGameObject))
{
instance.SetGameObjectToSelect(gameObjectToSelect, true);
}
((Behaviour)this).enabled = false;
}
}
private void OnDisable()
{
((Behaviour)this).enabled = false;
}
}
[HarmonyPatch]
internal static class Spellglass
{
private sealed class CircleDamage : CombatEffect
{
private readonly CombatEffect source;
internal CircleDamage(CombatEffect source)
{
this.source = source;
base.originRequirements = source.originRequirements;
base.targetRequirements = source.targetRequirements;
}
public override void Apply(List<Entity> targets, Entity target, AbilityBase origin, int originIdentifier, Entity self, StatContainer stats, float amount, Transform position = null)
{
CombatEffect current = CircleDelivery.Current;
CircleDelivery.Current = source;
try
{
source.Apply(targets, target, origin, originIdentifier, self, stats, amount, position);
}
finally
{
CircleDelivery.Current = current;
}
}
}
private static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(ProjectileActionFindTargets), "Trigger", (Type[])null, (Type[])null);
yield return AccessTools.Method(typeof(ProjectileSActionFindTargets), "Trigger", (Type[])null, (Type[])null);
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase original)
{
FieldInfo effects = AccessTools.Field(original.DeclaringType, "combatEffects");
FieldInfo radius = AccessTools.Field(original.DeclaringType, "radius");
MethodInfo hit = AccessTools.Method(typeof(ProjectileBase), "Hit", (Type[])null, (Type[])null);
LocalBuilder scoped = generator.DeclareLocal(typeof(List<CombatEffect>));
yield return new CodeInstruction(OpCodes.Ldarg_1, (object)null);
yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
yield return new CodeInstruction(OpCodes.Ldfld, (object)effects);
yield return CodeInstruction.Call(typeof(Spellglass), "ForCircle", (Type[])null, (Type[])null);
yield return new CodeInstruction(OpCodes.Stloc, (object)scoped);
int radii = 0;
int hits = 0;
foreach (CodeInstruction instruction in instructions)
{
if (CodeInstructionExtensions.Calls(instruction, hit))
{
yield return CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldloc, (object)scoped), instruction);
yield return CodeInstruction.Call(typeof(Spellglass), "Hit", (Type[])null, (Type[])null);
hits++;
continue;
}
yield return instruction;
if (CodeInstructionExtensions.LoadsField(instruction, radius, false))
{
yield return new CodeInstruction(OpCodes.Ldloc, (object)scoped);
yield return CodeInstruction.Call(typeof(Spellglass), "Radius", (Type[])null, (Type[])null);
radii++;
}
}
if (radii == 0 || hits != 1)
{
throw new InvalidOperationException("Unexpected circle query in " + original);
}
}
internal static List<CombatEffect> ForCircle(ProjectileBase projectile, List<CombatEffect> overrides)
{
if (!Catalog.Wears(projectile.GetOriginEntity(), "GKJ_CE_CrackedSpellglass"))
{
return null;
}
return WrapDamage((overrides != null && overrides.Count > 0) ? overrides : projectile.combatEffects);
}
internal static List<CombatEffect> WrapDamage(List<CombatEffect> effects)
{
List<CombatEffect> list = null;
if (effects == null)
{
return null;
}
for (int i = 0; i < effects.Count; i++)
{
CombatEffect val = effects[i];
if (val is CombatEffectDamage || val is CombatEffectRealDamage)
{
if (list == null)
{
list = new List<CombatEffect>(effects);
}
list[i] = (CombatEffect)(object)new CircleDamage(val);
}
}
return list;
}
internal static float Radius(float radius, List<CombatEffect> scoped)
{
if (scoped != null)
{
return radius * 1.4f;
}
return radius;
}
private static void Hit(ProjectileBase projectile, Entity target, List<CombatEffect> effects, bool setTarget, List<CombatEffect> scoped)
{
projectile.Hit(target, scoped ?? effects, setTarget);
}
}
[HarmonyPatch]
internal static class CircleDelivery
{
[ThreadStatic]
internal static CombatEffect Current;
private static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(CombatEffectDamage), "Trigger", (Type[])null, (Type[])null);
yield return AccessTools.Method(typeof(CombatEffectRealDamage), "Trigger", (Type[])null, (Type[])null);
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo receive = AccessTools.Method(typeof(IHealth), "ReceiveDamage", (Type[])null, (Type[])null);
int calls = 0;
foreach (CodeInstruction instruction in instructions)
{
if (!CodeInstructionExtensions.Calls(instruction, receive))
{
yield return instruction;
continue;
}
yield return CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldarg_0, (object)null), instruction);
yield return CodeInstruction.Call(typeof(CircleDelivery), "Receive", (Type[])null, (Type[])null);
calls++;
}
if (calls != 1)
{
throw new InvalidOperationException("Unexpected damage delivery signature.");
}
}
internal static float Receive(IHealth health, Damage damage, bool direct, bool trueDamage, CombatEffect source)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
CombatEffect current = Current;
if (current == source)
{
damage.damageAmount *= 0.8f;
}
Current = null;
try
{
return health.ReceiveDamage(damage, direct, trueDamage);
}
finally
{
Current = current;
}
}
}