using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [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; } } } public class AedenthornUtils { public static bool IgnoreKeyPresses(bool extra = false) { if (!extra) { if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog()) { Chat instance = Chat.instance; if (instance == null) { return false; } return instance.HasFocus(); } return true; } if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog()) { Chat instance2 = Chat.instance; if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible()) { if (Object.op_Implicit((Object)(object)TextViewer.instance)) { return TextViewer.instance.IsVisible(); } return false; } } return true; } public static bool CheckKeyDown(string value) { try { return Input.GetKeyDown(value.ToLower()); } catch { return false; } } } namespace CustomArmorStats { [BepInPlugin("cjayride.CustomArmorStats", "Custom Armor Stats", "0.9.1")] public class BepInExPlugin : BaseUnityPlugin { public enum NewDamageTypes { Water = 0x400 } [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class ZNetScene_Awake_Patch { public static void Postfix() { if (modEnabled.Value) { LoadAllArmorData(); } } } [HarmonyPatch(typeof(ItemDrop), "Awake")] public static class ItemDrop_Awake_Patch { public static void Postfix(ItemDrop __instance) { if (modEnabled.Value) { CheckArmorData(ref __instance); } } } [HarmonyPatch(typeof(ItemDrop), "SlowUpdate")] public static class ItemDrop_SlowUpdate_Patch { public static void Postfix(ref ItemDrop __instance) { if (modEnabled.Value) { CheckArmorData(ref __instance); } } } [HarmonyPatch(typeof(Player), "DamageArmorDurability")] public static class Player_DamageArmorDurability_Patch { public static void Prefix(ref HitData hit) { if (modEnabled.Value) { hit.ApplyModifier(globalArmorDurabilityLossMult.Value); } } } [HarmonyPatch(typeof(Player), "GetEquipmentMovementModifier")] public static class GetEquipmentMovementModifier_Patch { public static void Postfix(ref float __result) { if (modEnabled.Value) { __result *= globalArmorMovementModMult.Value; } } } [HarmonyPatch(typeof(SEMan), "AddStatusEffect", new Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })] public static class SEMan_AddStatusEffect_Hash_Patch { public static bool Prefix(SEMan __instance, int nameHash, Character ___m_character, ref StatusEffect __result) { if (!modEnabled.Value || (Object)(object)___m_character == (Object)null || !___m_character.IsPlayer()) { return true; } if (nameHash == SEMan.s_statusEffectWet && IsWaterImmune(___m_character)) { __result = null; return false; } return true; } } [HarmonyPatch(typeof(SEMan), "AddStatusEffect", new Type[] { typeof(StatusEffect), typeof(bool), typeof(int), typeof(float), typeof(short) })] public static class SEMan_AddStatusEffect_Patch { public static bool Prefix(SEMan __instance, StatusEffect statusEffect, Character ___m_character, ref StatusEffect __result) { if (!modEnabled.Value || (Object)(object)___m_character == (Object)null || !___m_character.IsPlayer() || (Object)(object)statusEffect == (Object)null) { return true; } if ((statusEffect.m_name == "$se_wet_name" || statusEffect.NameHash() == SEMan.s_statusEffectWet) && IsWaterImmune(___m_character)) { __result = null; return false; } return true; } } [HarmonyPatch(typeof(SE_Stats), "GetDamageModifiersTooltipString")] public static class GetDamageModifiersTooltipString_Patch { public static void Postfix(ref string __result, List mods) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected I4, but got Unknown //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Invalid comparison between Unknown and I4 if (!modEnabled.Value) { return; } __result = Regex.Replace(__result, "\\n.*", ""); foreach (DamageModPair mod in mods) { if (!Enum.IsDefined(typeof(DamageType), mod.m_type) && (int)mod.m_modifier != 4 && (int)mod.m_modifier != 0) { DamageModifier modifier = mod.m_modifier; switch (modifier - 1) { case 0: __result += "\n$inventory_dmgmod: $inventory_resistant VS "; break; case 1: __result += "\n$inventory_dmgmod: $inventory_weak VS "; break; case 2: __result += "\n$inventory_dmgmod: $inventory_immune VS "; break; case 4: __result += "\n$inventory_dmgmod: $inventory_veryresistant VS "; break; case 5: __result += "\n$inventory_dmgmod: $inventory_veryweak VS "; break; case 6: __result += "\n$inventory_dmgmod: Slightly resistant VS "; break; case 7: __result += "\n$inventory_dmgmod: Slightly weak VS "; break; } if ((int)mod.m_type == 1024) { __result = __result + "" + waterModifierName.Value + ""; } } } } } [HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")] public static class UpdateEnvStatusEffects_Patch { public static IEnumerable Transpiler(IEnumerable instructions) { //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Expected O, but got Unknown Dbgl("Transpiling UpdateEnvStatusEffects", (LogLevel)32); List list = new List(instructions); List list2 = new List(); bool flag = true; for (int i = 0; i < list.Count; i++) { if (flag && i + 4 < list.Count && IsLdloc(list[i].opcode) && list[i + 1].opcode == OpCodes.Ldc_I4_1 && IsBeq(list[i + 2].opcode) && IsLdloc(list[i + 3].opcode) && object.Equals(list[i + 3].operand, list[i].operand) && list[i + 4].opcode == OpCodes.Ldc_I4_5) { Dbgl("Adding frost immune and ignore", (LogLevel)32); list2.Add(new CodeInstruction(list[i])); list2.Add(new CodeInstruction(OpCodes.Ldc_I4_3, (object)null)); list2.Add(new CodeInstruction(list[i + 2])); list2.Add(new CodeInstruction(list[i])); list2.Add(new CodeInstruction(OpCodes.Ldc_I4_4, (object)null)); list2.Add(new CodeInstruction(list[i + 2])); flag = false; } list2.Add(list[i]); } if (flag) { Dbgl("UpdateEnvStatusEffects frost pattern not found; Immune/Ignore may already be handled or the IL changed", (LogLevel)4); } return list2.AsEnumerable(); } public static void Postfix(float dt, Player __instance, ItemData ___m_chestItem, ItemData ___m_legItem, ItemData ___m_helmetItem, ItemData ___m_shoulderItem, ItemData ___m_trinketItem, SEMan ___m_seman) { //IL_002d: 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) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Invalid comparison between Unknown and I4 //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Invalid comparison between Unknown and I4 //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Invalid comparison between Unknown and I4 //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Invalid comparison between Unknown and I4 if (!modEnabled.Value) { return; } int s_statusEffectWet = SEMan.s_statusEffectWet; if (!___m_seman.HaveStatusEffect(s_statusEffectWet)) { return; } DamageModifier newDamageTypeMod = GetNewDamageTypeMod(NewDamageTypes.Water, ___m_chestItem, ___m_legItem, ___m_helmetItem, ___m_shoulderItem, ___m_trinketItem); StatusEffect statusEffect = ___m_seman.GetStatusEffect(s_statusEffectWet); if (!((Object)(object)statusEffect == (Object)null)) { Traverse val = Traverse.Create((object)statusEffect); if ((int)newDamageTypeMod == 4 || (int)newDamageTypeMod == 3) { ___m_seman.RemoveStatusEffect(s_statusEffectWet, true); } else if ((int)newDamageTypeMod == 5 && !(bool)AccessTools.Method(typeof(Character), "InLiquidSwimDepth", Type.EmptyTypes, (Type[])null).Invoke(__instance, new object[0])) { ___m_seman.RemoveStatusEffect(s_statusEffectWet, true); } else if ((int)newDamageTypeMod == 1) { val.Field("m_time").SetValue((object)(val.Field("m_time").GetValue() + dt)); ___m_seman.RemoveStatusEffect(s_statusEffectWet, true); ___m_seman.AddStatusEffect(statusEffect, false, 0, 0f, (short)(-1)); } else if ((int)newDamageTypeMod == 2) { val.Field("m_time").SetValue((object)(val.Field("m_time").GetValue() - dt / 3f)); ___m_seman.RemoveStatusEffect(s_statusEffectWet, true); ___m_seman.AddStatusEffect(statusEffect, false, 0, 0f, (short)(-1)); } else if ((int)newDamageTypeMod == 6) { val.Field("m_time").SetValue((object)(val.Field("m_time").GetValue() - dt * 2f / 3f)); ___m_seman.RemoveStatusEffect(s_statusEffectWet, true); ___m_seman.AddStatusEffect(statusEffect, false, 0, 0f, (short)(-1)); } } } } [HarmonyPatch(typeof(Terminal), "InitTerminal")] public static class Terminal_InitTerminal_Patch { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__1_0; internal void b__1_0(ConsoleEventArgs args) { RunCommand(args); } } private static bool registered; public static void Postfix() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) //IL_0037: Expected O, but got Unknown if (registered) { return; } registered = true; object obj = <>c.<>9__1_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { RunCommand(args); }; <>c.<>9__1_0 = val; obj = (object)val; } new ConsoleCommand("customarmorstats", "CustomArmorStats commands", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } } public static BepInExPlugin context; public static ConfigEntry modEnabled; public static ConfigEntry isDebug; public static ConfigEntry globalArmorDurabilityLossMult; public static ConfigEntry globalArmorMovementModMult; public static ConfigEntry waterModifierName; public static Dictionary armorDatas = new Dictionary(); public static string assetPath; public static void Dbgl(object str, LogLevel level = (LogLevel)32) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (isDebug.Value) { ((BaseUnityPlugin)context).Logger.Log(level, str); } } public void Awake() { context = this; modEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Enable this mod"); isDebug = ((BaseUnityPlugin)this).Config.Bind("General", "IsDebug", false, "Enable debug logs"); globalArmorDurabilityLossMult = ((BaseUnityPlugin)this).Config.Bind("Stats", "GlobalArmorDurabilityLossMult", 1f, "Global armor durability loss multiplier"); globalArmorMovementModMult = ((BaseUnityPlugin)this).Config.Bind("Stats", "GlobalArmorMovementModMult", 1f, "Global armor movement modifier multiplier"); waterModifierName = ((BaseUnityPlugin)this).Config.Bind("Strings", "WaterModifierName", "Water", "Name of water damage modifier to show in tooltip"); assetPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CustomArmorStats"); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null); } private static bool IsBeq(OpCode opcode) { if (!(opcode == OpCodes.Beq)) { return opcode == OpCodes.Beq_S; } return true; } private static bool IsLdloc(OpCode opcode) { if (!(opcode == OpCodes.Ldloc) && !(opcode == OpCodes.Ldloc_S) && !(opcode == OpCodes.Ldloc_0) && !(opcode == OpCodes.Ldloc_1) && !(opcode == OpCodes.Ldloc_2)) { return opcode == OpCodes.Ldloc_3; } return true; } public static bool IsWaterImmune(Character character) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 DamageModifier newDamageTypeMod = GetNewDamageTypeMod(NewDamageTypes.Water, character); if ((int)newDamageTypeMod != 4) { return (int)newDamageTypeMod == 3; } return true; } public static DamageModifier GetNewDamageTypeMod(NewDamageTypes type, Character character) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) Traverse val = Traverse.Create((object)character); return GetNewDamageTypeMod(type, val.Field("m_chestItem").GetValue(), val.Field("m_legItem").GetValue(), val.Field("m_helmetItem").GetValue(), val.Field("m_shoulderItem").GetValue(), val.Field("m_trinketItem").GetValue()); } public static DamageModifier GetNewDamageTypeMod(NewDamageTypes type, ItemData chestItem, ItemData legItem, ItemData helmetItem, ItemData shoulderItem, ItemData trinketItem = null) { //IL_000f: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_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) //IL_008a: 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) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) DamageModPair val = default(DamageModPair); if (chestItem != null) { val = ((IEnumerable)chestItem.m_shared.m_damageModifiers).FirstOrDefault((Func)((DamageModPair s) => (int)s.m_type == (int)type)); } if (legItem != null) { DamageModPair val2 = ((IEnumerable)legItem.m_shared.m_damageModifiers).FirstOrDefault((Func)((DamageModPair s) => (int)s.m_type == (int)type)); if (ShouldOverride(val.m_modifier, val2.m_modifier)) { val = val2; } } if (helmetItem != null) { DamageModPair val3 = ((IEnumerable)helmetItem.m_shared.m_damageModifiers).FirstOrDefault((Func)((DamageModPair s) => (int)s.m_type == (int)type)); if (ShouldOverride(val.m_modifier, val3.m_modifier)) { val = val3; } } if (shoulderItem != null) { DamageModPair val4 = ((IEnumerable)shoulderItem.m_shared.m_damageModifiers).FirstOrDefault((Func)((DamageModPair s) => (int)s.m_type == (int)type)); if (ShouldOverride(val.m_modifier, val4.m_modifier)) { val = val4; } } if (trinketItem != null) { DamageModPair val5 = ((IEnumerable)trinketItem.m_shared.m_damageModifiers).FirstOrDefault((Func)((DamageModPair s) => (int)s.m_type == (int)type)); if (ShouldOverride(val.m_modifier, val5.m_modifier)) { val = val5; } } return val.m_modifier; } public static bool ShouldOverride(DamageModifier a, DamageModifier b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 if ((int)a != 4) { if ((int)b != 3) { if ((int)a != 5 || (int)b != 1) { if ((int)a == 6) { return (int)b != 2; } return true; } return false; } return true; } return false; } public static void LoadAllArmorData() { if ((Object)(object)ZNetScene.instance == (Object)null) { return; } armorDatas = GetArmorDataFromFiles(); ItemDrop[] array = Object.FindObjectsByType((FindObjectsSortMode)0); foreach (ItemDrop val in array) { if (!((Object)(object)val == (Object)null) && val.m_itemData != null && !((Object)(object)val.m_itemData.m_dropPrefab == (Object)null) && armorDatas.TryGetValue(((Object)val.m_itemData.m_dropPrefab).name, out var value)) { SetArmorData(val.m_itemData, value); } } } public static void CheckArmorData(ref ItemDrop instance) { string text = (string)AccessTools.Method(typeof(ItemDrop), "GetPrefabName", (Type[])null, (Type[])null).Invoke(instance, new object[1] { ((Object)((Component)instance).gameObject).name }); try { if (armorDatas.TryGetValue(text, out var value)) { Dbgl("Setting armor data for " + text, (LogLevel)32); SetArmorData(instance.m_itemData, value); Dbgl("Set armor data for " + text, (LogLevel)32); } } catch (Exception arg) { Dbgl($"Error setting armor data for {text}:\n\n{arg}", (LogLevel)4); } } public static Dictionary GetArmorDataFromFiles() { CheckModFolder(); Dictionary dictionary = new Dictionary(); string[] files = Directory.GetFiles(assetPath, "*.json"); for (int i = 0; i < files.Length; i++) { ArmorData armorData = JsonConvert.DeserializeObject(File.ReadAllText(files[i])); dictionary[armorData.name] = armorData; } return dictionary; } public static void CheckModFolder() { if (!Directory.Exists(assetPath)) { Dbgl("Creating mod folder", (LogLevel)32); Directory.CreateDirectory(assetPath); } } public static void SetArmorData(ItemData item, ArmorData armor) { //IL_00bf: 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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) try { item.m_shared.m_armor = armor.armor; item.m_shared.m_armorPerLevel = armor.armorPerLevel; item.m_shared.m_movementModifier = armor.movementModifier; if (armor.setName != null) { item.m_shared.m_setName = armor.setName; item.m_shared.m_setSize = armor.setSize; } item.m_shared.m_damageModifiers.Clear(); foreach (string damageModifier in armor.damageModifiers) { string[] array = damageModifier.Split(':'); NewDamageTypes result; int num = (Enum.TryParse(array[0], out result) ? ((int)result) : ((int)Enum.Parse(typeof(DamageType), array[0]))); item.m_shared.m_damageModifiers.Add(new DamageModPair { m_type = (DamageType)num, m_modifier = (DamageModifier)Enum.Parse(typeof(DamageModifier), array[1]) }); } if (armor.equipStatusEffects != null) { Dbgl("Got equip status effects for " + armor.name, (LogLevel)32); if (item.m_shared.m_equipStatusEffect == null) { item.m_shared.m_equipStatusEffect = (StatusEffect)(object)ScriptableObject.CreateInstance(); } foreach (KeyValuePair equipStatusEffect in armor.equipStatusEffects) { FieldInfo field = GetField(equipStatusEffect.Key); if (field != null) { SetValue(field, item.m_shared.m_equipStatusEffect, equipStatusEffect.Value); Dbgl($"set value of {field.Name} to {field.GetValue(item.m_shared.m_equipStatusEffect)}", (LogLevel)32); } } } if (armor.setStatusEffects == null) { return; } Dbgl("Got set status effects for " + armor.name, (LogLevel)32); if (item.m_shared.m_setStatusEffect == null) { item.m_shared.m_setStatusEffect = (StatusEffect)(object)ScriptableObject.CreateInstance(); } foreach (KeyValuePair setStatusEffect in armor.setStatusEffects) { FieldInfo field2 = GetField(setStatusEffect.Key); if (field2 != null) { field2.SetValue(item.m_shared.m_setStatusEffect, GetValue(field2, setStatusEffect.Value)); } } } catch (Exception ex) { Dbgl("Error setting data for " + armor.name + ":\n\n" + ex.StackTrace, (LogLevel)4); } } private static void SetValue(FieldInfo fi, StatusEffect se, object value) { //IL_0076: 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) //IL_00a0: 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) try { if (fi.FieldType == typeof(float)) { fi.SetValue(se, Convert.ToSingle(value)); } else if (fi.FieldType == typeof(int)) { fi.SetValue(se, Convert.ToInt32(value)); } else if (fi.FieldType == typeof(Vector3)) { fi.SetValue(se, (object)new Vector3(Convert.ToSingle(((JObject)value)["x"]), Convert.ToSingle(((JObject)value)["y"]), Convert.ToSingle(((JObject)value)["z"]))); } else if (fi.FieldType.IsEnum) { if (value is string) { fi.SetValue(se, Enum.Parse(fi.FieldType, (string)value)); } else if (value is int) { fi.SetValue(se, Convert.ChangeType(value, fi.FieldType)); } } else { fi.SetValue(se, value); } } catch (Exception ex) { Dbgl($"Error trying to set value of ({fi.FieldType}){fi.Name} to ({value.GetType()}){value}:\n\n {ex}", (LogLevel)4); } } public static FieldInfo GetField(string key) { FieldInfo fieldInfo = AccessTools.Field(typeof(SE_Stats), key); if (fieldInfo == null) { fieldInfo = AccessTools.Field(typeof(StatusEffect), key); } return fieldInfo; } public static object GetValue(FieldInfo fi, object value) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) object result = value; if (fi.FieldType == typeof(Vector3)) { JObject val = (JObject)((value is JObject) ? value : null); result = (object)new Vector3((float)val["x"], (float)val["y"], (float)val["z"]); } return result; } public static ArmorData GetArmorDataByName(string armor) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(armor); if (!Object.op_Implicit((Object)(object)itemPrefab)) { Dbgl("Armor not found!", (LogLevel)32); return null; } return GetArmorDataFromItem(itemPrefab.GetComponent().m_itemData, armor); } public unsafe static ArmorData GetArmorDataFromItem(ItemData item, string itemName) { ArmorData armorData = new ArmorData { name = itemName, armor = item.m_shared.m_armor, armorPerLevel = item.m_shared.m_armorPerLevel, movementModifier = item.m_shared.m_movementModifier, damageModifiers = item.m_shared.m_damageModifiers.Select((DamageModPair m) => ((object)(*(DamageType*)(&m.m_type))/*cast due to .constrained prefix*/).ToString() + ":" + ((object)(*(DamageModifier*)(&m.m_modifier))/*cast due to .constrained prefix*/).ToString()).ToList(), setName = item.m_shared.m_setName, setSize = item.m_shared.m_setSize }; if (item.m_shared.m_equipStatusEffect is SE_Stats) { armorData.equipStatusEffects = new Dictionary(); FieldInfo[] fields = typeof(SE_Stats).GetFields(); foreach (FieldInfo fieldInfo in fields) { armorData.equipStatusEffects[fieldInfo.Name] = fieldInfo.GetValue(item.m_shared.m_equipStatusEffect); } } if (item.m_shared.m_setStatusEffect is SE_Stats) { armorData.setStatusEffects = new Dictionary(); FieldInfo[] fields = typeof(SE_Stats).GetFields(); foreach (FieldInfo fieldInfo2 in fields) { armorData.setStatusEffects[fieldInfo2.Name] = fieldInfo2.GetValue(item.m_shared.m_setStatusEffect); } } return armorData; } public static void RunCommand(ConsoleEventArgs args) { //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Expected O, but got Unknown if (!modEnabled.Value) { return; } Terminal val = args.Context; string[] args2 = args.Args; if (args2.Length < 2) { PrintHelp(val); return; } string text = args2[1].ToLowerInvariant(); switch (text) { case "reset": ((BaseUnityPlugin)context).Config.Reload(); ((BaseUnityPlugin)context).Config.Save(); val.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded"); return; case "reload": armorDatas = GetArmorDataFromFiles(); LoadAllArmorData(); val.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " reloaded armor stats from files"); return; case "damagetypes": Dbgl("\r\n" + string.Join("\r\n", Enum.GetNames(typeof(DamageType))), (LogLevel)32); val.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " dumped damage types"); return; case "damagemods": Dbgl("\r\n" + string.Join("\r\n", Enum.GetNames(typeof(DamageModifier))), (LogLevel)32); val.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " dumped damage modifiers"); return; case "save": if (args2.Length >= 3) { string text2 = args2[^1]; ArmorData armorDataByName = GetArmorDataByName(text2); if (armorDataByName != null) { CheckModFolder(); File.WriteAllText(Path.Combine(assetPath, armorDataByName.name + ".json"), JsonConvert.SerializeObject((object)armorDataByName, (Formatting)1, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 })); val.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " saved armor data to " + text2 + ".json"); } return; } break; } if (text == "dump" && args2.Length >= 3) { string text3 = args2[^1]; ArmorData armorDataByName2 = GetArmorDataByName(text3); if (armorDataByName2 != null) { Dbgl(JsonConvert.SerializeObject((object)armorDataByName2, (Formatting)1, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }), (LogLevel)32); val.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " dumped " + text3); } } else { PrintHelp(val); } } private static void PrintHelp(Terminal terminal) { string text = "customarmorstats reset\r\ncustomarmorstats reload\r\ncustomarmorstats dump \r\ncustomarmorstats save \r\ncustomarmorstats damagetypes\r\ncustomarmorstats damagemods"; terminal.AddString(text); } } public class ArmorData { public string name; public float armor; public float armorPerLevel; public float movementModifier; public int setSize; public string setName; public List damageModifiers = new List(); public Dictionary equipStatusEffects; public Dictionary setStatusEffects; } }