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 NorseDemigodsPovBridge v0.6.0
NorseDemigodsPovBridge.dll
Decompiled 3 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace OblitusEs.DemigodsPovBridge { [BepInPlugin("OblitusEs.DemigodsPovBridge", "NorseDemigodsPovBridge", "0.6.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private struct Rule { public string Stat; public float Weight; } private sealed class Route { public bool Off; public bool Equipped; public bool ExplicitElement; public List<string> Stats = new List<string>(); public HashSet<string> Subjects = new HashSet<string>(StringComparer.OrdinalIgnoreCase); } public sealed class ClawState { public ItemData Weapon; public SharedData Original; } public const string Guid = "OblitusEs.DemigodsPovBridge"; public const string Name = "NorseDemigodsPovBridge"; public const string Version = "0.6.0"; internal static ManualLogSource Log; private static ConfigEntry<bool> cfgEnabled; private static ConfigEntry<string> cfgUnit; private static ConfigEntry<bool> cfgCapEnabled; private static ConfigEntry<float> cfgMaxBonus; private static ConfigEntry<string> cfgAlwaysStats; private static ConfigEntry<string> cfgHealingStats; private static ConfigEntry<string> cfgSummonStats; private static ConfigEntry<string> cfgAttributeRoute; private static ConfigEntry<string> cfgUnknownRoute; private static ConfigEntry<bool> cfgLogChanges; private static ConfigEntry<bool> cfgLogAllStats; private static ConfigEntry<bool> cfgLogRouting; private static ConfigEntry<string> cfgMode; private static ConfigEntry<bool> cfgLogScoped; private static ConfigEntry<bool> cfgLogValues; private static ConfigEntry<string> cfgCritMode; private static ConfigEntry<bool> cfgLogHits; private static ConfigEntry<bool> cfgClaws; private static ConfigEntry<string> cfgExtraClaws; private static readonly Dictionary<string, ConfigEntry<string>> abilityRoutes = new Dictionary<string, ConfigEntry<string>>(StringComparer.Ordinal); private static List<Rule> alwaysRules = new List<Rule>(); private static List<Rule> healingRules = new List<Rule>(); private static List<Rule> summonRules = new List<Rule>(); private static Func<string, float> povGet; private static HashSet<string> knownStats; private static List<string> knownList; private static bool ready; private static readonly Dictionary<string, KeyValuePair<int, float>> cache = new Dictionary<string, KeyValuePair<int, float>>(); private const int CacheMs = 200; private static readonly Dictionary<string, Route> routeCache = new Dictionary<string, Route>(StringComparer.Ordinal); private static readonly string[] NoStats = new string[0]; private static readonly Dictionary<string, string[]> RouteStats = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase) { { "SpellElemental", new string[4] { "Dmg_Magical", "Dmg_ElementalMagic", "Dmg_Staves", "Dmg_Scepters" } }, { "SpellBlood", new string[4] { "Dmg_Magical", "Dmg_BloodMagic", "Dmg_Staves", "Dmg_Scepters" } }, { "Staves", new string[2] { "Dmg_Magical", "Dmg_Staves" } }, { "Scepters", new string[2] { "Dmg_Magical", "Dmg_Scepters" } }, { "Swords", new string[1] { "Dmg_Swords" } }, { "Knives", new string[1] { "Dmg_Knives" } }, { "Clubs", new string[1] { "Dmg_Clubs" } }, { "Polearms", new string[1] { "Dmg_Polearms" } }, { "Spears", new string[1] { "Dmg_Spears" } }, { "Axes", new string[1] { "Dmg_Axes" } }, { "Unarmed", new string[1] { "Dmg_Unarmed" } }, { "Bows", new string[2] { "Dmg_Bows", "Dmg_Shooting" } }, { "Crossbows", new string[2] { "Dmg_Crossbows", "Dmg_Shooting" } } }; private static readonly Dictionary<string, string[]> RouteSubjects = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase) { { "SpellElemental", new string[5] { "Magical", "Spell", "Cast", "ElementalMagic", "Elemental" } }, { "SpellBlood", new string[4] { "Magical", "Spell", "Cast", "BloodMagic" } }, { "Staves", new string[4] { "Magical", "Spell", "Cast", "Staves" } }, { "Scepters", new string[4] { "Magical", "Spell", "Cast", "Scepters" } }, { "Swords", new string[4] { "Attack", "Melee", "Physical", "Swords" } }, { "Knives", new string[4] { "Attack", "Melee", "Physical", "Knives" } }, { "Clubs", new string[4] { "Attack", "Melee", "Physical", "Clubs" } }, { "Polearms", new string[4] { "Attack", "Melee", "Physical", "Polearms" } }, { "Spears", new string[4] { "Attack", "Melee", "Physical", "Spears" } }, { "Axes", new string[4] { "Attack", "Melee", "Physical", "Axes" } }, { "Unarmed", new string[4] { "Attack", "Melee", "Physical", "Fists" } }, { "Bows", new string[7] { "Attack", "Ranged", "Shooting", "Projectile", "Physical", "Bows", "Arrow" } }, { "Crossbows", new string[7] { "Attack", "Ranged", "Shooting", "Projectile", "Physical", "Crossbows", "Bolt" } } }; private static readonly HashSet<string> ElementTokens = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Fire", "Frost", "Lightning", "Poison", "Spirit", "Physical" }; private static readonly HashSet<string> TagTokens = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Projectile", "Area", "Minion" }; private static readonly Dictionary<string, string[]> ImpliedSubjects = new Dictionary<string, string[]>(StringComparer.Ordinal) { { "AbilityFireball", new string[2] { "Fire", "Projectile" } }, { "AbilityMeteor", new string[2] { "Fire", "Area" } }, { "AbilityBurningGround", new string[2] { "Fire", "Area" } }, { "AbilityFrostNova", new string[2] { "Frost", "Area" } }, { "AbilityIceshards", new string[2] { "Frost", "Projectile" } }, { "AbilityLightningBolt", new string[2] { "Lightning", "Projectile" } }, { "AbilityLightningStorm", new string[2] { "Lightning", "Area" } }, { "AbilityLightningStrike", new string[1] { "Lightning" } }, { "AbilityLightningTorpedo", new string[2] { "Lightning", "Projectile" } }, { "AbilityTornado", new string[1] { "Area" } }, { "AbilityPoisonCloud", new string[2] { "Poison", "Area" } }, { "AbilityPoisonJavelin", new string[2] { "Poison", "Projectile" } }, { "AbilityAcidBolt", new string[2] { "Poison", "Projectile" } } }; private static readonly string[] KnownAbilities = new string[38] { "AbilityAcidBolt", "AbilityArcaneBolt", "AbilityBlast", "AbilityBlink", "AbilityBloodSlash", "AbilityBomb", "AbilityBurningGround", "AbilityCleave", "AbilityCrush", "AbilityDash", "AbilityDecayAura", "AbilityElementalShield", "AbilityEnergyWisp", "AbilityEnraged", "AbilityFireball", "AbilityFrostNova", "AbilityHolyStrike", "AbilityHolySun", "AbilityIceshards", "AbilityInfusedArrow", "AbilityLightningBolt", "AbilityLightningStorm", "AbilityLightningStrike", "AbilityLightningTorpedo", "AbilityMeteor", "AbilityNanoCube", "AbilityPoisonCloud", "AbilityPoisonJavelin", "AbilityRestoration", "AbilitySacrifice", "AbilitySharpMist", "AbilitySlash", "AbilityStagger", "AbilityTornado", "AbilityVortex", "AbilityWaterSphere", "AbilityWhirlwind", "AbilityWolf" }; private const string RouteHelp = "Route(s) deciding which Path of Valheiman stats boost this ability. Combine several with commas (e.g. SpellElemental, Spears).\nSpellElemental / SpellBlood = Magical + Elemental (or Blood) magic + Staves + Scepters damage. Staves / Scepters = Magical + only that group.\nEquippedWeapon = the weapon you hold. Swords, Knives, Clubs, Polearms, Spears, Axes, Unarmed, Bows, Crossbows = that weapon's damage.\nNoCategory = only the 'always' stats (Damage > Stats). Off = leave this ability exactly as NorseDemigods made it.\nScoped modes also accept element/delivery tags: Fire, Frost, Lightning, Poison, Spirit, Physical, Projectile, Area, Minion (e.g. 'SpellElemental, Frost, Area'). If no element tag is given, a best guess from the ability's name is used."; private static Plugin instance; private static bool scopedReady; private static Type tStat; private static Type tSubject; private static Type tSubjects; private static MethodInfo miGet; private static MethodInfo miMul; private static MethodInfo miOf; private static Func<object> statSetGetter; private static bool scopedErrorLogged; private static object emptyScope; private static readonly Dictionary<string, object> statEnumCache = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, object> subjectEnumCache = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, object> scopeCache = new Dictionary<string, object>(StringComparer.Ordinal); private static readonly HashSet<string> warnedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private const float CritBaseMultiplier = 1.5f; private static readonly string[] HealingSubjects = new string[4] { "Healing", "Magical", "Spell", "Cast" }; private static readonly string[] SummonSubjects = new string[1] { "Minion" }; private static readonly Dictionary<string, string> lastScopedLine = new Dictionary<string, string>(StringComparer.Ordinal); private const string ClawAnimation = "dualaxes"; private const int ClawChain = 4; private const float ClawAngle = 90f; private const float ClawHeight = 0.6f; private static readonly MethodInfo memberwiseClone = typeof(object).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic); private static readonly Dictionary<SharedData, SharedData> clawShared = new Dictionary<SharedData, SharedData>(); private static readonly HashSet<string> clawLogged = new HashSet<string>(StringComparer.Ordinal); private static HashSet<string> extraClaws = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, string> lastValueLogged = new Dictionary<string, string>(StringComparer.Ordinal); private static readonly Dictionary<string, float> lastRouteLogged = new Dictionary<string, float>(StringComparer.Ordinal); private float nextLog; private string lastLine = ""; private string lastAllLine = ""; private void Awake() { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown instance = this; Log = ((BaseUnityPlugin)this).Logger; cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch. When false the bridge does nothing."); cfgUnit = ((BaseUnityPlugin)this).Config.Bind<string>("General", "StatUnit", "Fraction", new ConfigDescription("How Path of Valheiman reports its stat totals. 'Fraction' means 0.12 = +12% (confirmed for PoV 5.3.6). 'Percent' means 12 = +12%.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Fraction", "Percent" }), Array.Empty<object>())); cfgMode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ScalingMode", "Scoped", new ConfigDescription("How the damage bonus is read from Path of Valheiman.\nScoped = ask PoV for DamagePct as it would apply to that ability (spell/weapon/element-specific nodes count only where they fit). Route stat names other than DamagePct are not added on top. Falls back to StatNames if PoV's internals can't be reached.\nStatNames = add up the named stats of the ability's route (the original method; per-element bonuses are invisible to it).\nScopedPlusNamed = Scoped, plus the route's named stats (use only if the log shows Scoped is missing weapon/spell-group nodes).\nTip: with Diagnostics > LogScopedCompare on, the log shows both values per ability so you can compare.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "StatNames", "Scoped", "ScopedPlusNamed" }), Array.Empty<object>())); cfgCritMode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "CritMode", "Off", new ConfigDescription("Whether Path of Valheiman's crit stats raise ability damage (only in Scoped modes).\nOff = ignore crit. ExpectedValue = multiply damage by the average effect of crits, as PoV's own tooltips count it: 1 + CritChance x (1.5 + CritDamagePct - 1). It is a steady average, not random crits, and is applied after the cap.\nLeave it Off if PoV already rolls real crits on NorseDemigods hits (they would be counted twice).", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Off", "ExpectedValue" }), Array.Empty<object>())); cfgCapEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CapBonus", true, "Cap the bonus this bridge adds to one ability. Keeps specialist builds from running away."); cfgMaxBonus = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxBonus", 1.5f, "Largest bonus the bridge may add when the cap is on (1.5 = +150%, i.e. at most x2.5 damage)."); cfgAlwaysStats = ((BaseUnityPlugin)this).Config.Bind<string>("Damage", "Stats", "DamagePct:1", "Stats (name:weight, comma separated) added to EVERY routed ability, on top of its route's stats. Use for general damage.\nValid names include: DamagePct, MinionDamagePct, AttrSpirit, Dmg_Magical, Dmg_ElementalMagic, Dmg_BloodMagic, Dmg_Staves, Dmg_Scepters, Dmg_Swords, Dmg_Bows ...\nPer-element bonuses (fire/frost/lightning/poison/spirit damage) are NOT readable by name through Path of Valheiman's API.\nSet it empty to add nothing. If PoV already applies DamagePct to your demigod hits, remove DamagePct here to avoid counting it twice."); cfgHealingStats = ((BaseUnityPlugin)this).Config.Bind<string>("Healing", "Stats", "HealingEffectPct:1", "Stats that boost demigod healing (Eir's abilities and similar)."); cfgSummonStats = ((BaseUnityPlugin)this).Config.Bind<string>("Summons", "Stats", "MinionDamagePct:1", "Extra stats that boost summon damage (wolves, golems, minions). They stack on top of the ability's own route, because NorseDemigods already folds the damage modifier into summons."); cfgClaws = ((BaseUnityPlugin)this).Config.Bind<bool>("Claws", "ClawSwipe", true, "Give every claw weapon the slashing claw swipe (dual-axe animation, 4-hit chain, wide arc) whatever demigod you are. NorseDemigods only does this for Fenrir. A claw weapon here = an Unarmed-skill weapon that deals mostly slash damage. Only affects your own attacks. Takes effect on your next swing."); cfgExtraClaws = ((BaseUnityPlugin)this).Config.Bind<string>("Claws", "ExtraClawWeapons", "", "Extra weapon prefab names (comma separated, e.g. FistMyModdedClaw) that should always get the claw swipe, even if they aren't mostly slash damage."); cfgExtraClaws.SettingChanged += delegate { ParseExtraClaws(); }; ParseExtraClaws(); cfgAttributeRoute = ((BaseUnityPlugin)this).Config.Bind<string>("Routes", "AttributeProcs", "Off", "Route for NorseDemigods' passive attribute damage (Bear Strength, Flame Body, Bloody Archer ...). Off = unchanged.\nRoute(s) deciding which Path of Valheiman stats boost this ability. Combine several with commas (e.g. SpellElemental, Spears).\nSpellElemental / SpellBlood = Magical + Elemental (or Blood) magic + Staves + Scepters damage. Staves / Scepters = Magical + only that group.\nEquippedWeapon = the weapon you hold. Swords, Knives, Clubs, Polearms, Spears, Axes, Unarmed, Bows, Crossbows = that weapon's damage.\nNoCategory = only the 'always' stats (Damage > Stats). Off = leave this ability exactly as NorseDemigods made it.\nScoped modes also accept element/delivery tags: Fire, Frost, Lightning, Poison, Spirit, Physical, Projectile, Area, Minion (e.g. 'SpellElemental, Frost, Area'). If no element tag is given, a best guess from the ability's name is used."); cfgUnknownRoute = ((BaseUnityPlugin)this).Config.Bind<string>("Routes", "UnknownCaller", "SpellElemental", "Route used when the bridge can't tell which ability asked for damage.\nRoute(s) deciding which Path of Valheiman stats boost this ability. Combine several with commas (e.g. SpellElemental, Spears).\nSpellElemental / SpellBlood = Magical + Elemental (or Blood) magic + Staves + Scepters damage. Staves / Scepters = Magical + only that group.\nEquippedWeapon = the weapon you hold. Swords, Knives, Clubs, Polearms, Spears, Axes, Unarmed, Bows, Crossbows = that weapon's damage.\nNoCategory = only the 'always' stats (Damage > Stats). Off = leave this ability exactly as NorseDemigods made it.\nScoped modes also accept element/delivery tags: Fire, Frost, Lightning, Poison, Spirit, Physical, Projectile, Area, Minion (e.g. 'SpellElemental, Frost, Area'). If no element tag is given, a best guess from the ability's name is used."); cfgLogChanges = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogFactorChanges", true, "Log the current multipliers and raw stat values whenever they change."); cfgLogAllStats = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogAllActiveStats", false, "Also log EVERY Path of Valheiman stat that is currently non-zero (whenever that list changes)."); cfgLogRouting = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogRouting", false, "Log which route each ability used and its bonus (first time, and whenever it changes)."); cfgLogHits = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogHits", false, "Log every hit you land, at three stages: as the attack launches it, as it arrives at the target (after other mods such as Path of Valheiman have changed it), and after the target's resistances and armor. Shows exactly where a damage number grows or shrinks. Needs a restart to turn on or off. Turn it off when you're done: it writes a line per stage per hit."); cfgLogValues = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogDamageValues", false, "For each ability, log the damage modifier NorseDemigods passed in and the value the bridge returned (and calls it ignored, with the reason). Used to find out why a tooltip or hit doesn't change."); cfgLogScoped = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogScopedCompare", false, "For each ability, log what Path of Valheiman's scoped lookup returns (damage, unscoped damage, 'more' multiplier, crit) next to the named-stat sum. Used to check the Scoped modes before switching to them."); string[] knownAbilities = KnownAbilities; foreach (string ability in knownAbilities) { BindAbilityRoute(ability); } ParseAll(); cfgAlwaysStats.SettingChanged += delegate { ParseAll(); }; cfgHealingStats.SettingChanged += delegate { ParseAll(); }; cfgSummonStats.SettingChanged += delegate { ParseAll(); }; } private void Start() { //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown Log.LogInfo((object)("Config file in use: " + ((BaseUnityPlugin)this).Config.ConfigFilePath)); Log.LogInfo((object)("Always stats in effect: " + Describe(alwaysRules) + " (raw text: '" + cfgAlwaysStats.Value + "')")); Log.LogInfo((object)("Healing stats in effect: " + Describe(healingRules))); Log.LogInfo((object)("Summon stats in effect: " + Describe(summonRules))); if (!cfgEnabled.Value) { Log.LogInfo((object)"Disabled in config."); return; } PatchClaws(new Harmony("OblitusEs.DemigodsPovBridge.claws")); PatchHitLog(new Harmony("OblitusEs.DemigodsPovBridge.hitlog")); if (!ResolvePovApi()) { return; } Type type = AccessTools.TypeByName("NorseDemigods.Helper"); if (type == null) { Log.LogWarning((object)"NorseDemigods is not installed (type NorseDemigods.Helper not found). Bridge inactive."); return; } Harmony harmony = new Harmony("OblitusEs.DemigodsPovBridge"); int num = 0; num += Patch(harmony, type, "GetDamageModifier", "DamagePostfix"); num += Patch(harmony, type, "GetHealingModifier", "HealingPostfix"); num += Patch(harmony, type, "GetSummonDamageModifier", "SummonPostfix"); ready = num > 0; scopedReady = ResolveScoped(); if (!scopedReady && cfgMode.Value != "StatNames") { Log.LogWarning((object)("ScalingMode=" + cfgMode.Value + " needs Path of Valheiman's scoped lookup, which could not be bound. Falling back to StatNames.")); } Log.LogInfo((object)($"Ready: {num}/3 NorseDemigods modifiers hooked, reading Path of Valheiman stats " + "(mode=" + (Scoped() ? cfgMode.Value : "StatNames") + ", scoped lookup " + (scopedReady ? "available" : "unavailable") + ", unit=" + cfgUnit.Value + ", cap=" + (cfgCapEnabled.Value ? ("+" + (cfgMaxBonus.Value * 100f).ToString("0") + "%") : "off") + ").")); WarnUnknownStats(); } private static bool ResolvePovApi() { try { Type type = AccessTools.TypeByName("Valheiman.Api.Stats"); if (type == null) { Log.LogWarning((object)"Path of Valheiman API (Valheiman.Api.Stats) not found. Is PathOfValheiman installed and up to date? Bridge inactive."); return false; } MethodInfo methodInfo = AccessTools.Method(type, "Get", new Type[1] { typeof(string) }, (Type[])null); if (methodInfo == null || methodInfo.ReturnType != typeof(float)) { Log.LogWarning((object)"Valheiman.Api.Stats.Get(string) -> float not found; PoV's API changed. Bridge inactive."); return false; } povGet = (Func<string, float>)Delegate.CreateDelegate(typeof(Func<string, float>), methodInfo); try { if (AccessTools.Property(type, "Names")?.GetValue(null, null) is IEnumerable enumerable) { knownStats = new HashSet<string>(StringComparer.OrdinalIgnoreCase); knownList = new List<string>(); foreach (object item in enumerable) { string text = item as string; if (!string.IsNullOrEmpty(text)) { knownStats.Add(text); knownList.Add(text); } } } } catch (Exception) { knownStats = null; } return true; } catch (Exception ex2) { Log.LogWarning((object)("Could not bind Path of Valheiman API: " + ex2.GetBaseException().Message)); return false; } } private static int Patch(Harmony harmony, Type helper, string method, string postfixName) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown try { MethodInfo methodInfo = AccessTools.Method(helper, method, new Type[1] { typeof(Player) }, (Type[])null); if (methodInfo == null) { Log.LogWarning((object)("NorseDemigods.Helper." + method + "(Player) not found; NorseDemigods may have changed.")); return 0; } MethodInfo method2 = typeof(Plugin).GetMethod(postfixName, BindingFlags.Static | BindingFlags.NonPublic); harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); return 1; } catch (Exception ex) { Log.LogWarning((object)("Failed to patch " + method + ": " + ex.GetBaseException().Message)); return 0; } } private static void DamagePostfix(Player owner, ref float __result) { if (!Active(owner)) { LogSkipped(owner); return; } float before = __result; string caller; string text = Identify(out caller); string value; string label; if (text == "Ability") { value = BindAbilityRoute(caller).Value; label = caller; } else if (text == "Attribute") { value = cfgAttributeRoute.Value; label = caller + " (attribute)"; } else { value = cfgUnknownRoute.Value; label = "(unknown caller)"; } Route route = ParseRoute(value); if (route.Off) { LogRoute(label, value, 1f); return; } string ability = ((text == "Ability" || text == "Attribute") ? caller : null); float num = RoutedFactor(route, owner, ability); __result *= num; LogValue(label, before, __result, num); LogRoute(label, value, num); LogScopedCompare(label, route, owner, ability); } private static void HealingPostfix(Player owner, ref float __result) { if (Active(owner)) { __result *= ToFactor(SumHealing()); } } private static void SummonPostfix(Player owner, ref float __result) { if (Active(owner)) { __result *= ToFactor(SumSummon()); } } private static bool Active(Player owner) { return ready && cfgEnabled.Value && (Object)(object)owner != (Object)null && (Object)(object)owner == (Object)(object)Player.m_localPlayer; } private static string Identify(out string caller) { caller = null; try { StackFrame[] frames = new StackTrace(fNeedFileInfo: false).GetFrames(); if (frames == null) { return ""; } int num = Math.Min(frames.Length, 16); for (int i = 0; i < num; i++) { MethodBase method = frames[i].GetMethod(); Type type = ((method == null) ? null : method.DeclaringType); while (type != null && type.DeclaringType != null) { type = type.DeclaringType; } if (!(type == null)) { string text = type.Namespace; if (text == "NorseDemigods.Abilities") { caller = type.Name; return "Ability"; } if (text == "NorseDemigods.Attributes") { caller = type.Name; return "Attribute"; } } } } catch (Exception) { } return ""; } private static ConfigEntry<string> BindAbilityRoute(string ability) { if (abilityRoutes.TryGetValue(ability, out var value)) { return value; } value = Config_Bind("Routes", ability, DefaultRouteFor(ability), "Route(s) deciding which Path of Valheiman stats boost this ability. Combine several with commas (e.g. SpellElemental, Spears).\nSpellElemental / SpellBlood = Magical + Elemental (or Blood) magic + Staves + Scepters damage. Staves / Scepters = Magical + only that group.\nEquippedWeapon = the weapon you hold. Swords, Knives, Clubs, Polearms, Spears, Axes, Unarmed, Bows, Crossbows = that weapon's damage.\nNoCategory = only the 'always' stats (Damage > Stats). Off = leave this ability exactly as NorseDemigods made it.\nScoped modes also accept element/delivery tags: Fire, Frost, Lightning, Poison, Spirit, Physical, Projectile, Area, Minion (e.g. 'SpellElemental, Frost, Area'). If no element tag is given, a best guess from the ability's name is used."); abilityRoutes[ability] = value; return value; } private static ConfigEntry<string> Config_Bind(string section, string key, string def, string desc) { return ((BaseUnityPlugin)instance).Config.Bind<string>(section, key, def, desc); } private static string DefaultRouteFor(string ability) { switch (ability) { case "AbilitySlash": case "AbilityCleave": case "AbilityWhirlwind": case "AbilityStagger": case "AbilityBloodSlash": return "EquippedWeapon"; case "AbilityInfusedArrow": return "Bows"; case "AbilityWolf": return "Off"; default: return "SpellElemental"; } } private static Route ParseRoute(string text) { text = text ?? ""; if (routeCache.TryGetValue(text, out var value)) { return value; } value = new Route(); HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); string[] array = text.Split(new char[3] { ',', ';', '+' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text2 in array) { string text3 = text2.Trim(); if (text3.Length == 0) { continue; } if (string.Equals(text3, "Off", StringComparison.OrdinalIgnoreCase)) { value.Off = true; } else { if (string.Equals(text3, "NoCategory", StringComparison.OrdinalIgnoreCase)) { continue; } string[] value2; if (string.Equals(text3, "EquippedWeapon", StringComparison.OrdinalIgnoreCase)) { value.Equipped = true; } else if (RouteStats.TryGetValue(text3, out value2)) { string[] array2 = value2; foreach (string item in array2) { hashSet.Add(item); } if (RouteSubjects.TryGetValue(text3, out var value3)) { string[] array3 = value3; foreach (string item2 in array3) { value.Subjects.Add(item2); } } } else if (ElementTokens.Contains(text3)) { value.Subjects.Add(text3); value.ExplicitElement = true; } else if (TagTokens.Contains(text3)) { value.Subjects.Add(text3); } else { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)("Unknown route '" + text3 + "' (valid: SpellElemental, SpellBlood, Staves, Scepters, EquippedWeapon, Swords, Knives, Clubs, Polearms, Spears, Axes, Unarmed, Bows, Crossbows, NoCategory, Off, Fire, Frost, Lightning, Poison, Spirit, Physical, Projectile, Area, Minion). Ignored.")); } } } } value.Stats.AddRange(hashSet); routeCache[text] = value; return value; } private static string HeldSkill(Player player) { try { ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon(); if (currentWeapon == null || currentWeapon.m_shared == null) { return null; } return ((object)Unsafe.As<SkillType, SkillType>(ref currentWeapon.m_shared.m_skillType)/*cast due to .constrained prefix*/).ToString(); } catch (Exception) { return null; } } private static string EquippedRouteName(Player player) { string text = HeldSkill(player); if (text == null) { return null; } string text2 = text; string text3 = text2; if (!(text3 == "ElementalMagic")) { if (text3 == "BloodMagic") { return "SpellBlood"; } return text; } return "SpellElemental"; } private static string[] EquippedStats(Player player) { string text = EquippedRouteName(player); if (text != null && RouteStats.TryGetValue(text, out var value)) { return value; } return NoStats; } private static float RoutedFactor(Route route, Player owner, string ability) { if (Scoped() && TryScopedSum(route, owner, ability, out var sum, out var crit)) { return ToFactor(sum) * crit; } return ToFactor(NamedSum(route, owner)); } private static float NamedSum(Route route, Player owner) { HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); float num = SumRules(alwaysRules, hashSet); foreach (string stat in route.Stats) { if (hashSet.Add(stat)) { num += Read(stat); } } if (route.Equipped) { string[] array = EquippedStats(owner); foreach (string text in array) { if (hashSet.Add(text)) { num += Read(text); } } } return num; } private static bool Scoped() { return scopedReady && cfgMode != null && cfgMode.Value != "StatNames"; } private static bool ResolveScoped() { try { Type type = AccessTools.TypeByName("PassiveTree.Progress"); Type type2 = AccessTools.TypeByName("PassiveTree.StatSet"); tStat = AccessTools.TypeByName("PassiveTree.Stat"); tSubject = AccessTools.TypeByName("PassiveTree.Subject"); tSubjects = AccessTools.TypeByName("PassiveTree.Subjects"); List<string> list = new List<string>(); if (type == null) { list.Add("Progress"); } if (type2 == null) { list.Add("StatSet"); } if (tStat == null) { list.Add("Stat"); } if (tSubject == null) { list.Add("Subject"); } if (tSubjects == null) { list.Add("Subjects"); } if (list.Count > 0) { Log.LogWarning((object)("Scoped lookup unavailable: Path of Valheiman type(s) not found: " + string.Join(", ", list.ToArray()) + ". (PoV may have been restructured; StatNames mode still works.)")); return false; } miGet = AccessTools.Method(type2, "Get", new Type[2] { tStat, tSubjects }, (Type[])null); miMul = AccessTools.Method(type2, "MulOf", new Type[2] { tStat, tSubjects }, (Type[])null); miOf = AccessTools.Method(tSubjects, "Of", new Type[1] { tSubject.MakeArrayType() }, (Type[])null); if (miGet == null || miOf == null || miGet.ReturnType != typeof(float)) { Log.LogWarning((object)"Scoped lookup unavailable: StatSet.Get(Stat, Subjects) or Subjects.Of(Subject[]) not found with the expected shape."); return false; } Func<object> cur = null; PropertyInfo curProp = AccessTools.Property(type, "Current"); if (curProp != null) { cur = () => curProp.GetValue(null, null); } else { FieldInfo curField = AccessTools.Field(type, "Current"); if (curField != null) { cur = () => curField.GetValue(null); } } Func<object, object> stats = null; FieldInfo statsField = AccessTools.Field(type, "Stats"); if (statsField != null) { stats = (object o) => statsField.GetValue(o); } else { PropertyInfo statsProp = AccessTools.Property(type, "Stats"); if (statsProp != null) { stats = (object o) => statsProp.GetValue(o, null); } } if (cur == null || stats == null) { Log.LogWarning((object)"Scoped lookup unavailable: PassiveTree.Progress.Current / .Stats not found."); return false; } Type type3 = ((statsField != null) ? statsField.FieldType : AccessTools.Property(type, "Stats").PropertyType); if (!type2.IsAssignableFrom(type3)) { Log.LogWarning((object)("Scoped lookup unavailable: Progress.Stats is " + type3.FullName + ", not StatSet.")); return false; } statSetGetter = delegate { object obj = cur(); return (obj == null) ? null : stats(obj); }; emptyScope = BuildScope(new string[0]); return emptyScope != null; } catch (Exception ex) { Log.LogWarning((object)("Scoped lookup unavailable: " + ex.GetBaseException().Message)); return false; } } private static object StatEnum(string name) { if (statEnumCache.TryGetValue(name, out var value)) { return value; } try { value = Enum.Parse(tStat, name, ignoreCase: true); } catch (Exception) { value = null; if (warnedNames.Add("stat:" + name)) { Log.LogWarning((object)("Path of Valheiman has no stat '" + name + "' (scoped lookup).")); } } statEnumCache[name] = value; return value; } private static object SubjectEnum(string name) { if (subjectEnumCache.TryGetValue(name, out var value)) { return value; } try { value = Enum.Parse(tSubject, name, ignoreCase: true); } catch (Exception) { value = null; if (warnedNames.Add("subject:" + name)) { Log.LogWarning((object)("Path of Valheiman has no subject '" + name + "'. It is skipped in scopes.")); } } subjectEnumCache[name] = value; return value; } private static object BuildScope(IEnumerable<string> names) { List<object> list = new List<object>(); foreach (string name in names) { object obj = SubjectEnum(name); if (obj != null) { list.Add(obj); } } Array array = Array.CreateInstance(tSubject, list.Count); for (int i = 0; i < list.Count; i++) { array.SetValue(list[i], i); } return miOf.Invoke(null, new object[1] { array }); } private static object ScopeFor(Route route, Player owner, string ability, out string key) { HashSet<string> hashSet = new HashSet<string>(route.Subjects, StringComparer.OrdinalIgnoreCase); if (route.Equipped) { string text = EquippedRouteName(owner); if (text != null && RouteSubjects.TryGetValue(text, out var value)) { string[] array = value; foreach (string item in array) { hashSet.Add(item); } } } if (hashSet.Contains("Magical")) { string text2 = HeldSkill(owner); if (text2 == "ElementalMagic") { hashSet.Add("Staves"); } else if (text2 == "BloodMagic") { hashSet.Add("Scepters"); } } if (!route.ExplicitElement && ability != null && ImpliedSubjects.TryGetValue(ability, out var value2)) { string[] array2 = value2; foreach (string item2 in array2) { hashSet.Add(item2); } } List<string> list = new List<string>(hashSet); list.Sort(StringComparer.Ordinal); key = string.Join(",", list.ToArray()); if (scopeCache.TryGetValue(key, out var value3)) { return value3; } try { value3 = BuildScope(list); } catch (Exception ex) { value3 = null; NoteScopedError(ex); } scopeCache[key] = value3; return value3; } private static void NoteScopedError(Exception ex) { if (!scopedErrorLogged) { scopedErrorLogged = true; Log.LogWarning((object)("Scoped lookup failed (falling back to named stats): " + ex.GetBaseException().Message)); } } private static float ScopedGet(string stat, object scope, string key, bool mul = false) { if (scope == null) { return 0f; } string key2 = (mul ? "M:" : "G:") + stat + "|" + key; int tickCount = Environment.TickCount; if (cache.TryGetValue(key2, out var value) && tickCount - value.Key < 200) { return value.Value; } float num = 0f; try { MethodInfo methodInfo = (mul ? miMul : miGet); object obj = StatEnum(stat); object obj2 = statSetGetter(); if (methodInfo != null && obj != null && obj2 != null) { num = Convert.ToSingle(methodInfo.Invoke(obj2, new object[2] { obj, scope }), CultureInfo.InvariantCulture); } } catch (Exception ex) { NoteScopedError(ex); num = 0f; } if (float.IsNaN(num) || float.IsInfinity(num)) { num = 0f; } cache[key2] = new KeyValuePair<int, float>(tickCount, num); return num; } private static bool TryScopedSum(Route route, Player owner, string ability, out float sum, out float crit) { sum = 0f; crit = 1f; string key; object obj = ScopeFor(route, owner, ability, out key); if (obj == null) { return false; } crit = CritFactor(obj, key); HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < alwaysRules.Count; i++) { Rule rule = alwaysRules[i]; hashSet.Add(rule.Stat); if (string.Equals(rule.Stat, "DamagePct", StringComparison.OrdinalIgnoreCase)) { sum += ScopedGet("DamagePct", obj, key) * rule.Weight; } else { sum += Read(rule.Stat) * rule.Weight; } } if (cfgMode.Value == "ScopedPlusNamed") { foreach (string stat in route.Stats) { if (hashSet.Add(stat)) { sum += Read(stat); } } if (route.Equipped) { string[] array = EquippedStats(owner); foreach (string text in array) { if (hashSet.Add(text)) { sum += Read(text); } } } } return true; } private static float CritFactor(object scope, string key) { if (cfgCritMode == null || cfgCritMode.Value != "ExpectedValue") { return 1f; } float num = ScopedGet("CritChance", scope, key); if (num <= 0f) { return 1f; } if (num > 1f) { num = 1f; } float num2 = 1.5f + ScopedGet("CritDamagePct", scope, key); if (num2 < 1f) { num2 = 1f; } return 1f + num * (num2 - 1f); } private static float SumHealing() { return SumRulesScoped(healingRules, HealingSubjects); } private static float SumSummon() { return SumRulesScoped(summonRules, SummonSubjects); } private static float SumRulesScoped(List<Rule> rules, string[] subjects) { if (!Scoped()) { return SumRules(rules, null); } string key; object obj = ScopeFromNames(subjects, out key); if (obj == null) { return SumRules(rules, null); } float num = 0f; for (int i = 0; i < rules.Count; i++) { num += ScopedGet(rules[i].Stat, obj, key) * rules[i].Weight; } return num; } private static object ScopeFromNames(string[] names, out string key) { List<string> list = new List<string>(names); list.Sort(StringComparer.Ordinal); key = string.Join(",", list.ToArray()); if (scopeCache.TryGetValue(key, out var value)) { return value; } try { value = BuildScope(list); } catch (Exception ex) { value = null; NoteScopedError(ex); } scopeCache[key] = value; return value; } private static void LogScopedCompare(string label, Route route, Player owner, string ability) { if (!scopedReady || !cfgLogScoped.Value) { return; } try { string key; object obj = ScopeFor(route, owner, ability, out key); if (obj != null) { float num = ScopedGet("DamagePct", obj, key); float num2 = ScopedGet("DamagePct", emptyScope, ""); float num3 = ScopedGet("DamagePct", obj, key, mul: true); float val = ScopedGet("CritChance", obj, key); float num4 = ScopedGet("CritDamagePct", obj, key); float num5 = NamedSum(route, owner); CultureInfo invariantCulture = CultureInfo.InvariantCulture; string text = "scope=[" + key + "] DamagePct=" + num.ToString("0.####", invariantCulture) + " (unscoped " + num2.ToString("0.####", invariantCulture) + ") more=x" + num3.ToString("0.###", invariantCulture) + " crit=" + val.ToString("0.####", invariantCulture) + " critDmg=" + num4.ToString("0.####", invariantCulture) + " (avg-crit factor x" + (1f + Math.Min(1f, Math.Max(0f, val)) * (1.5f + num4 - 1f)).ToString("0.###", invariantCulture) + ", applied: " + ((cfgCritMode.Value == "ExpectedValue" && Scoped()) ? "yes" : "no") + ") | named-stat sum=" + num5.ToString("0.####", invariantCulture) + " | mode=" + (Scoped() ? cfgMode.Value : "StatNames"); if (!lastScopedLine.TryGetValue(label, out var value) || !(value == text)) { lastScopedLine[label] = text; Log.LogInfo((object)("Scoped " + label + " " + text)); } } } catch (Exception ex) { NoteScopedError(ex); } } private static float SumRules(List<Rule> rules, HashSet<string> used) { float num = 0f; for (int i = 0; i < rules.Count; i++) { used?.Add(rules[i].Stat); num += Read(rules[i].Stat) * rules[i].Weight; } return num; } private static float ToFactor(float sum) { if (cfgUnit.Value == "Percent") { sum *= 0.01f; } if (sum < -1f) { sum = -1f; } if (cfgCapEnabled.Value) { float num = ((cfgMaxBonus.Value < 0f) ? 0f : cfgMaxBonus.Value); if (sum > num) { sum = num; } } return 1f + sum; } private static float Read(string stat) { int tickCount = Environment.TickCount; if (cache.TryGetValue(stat, out var value) && tickCount - value.Key < 200) { return value.Value; } float num = 0f; try { num = povGet(stat); } catch (Exception) { num = 0f; } if (float.IsNaN(num) || float.IsInfinity(num)) { num = 0f; } cache[stat] = new KeyValuePair<int, float>(tickCount, num); return num; } private static void PatchHitLog(Harmony harmony) { //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Expected O, but got Unknown //IL_0139: Expected O, but got Unknown try { if (cfgLogHits.Value) { MethodInfo methodInfo = AccessTools.Method(typeof(Character), "Damage", new Type[1] { typeof(HitData) }, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(Character), "RPC_Damage", new Type[2] { typeof(long), typeof(HitData) }, (Type[])null); MethodInfo method = typeof(Plugin).GetMethod("HitLaunched", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo method2 = typeof(Plugin).GetMethod("HitArriving", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo method3 = typeof(Plugin).GetMethod("HitFinal", BindingFlags.Static | BindingFlags.NonPublic); int num = 0; if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(method) { priority = 800 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } else { Log.LogWarning((object)"Hit log: Character.Damage(HitData) not found; stage 1 unavailable."); } if (methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(method2) { priority = 0 }, new HarmonyMethod(method3) { priority = 0 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num += 2; } else { Log.LogWarning((object)"Hit log: Character.RPC_Damage(long, HitData) not found; stages 2 and 3 unavailable."); } Log.LogInfo((object)("Hit log: on (" + num + "/3 stages). Every hit you land is logged as 'Hit 1/2/3'.")); } } catch (Exception ex) { Log.LogWarning((object)("Hit log: could not patch: " + ex.GetBaseException().Message)); } } private static bool IsMyHit(HitData hit) { try { if (hit == null || (Object)(object)Player.m_localPlayer == (Object)null) { return false; } Character attacker = hit.GetAttacker(); return (Object)(object)attacker != (Object)null && (Object)(object)attacker == (Object)(object)Player.m_localPlayer; } catch (Exception) { return false; } } private static void HitLaunched(Character __instance, HitData hit) { if (IsMyHit(hit)) { LogHit("1 launched", __instance, hit); } } private static void HitArriving(Character __instance, HitData hit) { if (IsMyHit(hit)) { LogHit("2 arriving", __instance, hit); } } private static void HitFinal(Character __instance, HitData hit) { if (IsMyHit(hit)) { LogHit("3 after resist+armor", __instance, hit); } } private static void LogHit(string stage, Character target, HitData hit) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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) DamageTypes damage = hit.m_damage; StringBuilder stringBuilder = new StringBuilder(); AddType(stringBuilder, "dmg", damage.m_damage); AddType(stringBuilder, "blunt", damage.m_blunt); AddType(stringBuilder, "slash", damage.m_slash); AddType(stringBuilder, "pierce", damage.m_pierce); AddType(stringBuilder, "chop", damage.m_chop); AddType(stringBuilder, "pickaxe", damage.m_pickaxe); AddType(stringBuilder, "fire", damage.m_fire); AddType(stringBuilder, "frost", damage.m_frost); AddType(stringBuilder, "lightning", damage.m_lightning); AddType(stringBuilder, "poison", damage.m_poison); AddType(stringBuilder, "spirit", damage.m_spirit); if (stringBuilder.Length == 0) { stringBuilder.Append("(no damage)"); } Log.LogInfo((object)("Hit " + stage + " -> " + (((Object)(object)target != (Object)null) ? target.m_name : "?") + ": " + stringBuilder?.ToString() + " | total " + ((DamageTypes)(ref damage)).GetTotalDamage().ToString("0.###", CultureInfo.InvariantCulture) + " | bridge mode=" + (Scoped() ? cfgMode.Value : "StatNames"))); } private static void AddType(StringBuilder sb, string name, float v) { if (!(v <= 0f)) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(name).Append(' ').Append(v.ToString("0.###", CultureInfo.InvariantCulture)); } } private static void ParseExtraClaws() { HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); string text = ((cfgExtraClaws == null) ? "" : cfgExtraClaws.Value); string[] array = (text ?? "").Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text2 in array) { string text3 = text2.Trim(); if (text3.Length > 0) { hashSet.Add(text3); } } extraClaws = hashSet; } private static void PatchClaws(Harmony harmony) { //IL_00c8: 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) //IL_00d5: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Expected O, but got Unknown try { if (!cfgClaws.Value) { Log.LogInfo((object)"Claw swipe: off in config."); return; } MethodInfo methodInfo = AccessTools.Method(typeof(Humanoid), "StartAttack", new Type[2] { typeof(Character), typeof(bool) }, (Type[])null); MethodInfo method = typeof(Plugin).GetMethod("ClawPrefix", BindingFlags.Static | BindingFlags.NonPublic); MethodInfo method2 = typeof(Plugin).GetMethod("ClawFinalizer", BindingFlags.Static | BindingFlags.NonPublic); if (methodInfo == null || method == null || method2 == null) { Log.LogWarning((object)"Claw swipe: Humanoid.StartAttack(Character, bool) not found; the game may have changed. Claw swipe off."); return; } HarmonyMethod val = new HarmonyMethod(method) { priority = 0 }; harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null); Log.LogInfo((object)("Claw swipe: on (Unarmed weapons that deal mostly slash damage" + ((extraClaws.Count > 0) ? (", plus " + string.Join(", ", new List<string>(extraClaws).ToArray())) : "") + ").")); } catch (Exception ex) { Log.LogWarning((object)("Claw swipe: could not patch: " + ex.GetBaseException().Message)); } } private static bool IsClawWeapon(Player player, ItemData weapon) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 //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_008b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((Humanoid)player).m_unarmedWeapon != (Object)null && weapon == ((Humanoid)player).m_unarmedWeapon.m_itemData) { return false; } GameObject dropPrefab = weapon.m_dropPrefab; if ((Object)(object)dropPrefab != (Object)null && extraClaws.Contains(((Object)dropPrefab).name)) { return true; } if ((int)weapon.m_shared.m_skillType != 11) { return false; } DamageTypes damage = weapon.GetDamage(); float totalBlockableDamage = ((DamageTypes)(ref damage)).GetTotalBlockableDamage(); return totalBlockableDamage > 0f && damage.m_slash > totalBlockableDamage / 2f; } private static T Clone<T>(T source) where T : class { return (T)memberwiseClone.Invoke(source, null); } private static SharedData ClawVersion(SharedData original) { if (clawShared.TryGetValue(original, out var value)) { return value; } value = Clone<SharedData>(original); Attack val = Clone<Attack>(original.m_attack); val.m_attackAnimation = "dualaxes"; val.m_attackChainLevels = 4; val.m_attackAngle = 90f; val.m_attackHeight = 0.6f; val.m_attackHeightChar1 = 0f; val.m_attackHeightChar2 = 0f; value.m_attack = val; clawShared[original] = value; return value; } private static void ClawPrefix(Humanoid __instance, bool secondaryAttack, ref ClawState __state) { __state = null; try { if (secondaryAttack || !cfgClaws.Value) { return; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer || ((Character)val).InAttack()) { return; } ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon(); if (currentWeapon != null && currentWeapon.m_shared != null && currentWeapon.m_shared.m_attack != null && IsClawWeapon(val, currentWeapon) && !(currentWeapon.m_shared.m_attack.m_attackAnimation == "dualaxes")) { SharedData shared = currentWeapon.m_shared; currentWeapon.m_shared = ClawVersion(shared); __state = new ClawState { Weapon = currentWeapon, Original = shared }; string text = (((Object)(object)currentWeapon.m_dropPrefab != (Object)null) ? ((Object)currentWeapon.m_dropPrefab).name : shared.m_name); if (clawLogged.Add(text)) { Log.LogInfo((object)("Claw swipe applied to '" + text + "'.")); } } } catch (Exception ex) { if (clawLogged.Add("error:" + ex.GetBaseException().Message)) { Log.LogWarning((object)("Claw swipe failed: " + ex.GetBaseException().Message)); } } } private static Exception ClawFinalizer(Exception __exception, ClawState __state) { if (__state != null && __state.Weapon != null && __state.Original != null) { __state.Weapon.m_shared = __state.Original; } return __exception; } private static void LogValue(string label, float before, float after, float factor) { if (cfgLogValues.Value) { string text = "modifier " + before.ToString("0.####", CultureInfo.InvariantCulture) + " -> " + after.ToString("0.####", CultureInfo.InvariantCulture) + " (x" + factor.ToString("0.###", CultureInfo.InvariantCulture) + ", mode=" + (Scoped() ? cfgMode.Value : "StatNames") + ")"; if (!lastValueLogged.TryGetValue(label, out var value) || !(value == text)) { lastValueLogged[label] = text; Log.LogInfo((object)("Value " + label + " " + text)); } } } private static void LogSkipped(Player owner) { if (cfgLogValues.Value && ready) { string text = ((!cfgEnabled.Value) ? "bridge disabled" : (((Object)(object)owner == (Object)null) ? "owner is null" : ("owner is not the local player (" + owner.GetPlayerName() + ")"))); string caller; string text2 = Identify(out caller); string text3 = (caller ?? "(unknown caller)") + " [skipped]"; if (!lastValueLogged.TryGetValue(text3, out var value) || !(value == text)) { lastValueLogged[text3] = text; Log.LogInfo((object)("Value " + text3 + " " + text)); } } } private static void LogRoute(string label, string routeText, float factor) { if (cfgLogRouting.Value && (!lastRouteLogged.TryGetValue(label, out var value) || !(Math.Abs(value - factor) < 0.001f))) { lastRouteLogged[label] = factor; Log.LogInfo((object)("Route " + label + " [" + routeText + "] -> x" + factor.ToString("0.###", CultureInfo.InvariantCulture))); } } private static string Describe(List<Rule> rules) { if (rules.Count == 0) { return "(none)"; } List<string> list = new List<string>(); foreach (Rule rule in rules) { list.Add(rule.Stat + " x" + rule.Weight.ToString("0.####", CultureInfo.InvariantCulture)); } return string.Join(", ", list.ToArray()); } private static void ParseAll() { alwaysRules = ParseRules(cfgAlwaysStats.Value); healingRules = ParseRules(cfgHealingStats.Value); summonRules = ParseRules(cfgSummonStats.Value); cache.Clear(); if (ready) { WarnUnknownStats(); } } private static List<Rule> ParseRules(string text) { List<Rule> list = new List<Rule>(); if (string.IsNullOrWhiteSpace(text)) { return list; } string[] array = text.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text2 in array) { string text3 = text2.Trim(); if (text3.Length == 0) { continue; } int num = text3.LastIndexOf('='); if (num >= 0) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)("Config value '" + text3 + "' contains '='. Using only '" + text3.Substring(num + 1).Trim() + "'. (In the .cfg file the line should read just: Stats = Name:weight, Name:weight)")); } text3 = text3.Substring(num + 1).Trim(); if (text3.Length == 0) { continue; } } string text4 = text3; float result = 1f; int num2 = text3.IndexOf(':'); if (num2 > 0) { text4 = text3.Substring(0, num2).Trim(); if (!float.TryParse(text3.Substring(num2 + 1).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogWarning((object)("Ignoring '" + text3 + "': weight is not a number.")); } continue; } } if (text4.Length > 0) { list.Add(new Rule { Stat = text4, Weight = result }); } } return list; } private static void WarnUnknownStats() { if (knownStats == null) { return; } List<Rule>[] array = new List<Rule>[3] { alwaysRules, healingRules, summonRules }; foreach (List<Rule> list in array) { foreach (Rule item in list) { if (!knownStats.Contains(item.Stat)) { Log.LogWarning((object)("Path of Valheiman has no stat called '" + item.Stat + "' (names are case-insensitive but must match). It will count as 0.")); } } } } private void Update() { if (!ready || !cfgLogChanges.Value || (Object)(object)Player.m_localPlayer == (Object)null || Time.unscaledTime < nextLog) { return; } nextLog = Time.unscaledTime + 2f; Route route = ParseRoute("SpellElemental"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Spell-route factor x").Append(RoutedFactor(route, Player.m_localPlayer, null).ToString("0.###", CultureInfo.InvariantCulture)); stringBuilder.Append(" | Healing x").Append(ToFactor(SumHealing()).ToString("0.###", CultureInfo.InvariantCulture)); stringBuilder.Append(" | Summon extra x").Append(ToFactor(SumSummon()).ToString("0.###", CultureInfo.InvariantCulture)); stringBuilder.Append(" | raw:"); HashSet<string> hashSet = new HashSet<string>(); List<Rule>[] array = new List<Rule>[3] { alwaysRules, healingRules, summonRules }; foreach (List<Rule> list in array) { foreach (Rule item in list) { if (hashSet.Add(item.Stat)) { stringBuilder.Append(' ').Append(item.Stat).Append('=') .Append(Read(item.Stat).ToString("0.####", CultureInfo.InvariantCulture)); } } } foreach (string stat in route.Stats) { if (hashSet.Add(stat)) { stringBuilder.Append(' ').Append(stat).Append('=') .Append(Read(stat).ToString("0.####", CultureInfo.InvariantCulture)); } } string text = stringBuilder.ToString(); if (text != lastLine) { lastLine = text; Log.LogInfo((object)text); } if (!cfgLogAllStats.Value || knownList == null) { return; } StringBuilder stringBuilder2 = new StringBuilder("Active PoV stats:"); int num = 0; for (int j = 0; j < knownList.Count; j++) { float num2 = Read(knownList[j]); if (num2 > 1E-06f || num2 < -1E-06f) { if (num < 80) { stringBuilder2.Append(' ').Append(knownList[j]).Append('=') .Append(num2.ToString("0.####", CultureInfo.InvariantCulture)); } num++; } } if (num > 80) { stringBuilder2.Append(" ... (+").Append(num - 80).Append(" more)"); } if (num == 0) { stringBuilder2.Append(" none (no allocated node is feeding any stat yet)"); } string text2 = stringBuilder2.ToString(); if (text2 != lastAllLine) { lastAllLine = text2; Log.LogInfo((object)text2); } } } }