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 XytreeMegingjordProgression v0.2.0
MegingjordProgression.dll
Decompiled a month agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("MegingjordProgression")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("MegingjordProgression")] [assembly: AssemblyTitle("MegingjordProgression")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace MegingjordProgression { internal static class BalanceDefaults { public const int Tier1Capacity = 150; public const int Tier2Capacity = 200; public const int Tier3Capacity = 250; public const int Tier4Capacity = 300; public const float Tier2OreBonus = 10f; public const float Tier3OreBonus = 15f; public const float Tier4OreBonus = 20f; public const float Tier3CreatureDropBonus = 5f; public const float Tier4CreatureDropBonus = 10f; public const bool BonusBossDrops = false; public const bool BonusRareDrops = false; } [BepInPlugin("xytree.megingjordprogression", "Xytree's Megingjord Progression", "0.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private const string BeltCraftingStation = "forge"; private ConfigEntry<bool> DebugMode; private ConfigEntry<bool> EnableFreeMegingjord; private ConfigEntry<bool> EnableFreeHaulerBelts; private ConfigEntry<bool> EnableFreeFighterBelts; private ConfigEntry<string> CraftingDifficulty; private Harmony harmonyInstance; private ConfigEntry<float> HaulerT1CarryBonus; private ConfigEntry<float> HaulerT2CarryBonus; private ConfigEntry<float> HaulerT3CarryBonus; private ConfigEntry<float> HaulerT4CarryBonus; private ConfigEntry<float> HaulerT1MovementSpeedPercent; private ConfigEntry<float> HaulerT2MovementSpeedPercent; private ConfigEntry<float> HaulerT3MovementSpeedPercent; private ConfigEntry<float> HaulerT4MovementSpeedPercent; private ConfigEntry<float> FighterT1CarryBonus; private ConfigEntry<float> FighterT2CarryBonus; private ConfigEntry<float> FighterT3CarryBonus; private ConfigEntry<float> FighterT4CarryBonus; private ConfigEntry<int> FighterT1ArmorBonus; private ConfigEntry<int> FighterT2ArmorBonus; private ConfigEntry<int> FighterT3ArmorBonus; private ConfigEntry<int> FighterT4ArmorBonus; private ConfigEntry<float> FighterT1HealthRegenPercent; private ConfigEntry<float> FighterT2HealthRegenPercent; private ConfigEntry<float> FighterT3HealthRegenPercent; private ConfigEntry<float> FighterT4HealthRegenPercent; private readonly Dictionary<string, ItemDrop> registeredBeltItems = new Dictionary<string, ItemDrop>(); private readonly Dictionary<string, SE_Stats> registeredBeltEffects = new Dictionary<string, SE_Stats>(); private void Awake() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown BindHaulerConfiguration(); BindFighterConfiguration(); CraftingDifficulty = ((BaseUnityPlugin)this).Config.Bind<string>("Crafting", "CraftingDifficulty", "Normal", new ConfigDescription("Crafting difficulty: Easy, Normal, or Hard. Changing this requires a game restart to rebuild recipes.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Easy", "Normal", "Hard" }), Array.Empty<object>())); SubscribeToLiveStatSettings(); harmonyInstance = new Harmony("xytree.megingjordprogression"); harmonyInstance.PatchAll(Assembly.GetExecutingAssembly()); DebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("ZZZ - Debug", "DebugMode", false, "MASTER DEBUG SWITCH: Must be true for any debug-only option below to take effect. Requires a full game restart."); EnableFreeMegingjord = ((BaseUnityPlugin)this).Config.Bind<bool>("ZZZ - Debug", "EnableFreeMegingjord", false, "DEBUG ONLY: Adds a free Forge recipe for the vanilla Megingjord. Only works when DebugMode=true. Requires a full game restart to rebuild recipes."); EnableFreeHaulerBelts = ((BaseUnityPlugin)this).Config.Bind<bool>("ZZZ - Debug", "EnableFreeHaulerBelts", false, "DEBUG ONLY: Makes all Hauler belt recipes free for testing. Only works when DebugMode=true. Requires a full game restart to rebuild recipes."); EnableFreeFighterBelts = ((BaseUnityPlugin)this).Config.Bind<bool>("ZZZ - Debug", "EnableFreeFighterBelts", false, "DEBUG ONLY: Makes all Fighter belt recipes free for testing. Only works when DebugMode=true. Requires a full game restart to rebuild recipes."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Megingjord Progression: starting."); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Debug mode: " + (DebugMode.Value ? "ENABLED" : "disabled"))); if (!DebugMode.Value && (EnableFreeMegingjord.Value || EnableFreeHaulerBelts.Value || EnableFreeFighterBelts.Value)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"One or more free-recipe toggles are true, but DebugMode is false; all debug options are being ignored."); } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crafting difficulty: " + CraftingDifficulty.Value)); PrefabManager.OnVanillaPrefabsAvailable += RegisterBelts; } private void BindHaulerConfiguration() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Expected O, but got Unknown //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Expected O, but got Unknown HaulerT1CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 1 Carry Weight Bonus", 250f, new ConfigDescription("Additional carry weight while the Hauler Belt is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); HaulerT2CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 2 Carry Weight Bonus", 350f, new ConfigDescription("Additional carry weight while Hauler Belt Tier 2 is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); HaulerT3CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 3 Carry Weight Bonus", 450f, new ConfigDescription("Additional carry weight while Hauler Belt Tier 3 is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); HaulerT4CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 4 Carry Weight Bonus", 600f, new ConfigDescription("Additional carry weight while Hauler Belt Tier 4 is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); HaulerT1MovementSpeedPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 1 Movement Speed Bonus Percent", 5f, new ConfigDescription("Movement speed bonus percentage. 5 means +5%, not 5x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>())); HaulerT2MovementSpeedPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 2 Movement Speed Bonus Percent", 5f, new ConfigDescription("Movement speed bonus percentage. 5 means +5%, not 5x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>())); HaulerT3MovementSpeedPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 3 Movement Speed Bonus Percent", 10f, new ConfigDescription("Movement speed bonus percentage. 10 means +10%, not 10x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>())); HaulerT4MovementSpeedPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Hauler Belt", "Tier 4 Movement Speed Bonus Percent", 10f, new ConfigDescription("Movement speed bonus percentage. 10 means +10%, not 10x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>())); } private void BindFighterConfiguration() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Expected O, but got Unknown //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Expected O, but got Unknown //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Expected O, but got Unknown //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Expected O, but got Unknown //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Expected O, but got Unknown //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown FighterT1CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 1 Carry Weight Bonus", 200f, new ConfigDescription("Additional carry weight while the Iron Fighter Belt is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); FighterT2CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 2 Carry Weight Bonus", 250f, new ConfigDescription("Additional carry weight while the Silver Fighter Belt is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); FighterT3CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 3 Carry Weight Bonus", 300f, new ConfigDescription("Additional carry weight while the Black Metal Fighter Belt is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); FighterT4CarryBonus = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 4 Carry Weight Bonus", 350f, new ConfigDescription("Additional carry weight while the Mistlands Fighter Belt is equipped. This is a bonus, not total capacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())); FighterT1ArmorBonus = ((BaseUnityPlugin)this).Config.Bind<int>("Fighter Belt", "Tier 1 Armour Bonus", 2, new ConfigDescription("Flat armour added while the Iron Fighter Belt is equipped.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); FighterT2ArmorBonus = ((BaseUnityPlugin)this).Config.Bind<int>("Fighter Belt", "Tier 2 Armour Bonus", 4, new ConfigDescription("Flat armour added while the Silver Fighter Belt is equipped.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); FighterT3ArmorBonus = ((BaseUnityPlugin)this).Config.Bind<int>("Fighter Belt", "Tier 3 Armour Bonus", 6, new ConfigDescription("Flat armour added while the Black Metal Fighter Belt is equipped.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); FighterT4ArmorBonus = ((BaseUnityPlugin)this).Config.Bind<int>("Fighter Belt", "Tier 4 Armour Bonus", 8, new ConfigDescription("Flat armour added while the Mistlands Fighter Belt is equipped.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); FighterT1HealthRegenPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 1 Health Regen Bonus Percent", 5f, new ConfigDescription("Additional health regeneration percentage. 5 means +5%, not 5x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); FighterT2HealthRegenPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 2 Health Regen Bonus Percent", 10f, new ConfigDescription("Additional health regeneration percentage. 10 means +10%, not 10x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); FighterT3HealthRegenPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 3 Health Regen Bonus Percent", 15f, new ConfigDescription("Additional health regeneration percentage. 15 means +15%, not 15x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); FighterT4HealthRegenPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Fighter Belt", "Tier 4 Health Regen Bonus Percent", 20f, new ConfigDescription("Additional health regeneration percentage. 20 means +20%, not 20x.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); } private void SubscribeToLiveStatSettings() { SubscribeToLiveStatSetting<float>(HaulerT1CarryBonus); SubscribeToLiveStatSetting<float>(HaulerT2CarryBonus); SubscribeToLiveStatSetting<float>(HaulerT3CarryBonus); SubscribeToLiveStatSetting<float>(HaulerT4CarryBonus); SubscribeToLiveStatSetting<float>(HaulerT1MovementSpeedPercent); SubscribeToLiveStatSetting<float>(HaulerT2MovementSpeedPercent); SubscribeToLiveStatSetting<float>(HaulerT3MovementSpeedPercent); SubscribeToLiveStatSetting<float>(HaulerT4MovementSpeedPercent); SubscribeToLiveStatSetting<float>(FighterT1CarryBonus); SubscribeToLiveStatSetting<float>(FighterT2CarryBonus); SubscribeToLiveStatSetting<float>(FighterT3CarryBonus); SubscribeToLiveStatSetting<float>(FighterT4CarryBonus); SubscribeToLiveStatSetting<int>(FighterT1ArmorBonus); SubscribeToLiveStatSetting<int>(FighterT2ArmorBonus); SubscribeToLiveStatSetting<int>(FighterT3ArmorBonus); SubscribeToLiveStatSetting<int>(FighterT4ArmorBonus); SubscribeToLiveStatSetting<float>(FighterT1HealthRegenPercent); SubscribeToLiveStatSetting<float>(FighterT2HealthRegenPercent); SubscribeToLiveStatSetting<float>(FighterT3HealthRegenPercent); SubscribeToLiveStatSetting<float>(FighterT4HealthRegenPercent); } private void SubscribeToLiveStatSetting<T>(ConfigEntry<T> setting) { setting.SettingChanged += OnLiveStatSettingChanged; } private void OnLiveStatSettingChanged(object sender, EventArgs args) { RefreshRegisteredBeltEffects(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Belt stats refreshed from Configuration Manager. If a belt was already equipped, unequip and re-equip it to refresh its active effect."); } private void RefreshRegisteredBeltEffects() { RefreshHaulerEffect("MP_HaulerBelt", HaulerT1CarryBonus, HaulerT1MovementSpeedPercent); RefreshHaulerEffect("MP_HaulerBeltT2", HaulerT2CarryBonus, HaulerT2MovementSpeedPercent); RefreshHaulerEffect("MP_HaulerBeltT3", HaulerT3CarryBonus, HaulerT3MovementSpeedPercent); RefreshHaulerEffect("MP_HaulerBeltT4", HaulerT4CarryBonus, HaulerT4MovementSpeedPercent); RefreshFighterEffect("MP_FighterBelt", FighterT1CarryBonus, FighterT1ArmorBonus, FighterT1HealthRegenPercent); RefreshFighterEffect("MP_FighterBeltT2", FighterT2CarryBonus, FighterT2ArmorBonus, FighterT2HealthRegenPercent); RefreshFighterEffect("MP_FighterBeltT3", FighterT3CarryBonus, FighterT3ArmorBonus, FighterT3HealthRegenPercent); RefreshFighterEffect("MP_FighterBeltT4", FighterT4CarryBonus, FighterT4ArmorBonus, FighterT4HealthRegenPercent); } private void RefreshHaulerEffect(string prefabName, ConfigEntry<float> carry, ConfigEntry<float> movementPercent) { if (registeredBeltEffects.TryGetValue(prefabName, out SE_Stats value)) { value.m_addMaxCarryWeight = carry.Value; value.m_speedModifier = movementPercent.Value / 100f; } } private void RefreshFighterEffect(string prefabName, ConfigEntry<float> carry, ConfigEntry<int> armor, ConfigEntry<float> healthRegenPercent) { if (registeredBeltEffects.TryGetValue(prefabName, out SE_Stats value)) { float value2 = carry.Value; int value3 = armor.Value; float value4 = healthRegenPercent.Value; value.m_addMaxCarryWeight = value2; value.m_addArmor = value3; value.m_healthRegenMultiplier = 1f + value4 / 100f; string[] obj = new string[7] { "+", value3.ToString(), " Armour, +", value4.ToString("0.#"), "% Health Regeneration, and +", value2.ToString("0.#"), " Carry Weight." }; string text = (((StatusEffect)value).m_tooltip = string.Concat(obj)); if (registeredBeltItems.TryGetValue(prefabName, out ItemDrop value5)) { value5.m_itemData.m_shared.m_description = "A specialist combat belt. " + text; } } } private int ScaleMistlandsCost(int normalCost) { string text = CraftingDifficulty.Value.ToLowerInvariant(); if (!(text == "easy")) { if (text == "hard") { return normalCost * 2; } return normalCost; } return Math.Max(1, (int)Math.Ceiling((float)normalCost / 2f)); } private int GetMetalCost() { string text = CraftingDifficulty.Value.ToLowerInvariant(); if (!(text == "easy")) { if (text == "hard") { return 40; } return 20; } return 10; } private int GetHideCost() { string text = CraftingDifficulty.Value.ToLowerInvariant(); if (!(text == "easy")) { if (text == "hard") { return 20; } return 10; } return 5; } private Sprite LoadIcon(string fileName) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) string text = "MegingjordProgression.Assets." + fileName; using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text); if (stream == null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not find embedded icon: " + text)); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, array)) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not load PNG icon: " + fileName)); return null; } ((Object)val).name = fileName; ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).wrapMode = (TextureWrapMode)1; Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)obj).name = fileName; return obj; } private FieldInfo? FindInstanceField(Type type, string fieldName) { while (type != null) { FieldInfo field = type.GetField(fieldName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return field; } type = type.BaseType; } return null; } private bool TryCopyVanillaResistanceData(SE_Stats targetEffect, string sourcePrefabName, bool consumeStatusEffect, string resistanceLabel) { try { GameObject prefab = PrefabManager.Instance.GetPrefab(sourcePrefabName); if ((Object)(object)prefab == (Object)null) { return false; } ItemDrop component = prefab.GetComponent<ItemDrop>(); StatusEffect val = ((!((Object)(object)component != (Object)null)) ? null : (consumeStatusEffect ? component.m_itemData.m_shared.m_consumeStatusEffect : component.m_itemData.m_shared.m_equipStatusEffect)); if ((Object)(object)val == (Object)null) { return false; } bool flag = false; bool flag2 = false; FieldInfo fieldInfo = FindInstanceField(((object)val).GetType(), "m_mods"); FieldInfo fieldInfo2 = FindInstanceField(((object)targetEffect).GetType(), "m_mods"); if (fieldInfo != null && fieldInfo2 != null) { IList list = fieldInfo.GetValue(val) as IList; IList list2 = fieldInfo2.GetValue(targetEffect) as IList; if (list != null) { if (list2 == null) { list2 = Activator.CreateInstance(fieldInfo2.FieldType) as IList; if (list2 != null) { fieldInfo2.SetValue(targetEffect, list2); } } if (list2 != null) { foreach (object item in list) { bool flag3 = false; foreach (object item2 in list2) { if (item2.Equals(item)) { flag3 = true; break; } } if (!flag3) { list2.Add(item); flag = true; } } } } } FieldInfo fieldInfo3 = FindInstanceField(((object)val).GetType(), "m_attributes"); FieldInfo fieldInfo4 = FindInstanceField(((object)targetEffect).GetType(), "m_attributes"); if (fieldInfo3 != null && fieldInfo4 != null) { object value = fieldInfo3.GetValue(val); object value2 = fieldInfo4.GetValue(targetEffect); if (value != null && value2 != null && value.GetType().IsEnum) { long num = Convert.ToInt64(value); long num2 = Convert.ToInt64(value2); long num3 = num | num2; if (num3 != num2) { object value3 = Enum.ToObject(fieldInfo4.FieldType, num3); fieldInfo4.SetValue(targetEffect, value3); flag2 = true; } } } return flag || flag2; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not copy vanilla " + resistanceLabel + " resistance data from " + sourcePrefabName + ": " + ex.Message)); return false; } } private bool ApplyVanillaFrostResistance(SE_Stats targetEffect, string beltName) { int num; if (!TryCopyVanillaResistanceData(targetEffect, "CapeWolf", consumeStatusEffect: false, "frost") && !TryCopyVanillaResistanceData(targetEffect, "CapeLox", consumeStatusEffect: false, "frost")) { num = (TryCopyVanillaResistanceData(targetEffect, "MeadFrostResist", consumeStatusEffect: true, "frost") ? 1 : 0); if (num == 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)(beltName + ": could not locate vanilla Frost resistance data. Frost resistance may not work; check the prefab names in the log/source version.")); return (byte)num != 0; } } else { num = 1; } ((BaseUnityPlugin)this).Logger.LogInfo((object)(beltName + ": vanilla Frost resistance data added to belt effect.")); return (byte)num != 0; } private bool ApplyVanillaFireResistance(SE_Stats targetEffect, string beltName) { bool num = TryCopyVanillaResistanceData(targetEffect, "BarleyWine", consumeStatusEffect: true, "fire"); if (num) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(beltName + ": vanilla Fire resistance data added to belt effect.")); return num; } ((BaseUnityPlugin)this).Logger.LogWarning((object)(beltName + ": could not locate vanilla Fire resistance data. Fire resistance may not work; check the BarleyWine prefab.")); return num; } private void RegisterBelts() { try { if ((Object)(object)PrefabManager.Instance.GetPrefab("BeltStrength") == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Could not find vanilla Megingjord."); return; } int metalCost = GetMetalCost(); int hideCost = GetHideCost(); RegisterHauler("MP_HaulerBelt", "Hauler Belt", HaulerT1CarryBonus.Value, HaulerT1MovementSpeedPercent.Value / 100f, "BeltStrength", "An upgraded belt for carrying heavy loads.", "Iron", metalCost, "DeerHide", hideCost, "HaulerBelt.png"); RegisterHauler("MP_HaulerBeltT2", "Hauler Belt Tier 2", HaulerT2CarryBonus.Value, HaulerT2MovementSpeedPercent.Value / 100f, "MP_HaulerBelt", "A stronger belt for carrying heavy loads.", "Silver", metalCost, "WolfPelt", hideCost, "HaulerBeltTier2.png"); RegisterHauler("MP_HaulerBeltT3", "Hauler Belt Tier 3", HaulerT3CarryBonus.Value, HaulerT3MovementSpeedPercent.Value / 100f, "MP_HaulerBeltT2", "A powerful belt for carrying heavy loads.", "BlackMetal", metalCost, "LoxPelt", hideCost, "HaulerBeltTier3.png", "Wishbone", 1); RegisterHauler("MP_HaulerBeltT4", "Hauler Belt Tier 4", HaulerT4CarryBonus.Value, HaulerT4MovementSpeedPercent.Value / 100f, "MP_HaulerBeltT3", "The ultimate belt for carrying heavy loads.", "FlametalNew", metalCost, "AskHide", hideCost, "HaulerBeltTier4.png"); RegisterFighter("MP_FighterBelt", "Fighter Belt", FighterT1CarryBonus.Value, FighterT1ArmorBonus.Value, FighterT1HealthRegenPercent.Value, "BeltStrength", "Iron", metalCost, "DeerHide", hideCost, "FighterBelt.png"); RegisterFighter("MP_FighterBeltT2", "Fighter Belt Tier 2", FighterT2CarryBonus.Value, FighterT2ArmorBonus.Value, FighterT2HealthRegenPercent.Value, "MP_FighterBelt", "Silver", metalCost, "WolfPelt", hideCost, "FighterBeltTier2.png"); RegisterFighter("MP_FighterBeltT3", "Fighter Belt Tier 3", FighterT3CarryBonus.Value, FighterT3ArmorBonus.Value, FighterT3HealthRegenPercent.Value, "MP_FighterBeltT2", "BlackMetal", metalCost, "LoxPelt", hideCost, "FighterBeltTier3.png"); RegisterFighter("MP_FighterBeltT4", "Fighter Belt Tier 4", FighterT4CarryBonus.Value, FighterT4ArmorBonus.Value, FighterT4HealthRegenPercent.Value, "MP_FighterBeltT3", new string[3] { "Eitr", "BlackMarble", "ScaleHide" }, new int[3] { ScaleMistlandsCost(8), ScaleMistlandsCost(10), ScaleMistlandsCost(4) }, "FighterBeltTier4.png"); if (DebugMode.Value && EnableFreeMegingjord.Value) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"DEBUG MODE ENABLED: registering free vanilla Megingjord recipe."); RegisterFreeMegingjordRecipe(); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)(DebugMode.Value ? "Free Megingjord debug recipe disabled by its individual toggle." : "Debug mode is off; ignoring all debug-only recipe overrides.")); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Belt registration error: " + ex)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= RegisterBelts; } } private void RegisterFighter(string prefabName, string displayName, float carryBonus, int armorBonus, float healthRegenBonusPercent, string previousBelt, string material1, int amount1, string material2, int amount2, string iconFile) { RegisterFighter(prefabName, displayName, carryBonus, armorBonus, healthRegenBonusPercent, previousBelt, new string[2] { material1, material2 }, new int[2] { amount1, amount2 }, iconFile); } private void RegisterFighter(string prefabName, string displayName, float carryBonus, int armorBonus, float healthRegenBonusPercent, string previousBelt, string material1, int amount1, string material2, int amount2, string material3, int amount3, string iconFile) { RegisterFighter(prefabName, displayName, carryBonus, armorBonus, healthRegenBonusPercent, previousBelt, new string[3] { material1, material2, material3 }, new int[3] { amount1, amount2, amount3 }, iconFile); } private void RegisterFighter(string prefabName, string displayName, float carryBonus, int armorBonus, float healthRegenBonusPercent, string previousBelt, string[] materials, int[] materialAmounts, string iconFile) { //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Expected O, but got Unknown //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Expected O, but got Unknown try { GameObject val = PrefabManager.Instance.CreateClonedPrefab(prefabName, "BeltStrength"); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": failed to clone belt.")); return; } ItemDrop component = val.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": ItemDrop missing.")); return; } Sprite val2 = LoadIcon(iconFile); if ((Object)(object)val2 != (Object)null) { component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 }; } bool flag = prefabName == "MP_FighterBeltT3" || prefabName == "MP_FighterBeltT4"; string text = healthRegenBonusPercent.ToString("0.#"); string text2 = "+" + armorBonus + " Armour, +" + text + "% Health Regeneration, and +" + carryBonus.ToString("0.#") + " Carry Weight."; if (flag) { text2 += " Grants Frost and Fire resistance while equipped."; } SE_Stats val3 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val3).name = prefabName + "_Effect"; ((StatusEffect)val3).m_name = displayName; ((StatusEffect)val3).m_tooltip = text2; ((StatusEffect)val3).m_icon = component.m_itemData.GetIcon(); val3.m_addMaxCarryWeight = carryBonus; val3.m_addArmor = armorBonus; val3.m_healthRegenMultiplier = 1f + healthRegenBonusPercent / 100f; if (flag) { ApplyVanillaFrostResistance(val3, displayName); ApplyVanillaFireResistance(val3, displayName); } if (!ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val3, false))) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": status effect registration failed.")); return; } component.m_itemData.m_shared.m_name = displayName; component.m_itemData.m_shared.m_description = "A specialist combat belt. " + text2; component.m_itemData.m_shared.m_equipStatusEffect = (StatusEffect)(object)val3; if (!ItemManager.Instance.AddItem(new CustomItem(val, false))) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": item registration failed.")); return; } registeredBeltItems[prefabName] = component; registeredBeltEffects[prefabName] = val3; ((BaseUnityPlugin)this).Logger.LogInfo((object)(displayName + " registered. Carry +" + carryBonus + ", armour +" + armorBonus + ", health regen +" + text + "%.")); RegisterRecipeWithRequirements(prefabName, displayName, previousBelt, materials, materialAmounts, DebugMode.Value && EnableFreeFighterBelts.Value, 1); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + " registration error: " + ex)); } } private void RegisterHauler(string prefabName, string displayName, float carryBonus, float speedBonus, string previousBelt, string description, string metal, int metalAmount, string hide, int hideAmount, string iconFile, string extraMaterial = "", int extraMaterialAmount = 0) { //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Expected O, but got Unknown try { GameObject val = PrefabManager.Instance.CreateClonedPrefab(prefabName, "BeltStrength"); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": failed to clone belt.")); return; } ItemDrop component = val.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": ItemDrop missing.")); return; } Sprite val2 = LoadIcon(iconFile); if ((Object)(object)val2 != (Object)null) { component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 }; } bool flag; string text = ((flag = prefabName == "MP_HaulerBeltT3" || prefabName == "MP_HaulerBeltT4") ? " Includes the Wishbone's detection effect for nearby hidden treasures and ore deposits." : string.Empty); string text2 = (flag ? " Grants Frost resistance while equipped, preventing Cold and Freezing effects." : string.Empty); string text3 = description + text + text2; SE_Stats val3 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val3).name = prefabName + "_Effect"; ((StatusEffect)val3).m_name = displayName; ((StatusEffect)val3).m_tooltip = text3; val3.m_addMaxCarryWeight = carryBonus; val3.m_speedModifier = speedBonus; if (flag) { ApplyVanillaFrostResistance(val3, displayName); } if (!ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val3, false))) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": status effect registration failed.")); return; } component.m_itemData.m_shared.m_name = displayName; component.m_itemData.m_shared.m_description = text3; component.m_itemData.m_shared.m_equipStatusEffect = (StatusEffect)(object)val3; if (!ItemManager.Instance.AddItem(new CustomItem(val, false))) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": item registration failed.")); return; } registeredBeltItems[prefabName] = component; registeredBeltEffects[prefabName] = val3; ((BaseUnityPlugin)this).Logger.LogInfo((object)(displayName + " registered successfully.")); RegisterRecipe(prefabName, displayName, previousBelt, metal, metalAmount, hide, hideAmount, extraMaterial, extraMaterialAmount); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + " registration error: " + ex)); } } private void RegisterRecipe(string prefabName, string displayName, string previousBelt, string metal, int metalAmount, string hide, int hideAmount, string extraMaterial = "", int extraMaterialAmount = 0) { if (!string.IsNullOrEmpty(extraMaterial) && extraMaterialAmount > 0) { RegisterRecipeWithRequirements(prefabName, displayName, previousBelt, new string[3] { metal, hide, extraMaterial }, new int[3] { metalAmount, hideAmount, extraMaterialAmount }, DebugMode.Value && EnableFreeHaulerBelts.Value, 1); } else { RegisterRecipeWithRequirements(prefabName, displayName, previousBelt, new string[2] { metal, hide }, new int[2] { metalAmount, hideAmount }, DebugMode.Value && EnableFreeHaulerBelts.Value, 1); } } private void RegisterRecipeWithRequirements(string prefabName, string displayName, string previousBelt, string[] materials, int[] materialAmounts, bool freeForTesting, int minStationLevel) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown RecipeConfig val = new RecipeConfig(); val.Name = "Recipe_" + prefabName; val.Item = prefabName; val.Amount = 1; val.CraftingStation = "forge"; val.MinStationLevel = minStationLevel; if (!freeForTesting) { val.AddRequirement(previousBelt, 1, 0); for (int i = 0; i < materials.Length; i++) { val.AddRequirement(materials[i], materialAmounts[i], 0); } } if (ItemManager.Instance.AddRecipe(new CustomRecipe(val))) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(displayName + " recipe registered at forge. " + (freeForTesting ? "FREE DEBUG RECIPE." : ("Required previous belt: " + previousBelt + ".")))); } else { ((BaseUnityPlugin)this).Logger.LogError((object)(displayName + ": recipe registration failed.")); } } private void RegisterFreeMegingjordRecipe() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown RecipeConfig val = new RecipeConfig(); val.Name = "Recipe_MP_FreeMegingjord"; val.Item = "BeltStrength"; val.Amount = 1; val.CraftingStation = "forge"; val.MinStationLevel = 1; if (ItemManager.Instance.AddRecipe(new CustomRecipe(val))) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Free Megingjord debug recipe registered."); } else { ((BaseUnityPlugin)this).Logger.LogError((object)"Free Megingjord debug recipe registration failed."); } } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterBelts; if (harmonyInstance != null) { harmonyInstance.UnpatchSelf(); } } } [HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")] internal static class HaulerWishboneEffectPatch { private const string HaulerTier3Prefab = "MP_HaulerBeltT3"; private const string HaulerTier4Prefab = "MP_HaulerBeltT4"; private const string HaulerFinderEffectName = "MP_HaulerWishboneFinder"; private static StatusEffect? finderTemplate; private static bool loggedMissingWishbone; private static bool loggedMissingAddMethod; private static int GetValheimStableHashCode(string value) { if (value == null) { return 0; } int num = 5381; int num2 = num; for (int i = 0; i < value.Length && value[i] != 0; i += 2) { num = ((num << 5) + num) ^ value[i]; if (i == value.Length - 1 || value[i + 1] == '\0') { break; } num2 = ((num2 << 5) + num2) ^ value[i + 1]; } return num + num2 * 1566083941; } private static StatusEffect? GetFinderTemplate() { if ((Object)(object)finderTemplate != (Object)null) { return finderTemplate; } if ((Object)(object)ObjectDB.instance == (Object)null) { return null; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Wishbone"); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); StatusEffect val2 = (((Object)(object)val != (Object)null) ? val.m_itemData.m_shared.m_equipStatusEffect : null); if ((Object)(object)val2 == (Object)null) { if (!loggedMissingWishbone) { Debug.LogWarning((object)"[MegingjordProgression] Could not find the vanilla Wishbone finder status effect."); loggedMissingWishbone = true; } return null; } finderTemplate = Object.Instantiate<StatusEffect>(val2); ((Object)finderTemplate).name = "MP_HaulerWishboneFinder"; return finderTemplate; } private static bool InvokeAddStatusEffect(SEMan manager, StatusEffect effect) { MethodInfo[] methods = typeof(SEMan).GetMethods(BindingFlags.Instance | BindingFlags.Public); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name != "AddStatusEffect") { continue; } ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length == 0 || parameters[0].ParameterType != typeof(StatusEffect)) { continue; } object[] array = new object[parameters.Length]; for (int j = 0; j < parameters.Length; j++) { if (parameters[j].HasDefaultValue) { array[j] = parameters[j].DefaultValue; continue; } Type parameterType = parameters[j].ParameterType; array[j] = (parameterType.IsValueType ? Activator.CreateInstance(parameterType) : null); } array[0] = effect; methodInfo.Invoke(manager, array); return true; } if (!loggedMissingAddMethod) { Debug.LogWarning((object)"[MegingjordProgression] No SEMan.AddStatusEffect(StatusEffect) overload was found; the Hauler Wishbone effect could not be added."); loggedMissingAddMethod = true; } return false; } private static void Postfix(Humanoid __instance) { try { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null || (Object)(object)ObjectDB.instance == (Object)null) { return; } Inventory inventory = ((Humanoid)val).GetInventory(); if (inventory == null) { return; } bool flag = false; foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem != null && allItem.m_equipped && !((Object)(object)allItem.m_dropPrefab == (Object)null)) { string name = ((Object)allItem.m_dropPrefab).name; if (name == "MP_HaulerBeltT3" || name == "MP_HaulerBeltT4") { flag = true; break; } } } SEMan sEMan = ((Character)val).GetSEMan(); if (sEMan == null) { return; } int valheimStableHashCode = GetValheimStableHashCode("MP_HaulerWishboneFinder"); bool flag2 = sEMan.HaveStatusEffect(valheimStableHashCode); if (flag && !flag2) { StatusEffect val2 = GetFinderTemplate(); if (!((Object)(object)val2 == (Object)null)) { StatusEffect val3 = Object.Instantiate<StatusEffect>(val2); ((Object)val3).name = "MP_HaulerWishboneFinder"; if (InvokeAddStatusEffect(sEMan, val3)) { Debug.Log((object)"[MegingjordProgression] Applied Wishbone detection from Hauler Tier 3/4."); } } } else if (!flag && flag2) { sEMan.RemoveStatusEffect(valheimStableHashCode, false); Debug.Log((object)"[MegingjordProgression] Removed Hauler Wishbone detection because Tier 3/4 is no longer equipped."); } } catch (Exception ex) { Debug.LogError((object)("[MegingjordProgression] Failed to manage the Hauler Wishbone effect: " + ex)); } } } }