Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CoreOverhaul v1.0.2
CoreOverhaul.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using ConditionalConfigSync; using HarmonyLib; using ItemDataManager; using Jewelcrafting; using Jewelcrafting.GemEffects; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("CoreOverhaul")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.2.0")] [assembly: AssemblyInformationalVersion("1.0.2")] [assembly: AssemblyProduct("CoreOverhaul")] [assembly: AssemblyTitle("CoreOverhaul")] [assembly: AssemblyVersion("1.0.2.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 CoreOverhaul { internal static class Armor { private const string Section = "02 - Armor"; private const float DefaultHalvedHitPerArmor = 2f; private const float MinHalvedHitPerArmor = 0.25f; private const float MaxHalvedHitPerArmor = 10f; private const float DefaultMostReduction = 0.9f; private const float MinMostReduction = 0.5f; private const float MaxMostReduction = 0.99f; private const float NoArmor = 0f; private const float NoDamage = 0f; private const float FullDamage = 1f; private const float PercentScale = 100f; private const string TooltipTextName = "Text"; private const float TooltipTextPadding = 4f; private const string TooltipTopic = "Armor"; private const string TooltipHit = "{0} damage hit: you take <color=orange>{1}</color> ({2:0}% blocked)"; private const string LineBreak = "\n"; private const string JatifyArmorText = "Left"; private const string JatifyHoverName = "CoreOverhaul_ArmorHover"; private static readonly float[] ExampleHits = new float[4] { 20f, 50f, 100f, 200f }; internal static ConfigEntry<bool> PercentArmor; internal static ConfigEntry<float> HalvedHitPerArmor; internal static ConfigEntry<float> MostReduction; private static Character target; internal static void Bind(CoreOverhaulPlugin plugin) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown PercentArmor = plugin.BindShared("02 - Armor", "PercentArmor", defaultValue: true, "Your armor blocks a share of every hit, and the share depends on how hard the hit is next to your armor: light hits are mostly blocked, heavy hits less, and armor never stops mattering. Creatures' armor stays vanilla."); HalvedHitPerArmor = plugin.BindShared("02 - Armor", "HalvedHitPerArmor", 2f, new ConfigDescription("A hit this many times your armor is cut in half. With 2 and 50 armor, a 100 damage hit is halved, a 50 damage hit is blocked by two thirds and a 200 damage hit by a third. Higher makes armor stronger.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 10f), Array.Empty<object>())); MostReduction = plugin.BindShared("02 - Armor", "MostDamageBlocked", 0.9f, new ConfigDescription("The most of a hit armor can ever block. 0.9 means you always take at least 10%.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 0.99f), Array.Empty<object>())); } private static float HalvedHit(float armor) { return armor * HalvedHitPerArmor.Value; } internal static float Blocked(float armor, float damage) { if (armor <= 0f || damage <= 0f) { return 0f; } float num = HalvedHit(armor); return Mathf.Min(MostReduction.Value, num / (num + damage)); } internal static void ShowBlocked(Player player, TMP_Text armorText) { if ((Object)(object)player == (Object)null || (Object)(object)armorText == (Object)null) { return; } UITooltip val = ((Component)armorText).GetComponent<UITooltip>(); if (!PercentArmor.Value) { if ((Object)(object)val != (Object)null) { ((Behaviour)val).enabled = false; } return; } float bodyArmor = ((Character)player).GetBodyArmor(); if ((Object)(object)val == (Object)null) { val = ((Component)armorText).gameObject.AddComponent<UITooltip>(); } if ((Object)(object)((Component)val).GetComponent<SideTooltip>() == (Object)null) { ((Component)val).gameObject.AddComponent<SideTooltip>(); } ((Graphic)armorText).raycastTarget = true; Fill(val, bodyArmor); } internal static void Fill(UITooltip tooltip, float armor) { if ((Object)(object)((Component)tooltip).GetComponent<ArmorTooltip>() == (Object)null) { ((Component)tooltip).gameObject.AddComponent<ArmorTooltip>(); } if ((Object)(object)tooltip.m_tooltipPrefab == (Object)null) { tooltip.m_tooltipPrefab = EquipLoadBar.TooltipPrefab(); } ((Behaviour)tooltip).enabled = PercentArmor.Value; tooltip.m_topic = "Armor"; tooltip.m_text = HitsYouCanTake(armor); } internal static void BuildJatify(RectTransform card) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) Transform obj = ((Transform)card).Find("Left"); TMP_Text val = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null); if (!((Object)(object)val == (Object)null) && !((Object)(object)val.transform.Find("CoreOverhaul_ArmorHover") != (Object)null)) { GameObject val2 = new GameObject("CoreOverhaul_ArmorHover", new Type[4] { typeof(RectTransform), typeof(Image), typeof(UITooltip), typeof(JatifyArmorHover) }); val2.transform.SetParent(val.transform, false); Image component = val2.GetComponent<Image>(); ((Graphic)component).color = Color.clear; ((Graphic)component).raycastTarget = true; val2.GetComponent<JatifyArmorHover>().Stats = val; } } internal static void FitTooltip(UITooltip tooltip, GameObject shown) { //IL_0099: 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) //IL_00d7: 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_00dd: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)tooltip == (Object)null || (Object)(object)((Component)tooltip).GetComponent<ArmorTooltip>() == (Object)null || (Object)(object)shown == (Object)null || shown.transform.childCount == 0 || (Object)(object)shown.GetComponent<FittedTooltip>() != (Object)null) { return; } TMP_Text val = ((IEnumerable<TMP_Text>)shown.GetComponentsInChildren<TMP_Text>(true)).FirstOrDefault((Func<TMP_Text, bool>)((TMP_Text candidate) => ((Object)candidate).name == "Text")); if ((Object)(object)val == (Object)null) { return; } Transform child = shown.transform.GetChild(0); RectTransform val2 = (RectTransform)(object)((child is RectTransform) ? child : null); if (val2 == null) { return; } float num = val.GetPreferredValues(val.text, float.PositiveInfinity, float.PositiveInfinity).x + 4f; Rect rect = val.rectTransform.rect; float num2 = num - ((Rect)(ref rect)).width; if (!(num2 <= 0f)) { Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(num2, 0f); val2.sizeDelta += val3; if (Mathf.Approximately(val.rectTransform.anchorMin.x, val.rectTransform.anchorMax.x)) { RectTransform rectTransform = val.rectTransform; rectTransform.sizeDelta += val3; } shown.AddComponent<FittedTooltip>(); Utils.ClampUIToScreen(val2); } } private static string HitsYouCanTake(float armor) { StringBuilder stringBuilder = new StringBuilder(); float[] exampleHits = ExampleHits; foreach (float num in exampleHits) { float num2 = Blocked(armor, num); if (stringBuilder.Length > 0) { stringBuilder.Append("\n"); } stringBuilder.AppendFormat("{0} damage hit: you take <color=orange>{1}</color> ({2:0}% blocked)", num, Mathf.RoundToInt(num * (1f - num2)), num2 * 100f); } return stringBuilder.ToString(); } internal static Character StartHit(Character character) { Character result = target; target = character; return result; } internal static void EndHit(Character outer) { target = outer; } internal static bool Apply(HitData hit, float armor) { if (!PercentArmor.Value || !(target is Player)) { return true; } ((DamageTypes)(ref hit.m_damage)).Modify(1f - Blocked(armor, ((DamageTypes)(ref hit.m_damage)).GetTotalBlockableDamage())); return false; } } internal sealed class FittedTooltip : MonoBehaviour { } internal sealed class ArmorTooltip : MonoBehaviour { } internal sealed class JatifyArmorHover : MonoBehaviour { private const int ArmorLine = 0; internal TMP_Text Stats; private UITooltip tooltip; private Image hitArea; private RectTransform area; private float shownArmor = float.NaN; private void Awake() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_002f: Unknown result type (might be due to invalid IL or missing references) tooltip = ((Component)this).GetComponent<UITooltip>(); hitArea = ((Component)this).GetComponent<Image>(); area = (RectTransform)((Component)this).transform; area.pivot = Vector2.zero; } private void LateUpdate() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)Stats == (Object)null || (Object)(object)localPlayer == (Object)null) { return; } TMP_TextInfo textInfo = Stats.textInfo; bool flag = textInfo != null && textInfo.lineCount > 0; ((Behaviour)hitArea).enabled = flag && Armor.PercentArmor.Value; if (flag) { TMP_LineInfo val = textInfo.lineInfo[0]; RectTransform rectTransform = Stats.rectTransform; Rect rect = rectTransform.rect; RectTransform obj = area; Vector2 anchorMin = (area.anchorMax = rectTransform.pivot); obj.anchorMin = anchorMin; area.anchoredPosition = new Vector2(((Rect)(ref rect)).xMin, val.descender); area.sizeDelta = new Vector2(((Rect)(ref rect)).width, val.ascender - val.descender); float bodyArmor = ((Character)localPlayer).GetBodyArmor(); if (bodyArmor != shownArmor || ((Behaviour)tooltip).enabled != Armor.PercentArmor.Value) { shownArmor = bodyArmor; Armor.Fill(tooltip, bodyArmor); } } } } [HarmonyPatch(typeof(UITooltip), "OnHoverStart")] internal static class ArmorTooltipWidthPatch { private static readonly FieldRef<GameObject> Shown = AccessTools.StaticFieldRefAccess<GameObject>(AccessTools.Field(typeof(UITooltip), "m_tooltip")); private static void Postfix(UITooltip __instance) { Armor.FitTooltip(__instance, Shown.Invoke()); } } [HarmonyPatch(typeof(Character), "RPC_Damage")] internal static class ArmorHitPatch { private static void Prefix(Character __instance, out Character __state) { __state = Armor.StartHit(__instance); } private static void Finalizer(Character __state) { Armor.EndHit(__state); } } [HarmonyPatch(typeof(InventoryGui), "UpdateCharacterStats")] internal static class ArmorStatsPatch { private static void Postfix(Player __0, TMP_Text ___m_armor) { Armor.ShowBlocked(__0, ___m_armor); } } [HarmonyPatch(typeof(HitData), "ApplyArmor")] internal static class PercentArmorPatch { private static bool Prefix(HitData __instance, float __0) { return Armor.Apply(__instance, __0); } } internal static class AutoShield { private const string Section = "03 - Shields"; private const int HotbarRow = 0; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> PutAwayTogether; private static bool equippingSaved; private static int equipping; internal static void Bind(CoreOverhaulPlugin plugin) { Enabled = plugin.BindLocal("03 - Shields", "AutoEquipShield", defaultValue: true, "When you equip a one-handed weapon with nothing in your other hand, the first shield on your hotbar is equipped with it."); PutAwayTogether = plugin.BindLocal("03 - Shields", "UnequipShieldWithWeapon", defaultValue: true, "When you put away a one-handed weapon, the shield in your other hand is put away too. Switching straight to another weapon keeps the shield."); } internal static void EquipStarted() { equipping++; } internal static void EquipFinished() { equipping--; } internal static void AfterUnequip(Humanoid humanoid, ItemData item) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 if (equipping > 0 || equippingSaved || !PutAwayTogether.Value) { return; } Player val = (Player)(object)((humanoid is Player) ? humanoid : null); if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && item != null && (int)item.m_shared.m_itemType == 3) { ItemData leftItem = ((Humanoid)val).LeftItem; if (leftItem != null && (int)leftItem.m_shared.m_itemType == 5) { ((Humanoid)val).UnequipItem(leftItem, true); } } } internal static void LoadingStarted() { equippingSaved = true; } internal static void LoadingFinished() { equippingSaved = false; } internal static void AfterEquip(Humanoid humanoid, ItemData item, bool equipped) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Invalid comparison between Unknown and I4 if (!equipped || equippingSaved || !Enabled.Value) { return; } Player val = (Player)(object)((humanoid is Player) ? humanoid : null); if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && item != null && (int)item.m_shared.m_itemType == 3 && ((Humanoid)val).LeftItem == null) { ItemData val2 = (from candidate in ((Humanoid)val).GetInventory().GetAllItems() where candidate.m_gridPos.y == 0 && (int)candidate.m_shared.m_itemType == 5 orderby candidate.m_gridPos.x select candidate).FirstOrDefault(); if (val2 != null) { ((Humanoid)val).EquipItem(val2, true); } } } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] internal static class AutoShieldEquipPatch { private static void Prefix() { AutoShield.EquipStarted(); } private static void Postfix(Humanoid __instance, ItemData __0, bool __result) { AutoShield.AfterEquip(__instance, __0, __result); } private static void Finalizer() { AutoShield.EquipFinished(); } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] internal static class AutoShieldUnequipPatch { private static void Postfix(Humanoid __instance, ItemData __0) { AutoShield.AfterUnequip(__instance, __0); } } [HarmonyPatch(typeof(Player), "EquipInventoryItems")] internal static class AutoShieldLoadPatch { private static void Prefix() { AutoShield.LoadingStarted(); } private static void Finalizer() { AutoShield.LoadingFinished(); } } internal static class Ballista { private sealed class ExtraTarget { internal ItemDrop Item; internal readonly List<Character> Targets = new List<Character>(); } private const string Section = "21 - Ballista"; private const string BallistaPrefab = "piece_turret"; private const string ChestPrefab = "piece_chest_wood"; private const int TrophyColumns = 3; private const int TrophyRows = 2; private const string TargetSeparator = ", "; private const char EntrySeparator = ';'; private const char TargetMark = '='; private const char CreatureSeparator = ','; private const int PairParts = 2; private const string TrophiesHint = "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Trophies"; internal static ConfigEntry<bool> TrophyInventory; internal static ConfigEntry<string> ExtraTrophies; private static List<ExtraTarget> extras; private static ZNetScene extrasScene; private static readonly FieldRef<Turret, List<ItemDrop>> targetItems = AccessTools.FieldRefAccess<Turret, List<ItemDrop>>("m_targetItems"); private static readonly FieldRef<Turret, List<Character>> targetCharacters = AccessTools.FieldRefAccess<Turret, List<Character>>("m_targetCharacters"); private static readonly FieldRef<Turret, string> targetsText = AccessTools.FieldRefAccess<Turret, string>("m_targetsText"); internal static void Bind(CoreOverhaulPlugin plugin) { TrophyInventory = plugin.BindShared("21 - Ballista", "TrophyInventory", defaultValue: true, "The ballista gets a 6 slot inventory for trophies, opened with your alt key and use. It shoots every creature whose trophy is inside, or every enemy when it's empty."); ExtraTrophies = plugin.BindShared("21 - Ballista", "ExtraTrophyTargets", "", "More trophies the ballista accepts, for modded creatures, as TrophyPrefab=CreaturePrefab,CreaturePrefab pairs separated by semicolons. For example: TrophyMyBoar=MyBoar,MyBoarElite. A vanilla trophy listed here adds its creatures to the ones it already targets."); ExtraTrophies.SettingChanged += delegate { extras = null; }; } internal static void AddInventory() { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) ZNetScene instance = ZNetScene.instance; GameObject val = (((Object)(object)instance != (Object)null) ? instance.GetPrefab("piece_turret") : null); Turret val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Turret>() : null); if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val.GetComponent<Container>() != (Object)null)) { GameObject prefab = instance.GetPrefab("piece_chest_wood"); Container val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Container>() : null); Container val4 = val.AddComponent<Container>(); val4.m_name = val2.m_name; val4.m_width = 3; val4.m_height = 2; val4.m_checkGuardStone = true; val4.m_defaultItems = new DropTable(); val4.m_openEffects = (EffectList)(((Object)(object)val3 != (Object)null) ? ((object)val3.m_openEffects) : ((object)new EffectList())); val4.m_closeEffects = (EffectList)(((Object)(object)val3 != (Object)null) ? ((object)val3.m_closeEffects) : ((object)new EffectList())); if ((Object)(object)val3 != (Object)null) { val4.m_bkg = val3.m_bkg; } } } private static Container Trophies(Turret turret) { if (!TrophyInventory.Value || !((Object)(object)turret != (Object)null)) { return null; } return ((Component)turret).GetComponent<Container>(); } internal static bool Interact(Turret turret, Humanoid user, bool hold, bool alt, ref bool result) { Container val = Trophies(turret); if ((Object)(object)val == (Object)null || hold || !alt) { return true; } result = val.Interact(user, hold, alt); return false; } internal static bool UseItem(Turret turret, Humanoid user, ItemData item, ref bool result) { Container val = Trophies(turret); if ((Object)(object)val == (Object)null || item == null || !IsTrophyTarget(turret, item)) { return true; } result = val.Interact(user, false, true); return false; } private static bool IsTrophyTarget(Turret turret, ItemData item) { //IL_001d: 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) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) foreach (TrophyTarget configTarget in turret.m_configTargets) { if ((Object)(object)configTarget.m_item != (Object)null && configTarget.m_item.m_itemData.m_shared.m_name == item.m_shared.m_name) { return true; } } return Extras().Any((ExtraTarget extra) => extra.Item.m_itemData.m_shared.m_name == item.m_shared.m_name); } private static List<ExtraTarget> Extras() { ZNetScene instance = ZNetScene.instance; if (extras != null && (Object)(object)extrasScene == (Object)(object)instance) { return extras; } extras = new List<ExtraTarget>(); extrasScene = instance; if ((Object)(object)instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null) { return extras; } string[] array = ExtraTrophies.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { '=' }); if (array2.Length != 2) { continue; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(array2[0].Trim()); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { CoreOverhaulPlugin.Log.LogWarning((object)("Ballista trophy " + array2[0].Trim() + " was not found.")); continue; } ExtraTarget extraTarget = new ExtraTarget { Item = val }; string[] array3 = array2[1].Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array3) { GameObject prefab = instance.GetPrefab(text.Trim()); Character val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null); if ((Object)(object)val2 != (Object)null) { extraTarget.Targets.Add(val2); } else { CoreOverhaulPlugin.Log.LogWarning((object)("Ballista target " + text.Trim() + " was not found.")); } } if (extraTarget.Targets.Count > 0) { extras.Add(extraTarget); } } return extras; } internal static void ReadTrophies(Turret turret) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: 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_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) Container val = Trophies(turret); Inventory val2 = (((Object)(object)val != (Object)null) ? val.GetInventory() : null); if (val2 == null) { return; } List<ItemDrop> list = targetItems.Invoke(turret); List<Character> list2 = targetCharacters.Invoke(turret); List<string> list3 = new List<string>(); list.Clear(); list2.Clear(); foreach (ItemData allItem in val2.GetAllItems()) { foreach (TrophyTarget configTarget in turret.m_configTargets) { if (!((Object)(object)configTarget.m_item == (Object)null) && !list.Contains(configTarget.m_item) && !(configTarget.m_item.m_itemData.m_shared.m_name != allItem.m_shared.m_name)) { list.Add(configTarget.m_item); list2.AddRange(configTarget.m_targets); if (!string.IsNullOrEmpty(configTarget.m_nameOverride)) { list3.Add(configTarget.m_nameOverride); } else if (configTarget.m_targets.Count > 0) { list3.Add(configTarget.m_targets[0].m_name); } else { list3.Add(allItem.m_shared.m_name); } } } foreach (ExtraTarget item in Extras()) { if (!(item.Item.m_itemData.m_shared.m_name != allItem.m_shared.m_name) && !item.Targets.Any(list2.Contains)) { list2.AddRange(item.Targets); if (!list.Contains(item.Item)) { list.Add(item.Item); list3.Add(item.Targets[0].m_name); } } } } targetsText.Invoke(turret) = string.Join(", ", list3); } internal static void AddHint(Turret turret, ref string text) { if (!((Object)(object)Trophies(turret) == (Object)null) && !string.IsNullOrEmpty(text) && Localization.instance != null) { text += Localization.instance.Localize("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Trophies"); } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class BallistaInventoryPatch { private static void Postfix() { Ballista.AddInventory(); } } [HarmonyPatch(typeof(Turret), "Interact")] internal static class BallistaInteractPatch { private static bool Prefix(Turret __instance, Humanoid __0, bool __1, bool __2, ref bool __result) { return Ballista.Interact(__instance, __0, __1, __2, ref __result); } } [HarmonyPatch(typeof(Turret), "UseItem")] internal static class BallistaUseItemPatch { private static bool Prefix(Turret __instance, Humanoid __0, ItemData __1, ref bool __result) { return Ballista.UseItem(__instance, __0, __1, ref __result); } } [HarmonyPatch(typeof(Turret), "ReadTargets")] internal static class BallistaReadTargetsPatch { private static void Postfix(Turret __instance) { Ballista.ReadTrophies(__instance); } } [HarmonyPatch(typeof(Turret), "UpdateTarget")] internal static class BallistaUpdateTargetPatch { private static void Prefix(Turret __instance) { Ballista.ReadTrophies(__instance); } } [HarmonyPatch(typeof(Turret), "GetHoverText")] internal static class BallistaHoverPatch { private static void Postfix(Turret __instance, ref string __result) { Ballista.AddHint(__instance, ref __result); } } internal static class Bows { private const string Section = "06 - Bows"; private const float DefaultSneakBonus = 1.5f; private const float MinSneakBonus = 1f; private const float MaxSneakBonus = 5f; private const float DefaultDrawMovement = 0.5f; private const float MinDrawMovement = 0.1f; private const float MaxDrawMovement = 1f; private const float DefaultStagger = 0.5f; private const float MinStagger = 0f; private const float MaxStagger = 2f; private const float DefaultDrawSpeedPerLevel = 0.01f; private const float MinDrawSpeedPerLevel = 0f; private const float MaxDrawSpeedPerLevel = 0.04f; private const float MaxSkillLevel = 100f; private const float NormalSpeed = 1f; internal static ConfigEntry<float> SneakBonus; internal static ConfigEntry<float> DrawMovement; internal static ConfigEntry<float> Stagger; internal static ConfigEntry<bool> LinearDraw; internal static ConfigEntry<float> DrawSpeedPerLevel; private static readonly Dictionary<SharedData, (float sneak, float stagger)> originals = new Dictionary<SharedData, (float, float)>(); internal static void Bind(CoreOverhaulPlugin plugin) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown SneakBonus = plugin.BindShared("06 - Bows", "SneakAttackBonus", 1.5f, new ConfigDescription("Damage multiplier for a bow's sneak attack on an unaware enemy. Vanilla is 3.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>())); DrawMovement = plugin.BindShared("06 - Bows", "MovementWhileDrawing", 0.5f, new ConfigDescription("Your movement speed is multiplied by this while you draw a bow, so you can't kite backwards at full speed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>())); Stagger = plugin.BindShared("06 - Bows", "StaggerMultiplier", 0.5f, new ConfigDescription("Multiplies how much arrows stagger enemies, compared to vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); LinearDraw = plugin.BindShared("06 - Bows", "LinearDrawSpeed", defaultValue: true, "Bow skill speeds up your draw evenly with each level. Vanilla cuts the draw time faster and faster as the skill rises, until a level 100 bow draws five times as fast, which is a big part of why high level bows outclass melee."); DrawSpeedPerLevel = plugin.BindShared("06 - Bows", "DrawSpeedPerLevel", 0.01f, new ConfigDescription("How much faster you draw for each level of bow skill. 0.01 is 1% per level, so a level 100 bow draws twice as fast as level 0.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.04f), Array.Empty<object>())); SneakBonus.SettingChanged += delegate { Apply(); }; Stagger.SettingChanged += delegate { Apply(); }; } internal static float DrawDuration(float slowest, float fastest, float skillFactor) { if (!LinearDraw.Value) { return Mathf.Lerp(slowest, fastest, skillFactor); } return slowest / (1f + DrawSpeedPerLevel.Value * skillFactor * 100f); } private static bool IsBow(ItemData item) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 if (item != null && item.m_shared != null && (int)item.m_shared.m_skillType == 8 && item.m_shared.m_attack != null) { return item.m_shared.m_attack.m_bowDraw; } return false; } internal static void Apply() { ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null || instance.m_items == null) { return; } foreach (GameObject item in instance.m_items) { ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null); if (!((Object)(object)val == (Object)null) && IsBow(val.m_itemData)) { SharedData shared = val.m_itemData.m_shared; if (!originals.ContainsKey(shared)) { originals[shared] = (shared.m_backstabBonus, shared.m_attack.m_staggerMultiplier); } (float, float) tuple = originals[shared]; shared.m_backstabBonus = Mathf.Min(tuple.Item1, SneakBonus.Value); shared.m_attack.m_staggerMultiplier = tuple.Item2 * Stagger.Value; } } } } [HarmonyPatch(typeof(Humanoid), "GetAttackDrawPercentage")] internal static class LinearDrawPatch { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { MethodInfo lerp = AccessTools.Method(typeof(Mathf), "Lerp", (Type[])null, (Type[])null); MethodInfo drawDuration = AccessTools.Method(typeof(Bows), "DrawDuration", (Type[])null, (Type[])null); foreach (CodeInstruction instruction in instructions) { if (CodeInstructionExtensions.Calls(instruction, lerp)) { instruction.opcode = OpCodes.Call; instruction.operand = drawDuration; } yield return instruction; } } } [HarmonyPatch(typeof(Humanoid), "GetAttackSpeedFactorMovement")] internal static class DrawingMovementPatch { private static void Postfix(Humanoid __instance, ref float __result) { if (__instance is Player && ((Character)__instance).IsDrawingBow()) { __result *= Bows.DrawMovement.Value; } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class RangedAwakePatch { private static void Postfix() { Bows.Apply(); Crossbows.Apply(); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] internal static class RangedCopyPatch { private static void Postfix() { Bows.Apply(); Crossbows.Apply(); } } internal static class Building { private const string Section = "20 - Building"; private const string DefaultNoStation = "piece_groundtorch_wood"; private const char Separator = ','; private const float DefaultRangePerLevel = 4f; private const float MinRangePerLevel = 0f; private const float MaxRangePerLevel = 20f; private const string UnknownPieceMessage = "Can't destroy"; internal static ConfigEntry<string> NoStation; internal static ConfigEntry<bool> DismantleAnywhere; internal static ConfigEntry<bool> DismantleOnlyKnown; internal static ConfigEntry<float> StationRangePerLevel; private static readonly Dictionary<Piece, CraftingStation> originals = new Dictionary<Piece, CraftingStation>(); internal static void Bind(CoreOverhaulPlugin plugin) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown NoStation = plugin.BindShared("20 - Building", "NoCraftingStationNeeded", "piece_groundtorch_wood", "Comma separated piece prefabs that can be built anywhere, without a workbench or other crafting station nearby, like the wisp torch."); DismantleAnywhere = plugin.BindShared("20 - Building", "DismantleWithoutStation", defaultValue: true, "You can dismantle any piece with the hammer without its workbench or other crafting station nearby."); DismantleOnlyKnown = plugin.BindShared("20 - Building", "DismantleOnlyKnownPieces", defaultValue: true, "You can only dismantle pieces you know how to build yourself."); StationRangePerLevel = plugin.BindShared("20 - Building", "StationRangePerLevel", 4f, new ConfigDescription("Meters of build range every crafting station gains with each level from its upgrades: the workbench, forge, black forge, galdr table and the rest. A workbench starts at 20 m, so with 4 a fully upgraded level 5 workbench reaches 36 m.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>())); NoStation.SettingChanged += delegate { Apply(); }; } internal static bool MayDismantle(Player player, Piece piece, ref bool allowed) { if (!DismantleOnlyKnown.Value || (Object)(object)player == (Object)null || (Object)(object)piece == (Object)null || player.NoCostCheat()) { return true; } if (player.IsRecipeKnown(piece.m_name)) { return true; } ((Character)player).Message((MessageType)2, "Can't destroy", 0, (Sprite)null, false); allowed = false; return false; } internal static void Apply() { ZNetScene instance = ZNetScene.instance; if ((Object)(object)instance == (Object)null) { return; } foreach (KeyValuePair<Piece, CraftingStation> item in originals.Where((KeyValuePair<Piece, CraftingStation> entry) => (Object)(object)entry.Key != (Object)null)) { item.Key.m_craftingStation = item.Value; } originals.Clear(); foreach (string item2 in from entry in NoStation.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select entry.Trim()) { GameObject prefab = instance.GetPrefab(item2); Piece val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Piece>() : null); if ((Object)(object)val == (Object)null) { CoreOverhaulPlugin.Log.LogWarning((object)("No buildable piece called " + item2 + " was found.")); continue; } originals[val] = val.m_craftingStation; val.m_craftingStation = null; } } } [HarmonyPatch(typeof(Player), "CheckCanRemovePiece")] internal static class KnownPieceDismantlePatch { [HarmonyPriority(800)] private static bool Prefix(Player __instance, Piece __0, ref bool __result) { return Building.MayDismantle(__instance, __0, ref __result); } } [HarmonyPatch(typeof(Player), "CheckCanRemovePiece")] internal static class DismantlePatch { private static void Prefix(Piece __0, out CraftingStation __state) { __state = null; if (Building.DismantleAnywhere.Value && !((Object)(object)__0 == (Object)null)) { __state = __0.m_craftingStation; __0.m_craftingStation = null; } } private static void Finalizer(Piece __0, CraftingStation __state) { if ((Object)(object)__state != (Object)null && (Object)(object)__0 != (Object)null) { __0.m_craftingStation = __state; } } } [HarmonyPatch(typeof(CraftingStation), "GetExtensions")] internal static class StationRangePatch { private static void Prefix(CraftingStation __instance) { __instance.m_extraRangePerLevel = Building.StationRangePerLevel.Value; } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class BuildingScenePatch { [HarmonyPriority(0)] private static void Postfix() { Building.Apply(); } } internal static class CartographyTable { private const string Section = "25 - Cartography Table"; private const string RemovedPinsKeyPrefix = "Dreich_RemovedSharedPins_"; private const char EntrySeparator = ';'; private const char PartSeparator = ','; private const int EntryParts = 3; private const long OwnPin = 0L; private const string AltKey = "AltPlace"; private const string GamepadAltKey = "JoyAltPlace"; private const string RestoreHint = "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Read and bring back removed pins"; private const float RangeMargin = 1f; private const float OutOfRangeGrace = 0.5f; private const float NotOutOfRange = 0f; private static readonly PinType[] placedPinTypes; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> ShowPlayers; internal static ConfigEntry<bool> ShowPlacedPins; internal static ConfigEntry<bool> ShowCarts; internal static ConfigEntry<bool> ShowBoats; internal static ConfigEntry<bool> RememberRemovedPins; private static readonly FieldRef<MapTable, Switch> readSwitch; private static readonly FieldRef<Player, float> interactDistance; private static readonly FieldRef<bool> noMap; private static readonly FieldRef<Minimap, bool[]> visibleIconTypes; private static readonly FieldRef<Minimap, List<PinData>> pins; private static readonly FieldRef<Minimap, bool> pinUpdateRequired; private static readonly FieldRef<List<Vagon>> carts; private static readonly Dictionary<PinType, bool> hiddenTypes; private static readonly Dictionary<Component, PinData> vehiclePins; private static MapTable table; private static Transform readPoint; private static Collider[] tableColliders; private static float outOfRange; private static bool removingByHand; internal static bool Reading => (Object)(object)table != (Object)null; internal static bool NoMap { get { return noMap.Invoke(); } set { noMap.Invoke() = value; } } internal static bool Applies { get { if (Enabled.Value) { return NoMap; } return false; } } private static string RemovedPinsKey => "Dreich_RemovedSharedPins_" + (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetWorldUID().ToString(CultureInfo.InvariantCulture) : ""); private static bool AltHeld { get { if (!ZInput.GetButton("AltPlace")) { return ZInput.GetButton("JoyAltPlace"); } return true; } } internal static void Bind(CoreOverhaulPlugin plugin) { Enabled = plugin.BindShared("25 - Cartography Table", "MapInNoMapWorlds", defaultValue: true, "In a world with the No Map modifier, reading a cartography table opens the map for as long as you stand at the table."); ShowPlayers = plugin.BindShared("25 - Cartography Table", "ShowPlayers", defaultValue: true, "Show other players on the cartography table's map in No Map worlds. Only players who share their position are shown, like vanilla."); ShowPlacedPins = plugin.BindShared("25 - Cartography Table", "ShowPlayerPins", defaultValue: true, "Show the pins you and other players have placed on the cartography table's map in No Map worlds."); ShowCarts = plugin.BindShared("25 - Cartography Table", "ShowCarts", defaultValue: true, "Show carts on the cartography table's map in No Map worlds. Only carts in the area loaded around players can be shown."); ShowBoats = plugin.BindShared("25 - Cartography Table", "ShowBoats", defaultValue: true, "Show boats on the cartography table's map in No Map worlds. Only boats in the area loaded around players can be shown."); RememberRemovedPins = plugin.BindShared("25 - Cartography Table", "RememberRemovedPins", defaultValue: true, "When you remove a pin another player shared with you, reading a cartography table again won't put it back. Hold your alt key while reading a table to bring them all back."); } internal static void Open(MapTable mapTable, Humanoid user, ItemData item) { if (!Applies || item != null || (Object)(object)user == (Object)null || (Object)(object)user != (Object)(object)Player.m_localPlayer || (Object)(object)Minimap.instance == (Object)null || (Object)(object)mapTable == (Object)null) { return; } table = mapTable; Switch val = readSwitch.Invoke(mapTable); readPoint = (((Object)(object)val != (Object)null) ? ((Component)val).transform : ((Component)mapTable).transform); tableColliders = SolidColliders(mapTable); outOfRange = 0f; Minimap.instance.SetMapMode((MapMode)2); if (!Minimap.IsOpen()) { Close(); return; } Hide((PinType)10, !ShowPlayers.Value); PinType[] array = placedPinTypes; for (int i = 0; i < array.Length; i++) { Hide(array[i], !ShowPlacedPins.Value); } } private static Collider[] SolidColliders(MapTable mapTable) { List<Collider> list = new List<Collider>(); Collider[] componentsInChildren = ((Component)mapTable).GetComponentsInChildren<Collider>(); foreach (Collider val in componentsInChildren) { if ((Object)(object)val != (Object)null && !val.isTrigger) { list.Add(val); } } return list.ToArray(); } private static void Hide(PinType type, bool hide) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected I4, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) bool[] array = visibleIconTypes.Invoke(Minimap.instance); int num = (int)type; if (hide && array != null && num < array.Length && !hiddenTypes.ContainsKey(type)) { hiddenTypes[type] = array[num]; array[num] = false; pinUpdateRequired.Invoke(Minimap.instance) = true; } } internal static void Close() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Invalid comparison between Unknown and I4 //IL_0060: Unknown result type (might be due to invalid IL or missing references) table = null; readPoint = null; tableColliders = null; outOfRange = 0f; Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null) { return; } bool[] array = visibleIconTypes.Invoke(instance); foreach (KeyValuePair<PinType, bool> hiddenType in hiddenTypes) { if (array != null && (int)hiddenType.Key < array.Length) { array[hiddenType.Key] = hiddenType.Value; } } hiddenTypes.Clear(); foreach (PinData value in vehiclePins.Values) { instance.RemovePin(value); } vehiclePins.Clear(); pinUpdateRequired.Invoke(instance) = true; } internal static bool ShouldClose() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (!Reading) { return false; } if ((Object)(object)readPoint == (Object)null || !Applies) { return true; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { return true; } if (DistanceToTable(((Character)localPlayer).GetEyePoint()) <= interactDistance.Invoke(localPlayer) + 1f) { outOfRange = 0f; return false; } outOfRange += Time.unscaledDeltaTime; return outOfRange >= 0.5f; } private static float DistanceToTable(Vector3 point) { //IL_0054: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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) float num = float.MaxValue; if (tableColliders != null) { Collider[] array = tableColliders; foreach (Collider val in array) { if (!((Object)(object)val == (Object)null) && val.enabled) { num = Mathf.Min(num, Vector3.Distance(point, val.ClosestPointOnBounds(point))); } } } if (num != float.MaxValue) { return num; } return Vector3.Distance(point, readPoint.position); } internal static void UpdateVehicles(Minimap map) { //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) if (!Reading) { return; } List<Component> vehicles = new List<Component>(); if (ShowCarts.Value && carts.Invoke() != null) { vehicles.AddRange((IEnumerable<Component>)(from cart in carts.Invoke() where (Object)(object)cart != (Object)null select cart)); } if (ShowBoats.Value) { vehicles.AddRange((IEnumerable<Component>)(from ship in Ship.Instances.OfType<Ship>() where (Object)(object)ship != (Object)null select ship)); } foreach (Component item in vehiclePins.Keys.Where((Component vehicle) => (Object)(object)vehicle == (Object)null || !vehicles.Contains(vehicle)).ToList()) { map.RemovePin(vehiclePins[item]); vehiclePins.Remove(item); } foreach (Component item2 in vehicles) { if (!vehiclePins.TryGetValue(item2, out var value)) { Piece component = item2.GetComponent<Piece>(); value = map.AddPin(item2.transform.position, (PinType)8, ((Object)(object)component != (Object)null) ? component.m_name : "", false, false, 0L, default(PlatformUserID)); if ((Object)(object)component != (Object)null) { value.m_icon = component.m_icon; } vehiclePins[item2] = value; } value.m_pos = item2.transform.position; } pinUpdateRequired.Invoke(map) = true; } private static string PinEntry(PinData pin) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected I4, but got Unknown return string.Join(','.ToString(), Mathf.RoundToInt(pin.m_pos.x).ToString(CultureInfo.InvariantCulture), Mathf.RoundToInt(pin.m_pos.z).ToString(CultureInfo.InvariantCulture), ((int)pin.m_type).ToString(CultureInfo.InvariantCulture)); } private static HashSet<string> RemovedPins(Player player) { if (!player.m_customData.TryGetValue(RemovedPinsKey, out var value)) { return new HashSet<string>(); } return new HashSet<string>(from entry in value.Split(new char[1] { ';' }) where entry.Split(new char[1] { ',' }).Length == 3 select entry); } internal static void AddRestoreHint(ref string text) { Player localPlayer = Player.m_localPlayer; if (RememberRemovedPins.Value && !((Object)(object)localPlayer == (Object)null) && !string.IsNullOrEmpty(text) && Localization.instance != null && localPlayer.m_customData.ContainsKey(RemovedPinsKey)) { text += Localization.instance.Localize("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] Read and bring back removed pins"); } } internal static void StartRemovingByHand() { removingByHand = true; } internal static void StopRemovingByHand() { removingByHand = false; } internal static void RememberRemoved(PinData pin) { Player localPlayer = Player.m_localPlayer; if (removingByHand && RememberRemovedPins.Value && !((Object)(object)localPlayer == (Object)null) && pin != null && pin.m_ownerID != 0L) { HashSet<string> hashSet = RemovedPins(localPlayer); if (hashSet.Add(PinEntry(pin))) { localPlayer.m_customData[RemovedPinsKey] = string.Join(';'.ToString(), hashSet); } } } internal static void DropRemovedPins(Minimap map) { Player localPlayer = Player.m_localPlayer; if (!RememberRemovedPins.Value || (Object)(object)localPlayer == (Object)null || (Object)(object)map == (Object)null) { return; } if (AltHeld) { localPlayer.m_customData.Remove(RemovedPinsKey); return; } HashSet<string> removed = RemovedPins(localPlayer); if (removed.Count == 0) { return; } foreach (PinData item in (from pin in pins.Invoke(map) where pin.m_ownerID != 0L && removed.Contains(PinEntry(pin)) select pin).ToList()) { map.RemovePin(item); } } static CartographyTable() { PinType[] array = new PinType[5]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); placedPinTypes = (PinType[])(object)array; readSwitch = AccessTools.FieldRefAccess<MapTable, Switch>("m_readSwitch"); interactDistance = AccessTools.FieldRefAccess<Player, float>("m_maxInteractDistance"); noMap = AccessTools.StaticFieldRefAccess<bool>(AccessTools.Field(typeof(Game), "m_noMap")); visibleIconTypes = AccessTools.FieldRefAccess<Minimap, bool[]>("m_visibleIconTypes"); pins = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins"); pinUpdateRequired = AccessTools.FieldRefAccess<Minimap, bool>("m_pinUpdateRequired"); carts = AccessTools.StaticFieldRefAccess<List<Vagon>>(AccessTools.Field(typeof(Vagon), "m_instances")); hiddenTypes = new Dictionary<PinType, bool>(); vehiclePins = new Dictionary<Component, PinData>(); } } [HarmonyPatch(typeof(MapTable), "GetReadHoverText")] internal static class CartographyTableHoverPatch { private static void Postfix(ref string __result) { CartographyTable.AddRestoreHint(ref __result); } } [HarmonyPatch(typeof(MapTable), "OnRead", new Type[] { typeof(Switch), typeof(Humanoid), typeof(ItemData) })] internal static class CartographyTableReadPatch { private static void Postfix(MapTable __instance, Humanoid user, ItemData item) { CartographyTable.Open(__instance, user, item); } } [HarmonyPatch(typeof(Minimap), "SetMapMode")] internal static class CartographyTableMapModePatch { private static void Prefix(MapMode mode, out bool __state) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 __state = (int)mode == 2 && CartographyTable.Reading && CartographyTable.Applies; if (__state) { CartographyTable.NoMap = false; } } private static void Finalizer(MapMode mode, bool __state) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 if (__state) { CartographyTable.NoMap = true; } else if (CartographyTable.Reading && (int)mode != 2) { CartographyTable.Close(); } } } [HarmonyPatch(typeof(Minimap), "Update")] internal static class CartographyTableUpdatePatch { private static void Postfix(Minimap __instance) { if (CartographyTable.ShouldClose()) { CartographyTable.Close(); __instance.SetMapMode((MapMode)0); } else { CartographyTable.UpdateVehicles(__instance); } } } [HarmonyPatch(typeof(Minimap), "RemovePinUnderPointer")] internal static class RemovedPinByHandPatch { private static void Prefix() { CartographyTable.StartRemovingByHand(); } private static void Finalizer() { CartographyTable.StopRemovingByHand(); } } [HarmonyPatch(typeof(Minimap), "RemovePin", new Type[] { typeof(PinData) })] internal static class RememberRemovedPinPatch { private static void Prefix(PinData __0) { CartographyTable.RememberRemoved(__0); } } [HarmonyPatch(typeof(Minimap), "AddSharedMapData")] internal static class DropRemovedSharedPinsPatch { private static void Postfix(Minimap __instance) { CartographyTable.DropRemovedPins(__instance); } } internal static class Combat { private const string Section = "01 - Combat"; private const float CheckInterval = 0.25f; private const float DefaultEnemyRange = 30f; private const float MinEnemyRange = 5f; private const float MaxEnemyRange = 100f; private const float DefaultLinger = 5f; private const float MinLinger = 0f; private const float MaxLinger = 60f; internal static ConfigEntry<float> EnemyRange; internal static ConfigEntry<float> Linger; private static float lastFight = float.NegativeInfinity; private static float nextCheck; private static bool enemyAware; private static bool enemyNearby; internal static void Bind(CoreOverhaulPlugin plugin) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown EnemyRange = plugin.BindShared("01 - Combat", "EnemyRange", 30f, new ConfigDescription("You count as in combat while a hostile creature within this many meters is alerted or targeting you.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>())); Linger = plugin.BindShared("01 - Combat", "CombatLinger", 5f, new ConfigDescription("Seconds you stay in combat after you hit a creature or a creature hits you.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>())); } internal static void Fought() { lastFight = Time.time; } internal static bool InCombat(Player player) { if (Time.time - lastFight < Linger.Value) { return true; } Scan(player); return enemyAware; } internal static bool EnemyNearby(Player player) { if (Time.time - lastFight < Linger.Value) { return true; } Scan(player); return enemyNearby; } private static void Scan(Player player) { //IL_003c: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) if (Time.time < nextCheck) { return; } nextCheck = Time.time + 0.25f; enemyAware = false; enemyNearby = false; float value = EnemyRange.Value; float num = value * value; Vector3 position = ((Component)player).transform.position; foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter == (Object)null || (Object)(object)allCharacter == (Object)(object)player || allCharacter.IsPlayer() || allCharacter.IsTamed() || allCharacter.IsDead()) { continue; } Vector3 val = ((Component)allCharacter).transform.position - position; if (((Vector3)(ref val)).sqrMagnitude > num) { continue; } BaseAI baseAI = allCharacter.GetBaseAI(); MonsterAI val2 = (MonsterAI)(object)((baseAI is MonsterAI) ? baseAI : null); if (val2 != null && BaseAI.IsEnemy(allCharacter, (Character)(object)player)) { enemyNearby = true; if (((BaseAI)val2).IsAlerted() || (Object)(object)((BaseAI)val2).GetTargetCreature() == (Object)(object)player) { enemyAware = true; break; } } } } } [HarmonyPatch(typeof(Character), "OnDamaged")] internal static class DamagedInCombatPatch { private static void Postfix(Character __instance, HitData __0) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && __0 != null) { Character attacker = __0.GetAttacker(); if ((Object)(object)attacker != (Object)null && (Object)(object)attacker != (Object)(object)__instance && !attacker.IsTamed()) { Combat.Fought(); } } } } [HarmonyPatch(typeof(Character), "Damage")] internal static class HitInCombatPatch { private static void Postfix(Character __instance, HitData __0) { if (__0 != null && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)__0.GetAttacker() != (Object)(object)Player.m_localPlayer) && (Object)(object)__instance != (Object)(object)Player.m_localPlayer && !__instance.IsPlayer() && !__instance.IsTamed()) { Combat.Fought(); } } } [BepInPlugin("com.dreich.coreoverhaul", "Core Overhaul", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("com.dreich.parryrework")] [BepInIncompatibility("com.dreich.grapplehookskill")] [BepInIncompatibility("com.dreich.keeploaded")] [BepInIncompatibility("com.dreich.hammerrepairradius")] [BepInIncompatibility("com.dreich.wisplightupgrades")] [BepInIncompatibility("com.dreich.linkedstations")] [BepInIncompatibility("com.dreich.nomapcartographytable")] public class CoreOverhaulPlugin : BaseUnityPlugin { public const string Guid = "com.dreich.coreoverhaul"; public const string Name = "Core Overhaul"; public const string Version = "1.0.2"; internal const string ConfigSyncGuid = "_shudnal.ConditionalConfigSync"; internal const string TreasureMapsGuid = "com.dreich.treasuremaps"; internal const string ImpactfulSkillsGuid = "MidnightsFX.ImpactfulSkills"; private const string ParryReworkGuid = "com.dreich.parryrework"; private const string GrappleHookSkillGuid = "com.dreich.grapplehookskill"; private const string KeepLoadedGuid = "com.dreich.keeploaded"; private const string HammerRepairRadiusGuid = "com.dreich.hammerrepairradius"; private const string WisplightUpgradesGuid = "com.dreich.wisplightupgrades"; private const string LinkedStationsGuid = "com.dreich.linkedstations"; private const string NoMapCartographyTableGuid = "com.dreich.nomapcartographytable"; internal static ManualLogSource Log; internal static bool ConfigSyncAvailable; private static bool? treasureMaps; private static bool? impactfulSkills; private static ConfigEntry<bool> configLocked; internal static bool TreasureMapsAvailable { get { bool? flag = treasureMaps; if (!flag.HasValue) { bool? flag2 = (treasureMaps = Chainloader.PluginInfos.ContainsKey("com.dreich.treasuremaps")); return flag2.Value; } return flag == true; } } internal static bool ImpactfulSkillsAvailable { get { bool? flag = impactfulSkills; if (!flag.HasValue) { bool? flag2 = (impactfulSkills = Chainloader.PluginInfos.ContainsKey("MidnightsFX.ImpactfulSkills")); return flag2.Value; } return flag == true; } } private void Awake() { //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ConfigSyncAvailable = Chainloader.PluginInfos.ContainsKey("_shudnal.ConditionalConfigSync"); if (ConfigSyncAvailable) { ConfigSyncCompat.Initialize("com.dreich.coreoverhaul", "Core Overhaul", "1.0.2"); } configLocked = ((BaseUnityPlugin)this).Config.Bind<bool>("00 - General", "Lock Configuration", true, "If on, the configuration is locked and can be changed by server admins only. Requires ConditionalConfigSync."); if (ConfigSyncAvailable) { ConfigSyncCompat.AddLockingConfigEntry(configLocked); } ParryConfig.Bind(this); TowerShields.Bind(this); AutoShield.Bind(this); Combat.Bind(this); FreeStamina.Bind(this); Bows.Bind(this); Crossbows.Bind(this); Sneak.Bind(this); Building.Bind(this); WeightInventory.Bind(this); FallDamage.Bind(this); Respawn.Bind(this); GrapplingHook.Bind(this); HammerRepair.Bind(this); Specialization.Bind(this); Food.Bind(this); TerrainTools.Bind(this); Progression.Bind(this); Armor.Bind(this); WeaponDamage.Bind(this); EquipLoad.Bind(this); Wisplight.Bind(this); LinkedStations.Bind(this); EarlyMagic.Bind(this); DeadRaiser.Bind(this); EmberStaff.Bind(this); Ballista.Bind(this); Paths.Bind(this); CartographyTable.Bind(this); UpgradeChanges.Bind(this); Harmony val = new Harmony("com.dreich.coreoverhaul"); val.PatchAll(); Wisplight.PatchMods(val); } internal ConfigEntry<T> BindShared<T>(string section, string key, T defaultValue, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return BindShared(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } internal ConfigEntry<T> BindShared<T>(string section, string key, T defaultValue, ConfigDescription description) { ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description); if (ConfigSyncAvailable) { ConfigSyncCompat.AddConfigEntry<T>(val); } return val; } internal ConfigEntry<T> BindLocal<T>(string section, string key, T defaultValue, string description) { return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description); } } internal static class ConfigSyncCompat { private static object configSync; [MethodImpl(MethodImplOptions.NoInlining)] internal static void Initialize(string guid, string name, string version) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown configSync = (object)new ConfigSync(guid) { DisplayName = name, CurrentVersion = version, MinimumRequiredVersion = version, ModRequired = true }; } [MethodImpl(MethodImplOptions.NoInlining)] internal static void AddLockingConfigEntry(ConfigEntry<bool> entry) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) ((ConditionalConfigSync)(ConfigSync)configSync).AddLockingConfigEntry<bool>(entry); } [MethodImpl(MethodImplOptions.NoInlining)] internal static void AddConfigEntry<T>(ConfigEntry<T> entry) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) ((ConditionalConfigSync)(ConfigSync)configSync).AddConfigEntry<T>(entry, (ConfigSyncMode)0); } } internal static class ModTypes { internal static Type Find(string assemblyName, string typeName) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetName().Name == assemblyName) { return assembly.GetType(typeName); } } return null; } } internal static class JatifyState { private const string Assembly = "JatifyUI"; private const string PluginType = "Jatify.UI.Plugin"; private const string InstanceField = "Instance"; private static bool looked; private static FieldInfo instance; internal static bool Running { get { if (!looked) { looked = true; Type type = ModTypes.Find("JatifyUI", "Jatify.UI.Plugin"); instance = ((type != null) ? AccessTools.Field(type, "Instance") : null); } object? obj = instance?.GetValue(null); Behaviour val = (Behaviour)((obj is Behaviour) ? obj : null); if (val != null && (Object)(object)val != (Object)null) { return val.enabled; } return false; } } } internal static class Crossbows { private sealed class Original { internal float Reload; internal DamageTypes Damage; internal DamageTypes DamagePerLevel; } private const string Section = "07 - Crossbows"; private const float DefaultReload = 1.3f; private const float MinReload = 0.25f; private const float MaxReload = 3f; private const float DefaultDamage = 1.5f; private const float MinDamage = 0.25f; private const float MaxDamage = 5f; private const float DefaultSkillGain = 3f; private const float MinSkillGain = 1f; private const float MaxSkillGain = 10f; internal static ConfigEntry<float> ReloadMultiplier; internal static ConfigEntry<float> DamageMultiplier; internal static ConfigEntry<float> SkillGain; internal static ConfigEntry<bool> KeepReloadProgress; private static readonly Dictionary<SharedData, Original> originals = new Dictionary<SharedData, Original>(); internal static void Bind(CoreOverhaulPlugin plugin) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown ReloadMultiplier = plugin.BindShared("07 - Crossbows", "ReloadTimeMultiplier", 1.3f, new ConfigDescription("Multiplies the crossbow's base reload time. Vanilla is 3.5 seconds, so 1.3 makes it about 4.5. The Crossbows skill still halves it at level 100.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 3f), Array.Empty<object>())); DamageMultiplier = plugin.BindShared("07 - Crossbows", "DamageMultiplier", 1.5f, new ConfigDescription("Multiplies the crossbow's own damage. Bolts add their damage on top as usual.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 5f), Array.Empty<object>())); SkillGain = plugin.BindShared("07 - Crossbows", "SkillGainMultiplier", 3f, new ConfigDescription("Multiplies Crossbows skill experience. A crossbow fires about a third as often as a bow, so 3 levels it at the bow's pace.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); KeepReloadProgress = plugin.BindShared("07 - Crossbows", "KeepReloadProgress", defaultValue: true, "An interrupted reload, from sprinting, jumping or swapping weapons, picks up where it left off instead of starting over."); KeepLoaded.Crossbow = plugin.BindShared("07 - Crossbows", "KeepLoaded", defaultValue: true, "A loaded crossbow stays loaded when you put it away or drop it, until you fire it."); ReloadMultiplier.SettingChanged += delegate { Apply(); }; DamageMultiplier.SettingChanged += delegate { Apply(); }; } private static bool IsCrossbow(ItemData item) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 if (item != null && item.m_shared != null && (int)item.m_shared.m_skillType == 14 && item.m_shared.m_attack != null && item.m_shared.m_attack.m_requiresReload) { return !GrapplingHook.IsHook(item); } return false; } internal static void Apply() { //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null || instance.m_items == null) { return; } foreach (GameObject item in instance.m_items) { ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null); if (!((Object)(object)val == (Object)null) && IsCrossbow(val.m_itemData)) { SharedData shared = val.m_itemData.m_shared; if (!originals.TryGetValue(shared, out var value)) { value = new Original { Reload = shared.m_attack.m_reloadTime, Damage = ((DamageTypes)(ref shared.m_damages)).Clone(), DamagePerLevel = ((DamageTypes)(ref shared.m_damagesPerLevel)).Clone() }; originals[shared] = value; } shared.m_attack.m_reloadTime = value.Reload * ReloadMultiplier.Value; shared.m_damages = ((DamageTypes)(ref value.Damage)).Clone(); ((DamageTypes)(ref shared.m_damages)).Modify(DamageMultiplier.Value); shared.m_damagesPerLevel = ((DamageTypes)(ref value.DamagePerLevel)).Clone(); ((DamageTypes)(ref shared.m_damagesPerLevel)).Modify(DamageMultiplier.Value); } } } } [HarmonyPatch(typeof(Skills), "RaiseSkill")] internal static class CrossbowSkillPatch { private static void Prefix(SkillType __0, ref float __1) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 if ((int)__0 == 14) { __1 *= Crossbows.SkillGain.Value; } } } internal static class ReloadProgress { private const int ReloadAction = 2; private const float AlmostDone = 0.95f; private static readonly FieldInfo Queue = AccessTools.Field(typeof(Player), "m_actionQueue"); private static ItemData savedItem; private static float savedTime; private static object FindReload(Player player) { if (!(Queue?.GetValue(player) is IList list)) { return null; } foreach (object item in list) { if (item != null) { object obj = AccessTools.Field(item.GetType(), "m_type")?.GetValue(item); if (obj != null && Convert.ToInt32(obj) == 2) { return item; } } } return null; } private static float Read(object action, string field) { return (float)AccessTools.Field(action.GetType(), field).GetValue(action); } internal static void Remember(Player player) { if (Crossbows.KeepReloadProgress.Value && !((Object)(object)player != (Object)(object)Player.m_localPlayer)) { object obj = FindReload(player); if (obj != null) { object? value = AccessTools.Field(obj.GetType(), "m_item").GetValue(obj); savedItem = (ItemData)((value is ItemData) ? value : null); savedTime = Read(obj, "m_time"); } } } internal static void Restore(Player player) { if (Crossbows.KeepReloadProgress.Value && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && savedItem != null) { object obj = FindReload(player); if (obj != null && AccessTools.Field(obj.GetType(), "m_item").GetValue(obj) == savedItem) { float num = Read(obj, "m_duration"); AccessTools.Field(obj.GetType(), "m_time").SetValue(obj, Mathf.Min(savedTime, num * 0.95f)); savedItem = null; } } } internal static void Forget() { savedItem = null; } } [HarmonyPatch(typeof(Player), "CancelReloadAction")] internal static class CancelReloadPatch { private static void Prefix(Player __instance) { ReloadProgress.Remember(__instance); } } [HarmonyPatch(typeof(Player), "ClearActionQueue")] internal static class ClearQueuePatch { private static void Prefix(Player __instance) { ReloadProgress.Remember(__instance); } } [HarmonyPatch(typeof(Player), "QueueReloadAction")] internal static class QueueReloadPatch { private static void Postfix(Player __instance) { ReloadProgress.Restore(__instance); } } [HarmonyPatch(typeof(Player), "SetWeaponLoaded")] internal static class LoadedPatch { private static void Postfix(ItemData __0) { if (__0 != null) { ReloadProgress.Forget(); } } } internal static class KeepLoaded { private const string LoadedKey = "KeepLoaded_Loaded"; private const string LoadedValue = "1"; internal static ConfigEntry<bool> Crossbow; internal static ConfigEntry<bool> Hook; internal static bool Unequipping; internal static bool Applies(ItemData item) { if (item?.m_shared?.m_attack == null || !item.m_shared.m_attack.m_requiresReload) { return false; } if (!GrapplingHook.IsHook(item)) { return Crossbow.Value; } return Hook.Value; } internal static bool IsLoaded(ItemData item) { if (item?.m_customData != null) { return item.m_customData.ContainsKey("KeepLoaded_Loaded"); } return false; } internal static void MarkLoaded(ItemData item) { if (item?.m_customData != null) { item.m_customData["KeepLoaded_Loaded"] = "1"; } } internal static void MarkUnloaded(ItemData item) { item?.m_customData?.Remove("KeepLoaded_Loaded"); } } [HarmonyPatch(typeof(Player), "SetWeaponLoaded")] internal static class KeepLoadedMarkPatch { private static void Postfix(Player __instance, ItemData __0) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && __0 != null && KeepLoaded.Applies(__0)) { KeepLoaded.MarkLoaded(__0); } } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] internal static class KeepLoadedUnequipPatch { private static void Prefix(Humanoid __instance, ItemData __0) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { KeepLoaded.Unequipping = true; if (KeepLoaded.IsLoaded(__0) && !KeepLoaded.Applies(__0)) { KeepLoaded.MarkUnloaded(__0); } } } private static void Finalizer() { KeepLoaded.Unequipping = false; } } [HarmonyPatch(typeof(Player), "ResetLoadedWeapon")] internal static class KeepLoadedFiredPatch { private static void Prefix(Player __instance, ItemData ___m_weaponLoaded) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && !KeepLoaded.Unequipping) { KeepLoaded.MarkUnloaded(___m_weaponLoaded); } } } [HarmonyPatch(typeof(Player), "UpdateWeaponLoading")] internal static class KeepLoadedRestorePatch { private static readonly Action<Player> cancelReload = AccessTools.MethodDelegate<Action<Player>>(AccessTools.Method(typeof(Player), "CancelReloadAction", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player, ItemData> setLoaded = AccessTools.MethodDelegate<Action<Player, ItemData>>(AccessTools.Method(typeof(Player), "SetWeaponLoaded", (Type[])null, (Type[])null), (object)null, true); private static bool Prefix(Player __instance, ItemData __0, ItemData ___m_weaponLoaded) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || __0 == null || ___m_weaponLoaded == __0) { return true; } if (!KeepLoaded.Applies(__0) || !KeepLoaded.IsLoaded(__0)) { return true; } cancelReload(__instance); setLoaded(__instance, __0); return false; } } internal static class DeadRaiser { internal const string Prefab = "StaffSkeleton"; private const string FriendlySkeletonPrefab = "Skeleton_Friendly"; private const string SkeletonPrefab = "Skeleton"; private const string DraugrPrefab = "Draugr"; private const string DraugrElitePrefab = "Draugr_Elite"; private const string WarriorSummonPrefab = "CoreOverhaul_SkeletonWarrior"; private const string ArcherSummonPrefab = "CoreOverhaul_SkeletonArcher"; private const string DraugrSummonPrefab = "CoreOverhaul_DraugrSummon"; private const string DraugrEliteSummonPrefab = "CoreOverhaul_DraugrEliteSummon"; private const int FirstLevel = 1; private const int ArcherLevel = 2; private const int DraugrLevel = 3; private const int DraugrEliteLevel = 4; private const int SingleSummon = 1; private const int SecondLevel = 2; private const float DefaultFirstLevelEitr = 10f; private const float DefaultSecondLevelEitr = 15f; private const float DefaultBaseHealthCost = 10f; private const float MinCost = 0f; private const float MaxEitrCost = 200f; private const float MaxHealthCost = 100f; private const float PercentScale = 100f; private const float SkillDiscount = 0.33f; private const float DefaultDraugrHealth = 2f; private const float DefaultDraugrEliteHealth = 3f; private const float MinSummonHealth = 0.5f; private const float MaxSummonHealth = 10f; internal static ConfigEntry<float> FirstLevelEitr; internal static ConfigEntry<float> SecondLevelEitr; internal static ConfigEntry<float> BaseHealthCost; internal static ConfigEntry<bool> NormalSkeletons; internal static ConfigEntry<float> DraugrHealth; internal static ConfigEntry<float> DraugrEliteHealth; private static readonly MethodInfo setupSpawn = AccessTools.Method(typeof(SpawnAbility), "Setup", (Type[])null, (Type[])null); private static readonly HashSet<ItemType> weaponTypes = new HashSet<ItemType> { (ItemType)3, (ItemType)14, (ItemType)22, (ItemType)4 }; private static readonly List<GameObject> summons = new List<GameObject>(); private static SharedData shared; private static float vanillaEitrCost; private static float vanillaHealthCost; private static GameObject warrior; private static GameObject archer; private static GameObject draugr; private static GameObject draugrElite; private static bool splitting; internal static void Bind(CoreOverhaulPlugin plugin) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Expected O, but got Unknown FirstLevelEitr = plugin.BindShared("08 - Early Magic", "DeadRaiserLevel1EitrCost", 10f, new ConfigDescription("Eitr a level 1 Dead Raiser costs to cast, so it works with the 20 eitr from a lesser eitr mead.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>())); SecondLevelEitr = plugin.BindShared("08 - Early Magic", "DeadRaiserLevel2EitrCost", 15f, new ConfigDescription("Eitr a level 2 Dead Raiser costs to cast. Higher levels rise evenly from this until they match vanilla's 100 at the highest level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>())); BaseHealthCost = plugin.BindShared("08 - Early Magic", "DeadRaiserHealthCost", 10f, new ConfigDescription("Percent of your current health a level 1 Dead Raiser costs to cast. It rises evenly with each level until it matches vanilla's 40% at the highest level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); NormalSkeletons = plugin.BindShared("08 - Early Magic", "DeadRaiserNormalSkeletons", defaultValue: true, "The skeletons a level 1 or 2 Dead Raiser summons have a normal skeleton's health, weapons and resistances, instead of the much tougher skeleton the vanilla staff summons. Applies to skeletons summoned from then on."); DraugrHealth = plugin.BindShared("08 - Early Magic", "DeadRaiserDraugrHealth", 2f, new ConfigDescription("Health of the draugr a level 3 Dead Raiser summons, as a multiple of a normal draugr's. Applies to draugr summoned from then on.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>())); DraugrEliteHealth = plugin.BindShared("08 - Early Magic", "DeadRaiserDraugrEliteHealth", 3f, new ConfigDescription("Health of the draugr elite a level 4 Dead Raiser summons, as a multiple of a normal draugr elite's. Applies to draugr elites summoned from then on.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>())); NormalSkeletons.SettingChanged += delegate { ApplySummons(); }; DraugrHealth.SettingChanged += delegate { ApplySummons(); }; DraugrEliteHealth.SettingChanged += delegate { ApplySummons(); }; FirstLevelEitr.SettingChanged += delegate { ResetCosts(); }; SecondLevelEitr.SettingChanged += delegate { ResetCosts(); }; BaseHealthCost.SettingChanged += delegate { ResetCosts(); }; } internal static void Apply(ObjectDB db) { SharedData val = EarlyMagic.SharedOf(db, "StaffSkeleton"); if (val?.m_attack != null && val != shared) { shared = val; vanillaEitrCost = val.m_attack.m_attackEitr; vanillaHealthCost = val.m_attack.m_attackHealthPercentage; } ResetCosts(); ApplySummons(); } internal static void ResetCosts() { if (shared?.m_attack != null) { shared.m_attack.m_attackEitr = FirstLevelEitr.Value; shared.m_attack.m_attackHealthPercentage = BaseHealthCost.Value; } } internal static bool IsStaff(ItemData item) { if (item?.m_shared != null && shared != null) { return item.m_shared.m_name == shared.m_name; } return false; } private static int Level(ItemData item) { return Mathf.Max(1, item.m_quality); } private static float Progress(int level) { return EarlyMagic.LevelProgress(level, shared.m_maxQuality); } private static float EitrCost(int level) { if (level <= 1) { return FirstLevelEitr.Value; } if (level == 2 || shared.m_maxQuality <= 2) { return SecondLevelEitr.Value; } float num = Mathf.Clamp01((float)(level - 2) / (float)(shared.m_maxQuality - 2)); return Mathf.Lerp(SecondLevelEitr.Value, vanillaEitrCost, num); } private static float HealthCost(int level) { return Mathf.Lerp(BaseHealthCost.Value, vanillaHealthCost, Progress(level)); } private static float AfterSkill(float cost, Character character, ItemData weapon) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) return cost - cost * 0.33f * character.GetSkillFactor(weapon.m_shared.m_skillType); } internal static void ScaleEitrCost(Character character, ItemData weapon, ref float cost) { if (!((Object)(object)character == (Object)null) && IsStaff(weapon)) { cost = AfterSkill(EitrCost(Level(weapon)), character, weapon); } } internal static void ScaleHealthCost(Character character, ItemData weapon, float flatHealth, ref float cost) { if (!((Object)(object)character == (Object)null) && IsStaff(weapon)) { float cost2 = flatHealth + character.GetHealth() * HealthCost(Level(weapon)) / 100f; cost = AfterSkill(cost2, character, weapon); } } internal static void ShowLevelCosts(ItemData item, int level) { if (IsStaff(item) && item.m_shared.m_attack != null) { item.m_shared.m_attack.m_attackEitr = EitrCost(Mathf.Max(1, level)); item.m_shared.m_attack.m_attackHealthPercentage = HealthCost(Mathf.Max(1, level)); } } private static void ApplySummons() { ZNetScene instance = ZNetScene.instance; if ((Object)(object)instance == (Object)null) { return; } if (summons.Count == 0) { GameObject prefab = instance.GetPrefab("Skeleton_Friendly"); if ((Object)(object)prefab == (Object)null) { return; } warrior = MakeSkeleton(prefab, "CoreOverhaul_SkeletonWarrior"); archer = MakeSkeleton(prefab, "CoreOverhaul_SkeletonArcher"); draugr = MakeDraugr(instance.GetPrefab("Draugr"), prefab, "CoreOverhaul_DraugrSummon"); draugrElite = MakeDraugr(instance.GetPrefab("Draugr_Elite"), prefab, "CoreOverhaul_DraugrEliteSummon"); } ApplySummonStats(instance); foreach (GameObject summon in summons) { EarlyMagic.Register(summon); } } private static void ApplySummonStats(ZNetScene scene) { GameObject prefab = scene.GetPrefab("Skeleton_Friendly"); GameObject prefab2 = scene.GetPrefab("Skeleton"); if (!((Object)(object)prefab == (Object)null)) { GameObject val = ((NormalSkeletons.Value && (Object)(object)prefab2 != (Object)null) ? prefab2 : prefab); List<GameObject> weapons = Weapons(val, prefab, prefab2); GameObject weapon = FindWeapon(weapons, (SharedData item) => (int)item.m_skillType == 1) ?? FindWeapon(weapons, (SharedData item) => (int)item.m_itemType != 4); GameObject weapon2 = FindWeapon(weapons, (SharedData item) => (int)item.m_itemType == 4); Equip(warrior, prefab, val, weapon); Equip(archer, prefab, val, weapon2); Toughen(draugr, scene.GetPrefab("Draugr"), DraugrHealth.Value); Toughen(draugrElite, scene.GetPrefab("Draugr_Elite"), DraugrEliteHealth.Value); } } private static void Equip(GameObject summon, GameObject friendly, GameObject like, GameObject weapon) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)summon == (Object)null) && !((Object)(object)weapon == (Object)null)) { List<GameObject> list = ((IEnumerable<GameObject>)(((object)friendly.GetComponent<Humanoid>().m_defaultItems) ?? ((object)new GameObject[0]))).Where((GameObject item) => !IsWeapon(item)).ToList(); list.Add(weapon); summon.GetComponent<Humanoid>().m_defaultItems = list.ToArray(); Character component = like.GetComponent<Character>(); Character component2 = summon.GetComponent<Character>(); component2.m_health = component.m_health; component2.m_damageModifiers = component.m_damageModifiers; } } private static void Toughen(GameObject summon, GameObject source, float healthMultiplier) { Character val = (((Object)(object)summon != (Object)null) ? summon.GetComponent<Character>() : null); Character val2 = (((Object)(object)source != (Object)null) ? source.GetComponent<Character>() : null); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null) { val.m_health = val2.m_health * healthMultiplier; } } private static List<GameObject> Weapons(params GameObject[] creatures) { List<GameObject> list = new List<GameObject>(); foreach (GameObject val in creatures) { Humanoid val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Humanoid>() : null); if ((Object)(object)val2 == (Object)null) { continue; } if (val2.m_defaultItems != null) { list.AddRange(val2.m_defaultItems); } if (val2.m_randomWeapon != null) { list.AddRange(val2.m_randomWeapon); } if (val2.m_randomSets == null) { continue; } ItemSet[] randomSets = val2.m_randomSets; foreach (ItemSet val3 in randomSets) { if (val3?.m_items != null) { list.AddRange(val3.m_items); } } } return list.Where(IsWeapon).ToList(); } private static bool IsWeapon(GameObject item) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null); if ((Object)(object)val != (Object)null) { return weaponTypes.Contains(val.m_itemData.m_shared.m_itemType); } return false; } private static GameObject FindWeapon(List<GameObject> weapons, Func<SharedData, bool> match) { return ((IEnumerable<GameObject>)weapons).FirstOrDefault((Func<GameObject, bool>)((GameObject weapon) => match(weapon.GetComponent<ItemDrop>().m_itemData.m_shared))); } private static GameObject MakeSkeleton(GameObject friendly, string name) { GameObject val = Object.Instantiate<GameObject>(friendly, EarlyMagic.Container().transform); ((Object)val).name = name; Humanoid component = val.GetComponent<Humanoid>(); if (component.m_randomWeapon != null) { Array.Resize(ref component.m_randomWeapon, 0); } if (component.m_randomSets != null) { Array.Resize(ref component.m_randomSets, 0); } summons.Add(val); return val; } private static GameObject MakeDraugr(GameObject source, GameObject friendly, string name) { //IL_0045: 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) if ((Object)(object)source == (Object)null) { return null; } GameObject val = Object.Instantiate<GameObject>(source, EarlyMagic.Container().transform); ((Object)val).name = name; Character component = val.GetComponent<Character>(); Character component2 = friendly.GetComponent<Character>(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null) { component.m_faction = component2.m_faction; } MonsterAI component3 = val.GetComponent<MonsterAI>(); MonsterAI component4 = friendly.GetComponent<MonsterAI>(); if ((Object)(object)component3 != (Object)null && (Object)(object)component4 != (Object)null) { component3.m_enableHuntPlayer = component4.m_enableHuntPlayer; component3.m_attackPlayerObjects = component4.m_attackPlayerObjects; } CopyComponent<Tameable>(friendly, val); CopyComponent<CharacterTimedDestruction>(friendly, val); CharacterDrop[] components = val.GetComponents<CharacterDrop>(); for (int i = 0; i < components.Length; i++) { Object.DestroyImmediate((Object)(object)components[i]); } summons.Add(val); return val; } private static void CopyComponent<T>(GameObject from, GameObject to) where T : Component { T component = from.GetComponent<T>(); if ((Object)(object)component == (Object)null) { return; } T val = to.GetComponent<T>(); if ((Object)(object)val == (Object)null) { val = to.AddComponent<T>(); } FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if ((fieldInfo.IsPublic && !fieldInfo.IsNotSerialized) || fieldInfo.IsDefined(typeof(SerializeField), inherit: true)) { fieldInfo.SetValue(val, fieldInfo.GetValue(component)); } } } private static GameObject[] Tier(int level) { GameObject[] source = (GameObject[])(object)((level >= 4) ? new GameObject[1] { draugrElite } : ((level >= 3) ? new GameObject[1] { draugr } : ((level < 2) ? new GameObject[1] { warrior } : new GameObject[2] { warrior, archer }))); return source.Where((GameObject summon) => (Object)(object)summon != (Object)null).ToArray(); } internal static void PrepareSummon(SpawnAbility ability, ItemData weapon, object[] setupArgs) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) if (splitting || (Object)(object)ability == (Object)null || !IsStaff(weapon)) { return; } GameObject[] array = Tier(Level(weapon)); if (array.Length == 0) { return; } Summon(ability, array[0]); for (int i = 1; i < array.Length; i++) { SpawnAbility component = Object.Instantiate<GameObject>(((Component)ability).gameObject, ((Component)ability).transform.position, ((Component)ability).transform.rotation).GetComponent<SpawnAbility>(); Summon(component, array[i]); splitting = true; try { setupSpawn.Invoke(component, setupArgs); } finally { splitting = false; } } } private static void Summon(SpawnAbility ability, GameObject prefab) { ability.m_spawnPrefab = (GameObject[])(object)new GameObject[1] { prefab }; ability.m_minToSpawn = 1; ability.m_maxToSpawn = 1; } } [HarmonyPatch] internal static class DeadRaiserEitrPatch { private const int ParameterCount = 2; private static MethodBase TargetMethod() { return AccessTools.GetDeclaredMethods(typeof(Attack)).First((MethodInfo method) => method.Name == "GetAttackEitr" && method.GetParameters().Length == 2); } private static void Postfix(Character __0, ItemData __1, ref float __result) { DeadRaiser.ScaleEitrCost(__0, __1, ref __result); } } [HarmonyPatch(typeof(Attack), "GetAttackHealth")] internal static class DeadRaiserHealthPatch { private static void Postfix(Character ___m_character, ItemData ___m_weapon, float ___m_attackHealth, ref float __result) { DeadRaiser.ScaleHealthCost(___m_character, ___m_weapon, ___m_attackHealth, ref __result); } } [HarmonyPatch] internal static class DeadRaiserTooltipPatch { private static MethodBase TargetMethod() { return AccessTools.GetDeclaredMethods(typeof(ItemData)).First((MethodInfo method) => method.Name == "GetTooltip" && method.IsStatic); } private static void Prefix(ItemData __0, int __1) { DeadRaiser.ShowLevelCosts(__0, __1); } private static void Finalizer(ItemData __0) { if (DeadRaiser.IsStaff(__0)) { DeadRaiser.ResetCosts(); } } } [HarmonyPatch(typeof(SpawnAbility), "Setup")] internal static class DeadRaiserSummonPatch { private static void Prefix(SpawnAbility __instance, ItemData __4, object[] __args) { DeadRaiser.PrepareSummon(__instance, __4, __args); } } internal static class EarlyMagic { private sealed class EitrMead { internal readonly string LookPrefab; internal readonly string Prefab; internal readonly string EffectName; internal readonly string Name; internal readonly string Description; internal readonly string SoldAfter; internal ConfigEntry<int> Price; internal ConfigEntry<float> Eitr; internal GameObject Item; internal SE_Stats Effect; internal EitrMead(string lookPrefab, string prefab, string effectName, string name, string description, string soldAfter) { LookPrefab = lookPrefab; Prefab = prefab; EffectName = effectName; Name = name; Description = description; SoldAfter = soldAfter; } } internal const string Section = "08 - Early Magic"; private const string ContainerName = "CoreOverhaul_MagicPrefabs"; private const string ElderKey = "defeated_gdking"; private const string ModerKey = "defeated_dragon"; private const string HaldorPrefab = "Haldor"; private const string ForgePrefab = "forge"; private const string JatifyAssembly = "JatifyUI"; private const string JatifyTooltipType = "Jatify.UI.ItemTip"; private const string BoughtKeyPrefix = "CoreOverhaul_Bought_"; private const string NoBuyLimit = ""; private const string MeadSourcePrefab = "MeadEitrMinor"; private const string MeadPrefab = "CoreOverhaul_MeadEitr"; private const string MeadEffectName = "CoreOverhaul_EitrMead"; private const string MeadCategory = "CoreOverhaul_EitrMead"; private const string MeadName = "Lesser eitr mead"; private const string MeadDescription = "A thin mead brewed with a trace of eitr. While it lasts, even those who have never eaten a mage's meal can draw on a small pool of eitr, which refills on its own."; private const string MediumMeadLookPrefab = "MeadEitrLingering"; private const string MediumMeadPrefab = "CoreOverhaul_MeadEitrMedium"; private const string MediumMeadEffectName = "CoreOverhaul_EitrMeadMedium"; private const string MediumMeadName = "Medium eitr mead"; private const string MediumMeadDescription = "A stronger mead brewed with eitr. While it lasts, even those who have never eaten a mage's meal can draw on a pool of eitr, which refills on its own."; private const string MeadTooltipFormat = "Max eitr: <color=orange>+{0}</color>"; private const string DefaultUpgradeCosts = "2=DragonTear:1,Silver:10; 3=Eitr:10,YggdrasilWood:10; 4=Eitr:20,BlackCore:1"; private const string UpgradeCostsDescription = "What each upgrade costs, as level=Item:amount pairs, with levels separated by semicolons. Level 2 is made at the forge, and every level after that at the galdr table like vanilla."; private const int FirstLevel = 1; private const int ForgeLevel = 2; private const int FirstStationLevel = 1; private const int SingleItem = 1; private const int DefaultStaffPrice = 1500; private const int DefaultMeadPrice = 60; private const int DefaultMediumMeadPrice = 80; private const int MinPrice = 1; private const int MaxPrice = 10000; private const float DefaultMeadEitr = 20f; private const float DefaultMediumMeadEitr = 40f; private const float MinMeadEitr = 1f; private const float MaxMeadEitr = 200f; private const float DefaultMeadDuration = 600f; private const float MinMeadDuration = 30f; private const float MaxMeadDuration = 3600f; private const float NoEitr = 0f; private const float CastingMargin = 0.5f; private const float FullProgress = 1f; internal static ConfigEntry<int> DeadRaiserPrice; internal static ConfigEntry<int> EmberStaffPrice; internal static ConfigEntry<float> MeadDuration; internal static ConfigEntry<string> DeadRaiserUpgradeCosts; internal static ConfigEntry<string> EmberStaffUpgradeCosts; private static readonly MethodInfo addKnownRecipe = AccessTools.Method(typeof(Player), "AddKnownRecipe", new Type[1] { typeof(Recipe) }, (Type[])null); private static readonly MethodInfo updateRegisters = AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null); private static readonly FieldInfo namedPrefabs = AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs"); private static readonly string[] staffPrefabs = new string[2] { "StaffSkeleton", "StaffFireball" }; private static readonly HashSet<Recipe> staffRecipes = new HashSet<Recipe>(); private static GameObject container; private static readonly EitrMead lesserMead = new EitrMead("MeadEitrMinor", "CoreOverhaul_MeadEitr", "