using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using SimpleJson; using UnityEngine; using UnityEngine.Serialization; using Valharvest.Configurations; using Valharvest.Scripts; using Valharvest.WorldGen; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Valharvest")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Valharvest")] [assembly: AssemblyCopyright("Copyright Frenvius 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("3.3.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("3.3.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 CustomBeehive : MonoBehaviour, Hoverable, Interactable { public string m_name = ""; public GameObject m_hideWhenPicked; public Transform m_spawnPoint; public float m_secPerUnit = 800f; public int m_maxHoney = 3; public ItemDrop m_honeyItem; public EffectList m_spawnEffect = new EffectList(); private ZNetView m_nview; private void Awake() { m_nview = ((Component)this).GetComponent(); if (m_nview.GetZDO() != null) { HidePrefab(); if (m_nview.IsOwner() && m_nview.GetZDO().GetLong("lastTime", 0L) == 0L) { m_nview.GetZDO().Set("lastTime", ZNet.instance.GetTime().Ticks); } m_nview.Register("Extract", (Action)RPC_Extract); ((MonoBehaviour)this).InvokeRepeating("UpdateBees", 0f, 10f); ((MonoBehaviour)this).InvokeRepeating("HidePrefab", 0f, 5f); } } private void HidePrefab() { if (Object.op_Implicit((Object)(object)m_hideWhenPicked)) { int honeyLevel = GetHoneyLevel(); m_hideWhenPicked.SetActive(honeyLevel > 0); } } public string GetHoverText() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, false, false)) { return Localization.instance.Localize(m_name + "\n$piece_noaccess"); } int honeyLevel = GetHoneyLevel(); if (honeyLevel > 0) { return Localization.instance.Localize(m_name + " ( " + m_honeyItem.m_itemData.m_shared.m_name + " x " + honeyLevel + " )\n[$KEY_Use] $water_well_extract"); } return Localization.instance.Localize(m_name + " ( $piece_container_empty )\n[$KEY_Use] $water_well_check"); } public string GetHoverName() { return m_name; } public bool Interact(Humanoid character, bool repeat, bool alt) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (repeat) { return false; } if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false)) { return true; } if (GetHoneyLevel() > 0) { Extract(); } else { ((Character)character).Message((MessageType)2, "$water_well_use", 0, (Sprite)null); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } private void Extract() { m_nview.InvokeRPC("Extract", Array.Empty()); } private void RPC_Extract(long caller) { //IL_0033: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) int honeyLevel = GetHoneyLevel(); if (honeyLevel > 0) { if (Object.op_Implicit((Object)(object)m_hideWhenPicked)) { m_hideWhenPicked.SetActive(false); } m_spawnEffect.Create(m_spawnPoint.position, Quaternion.identity, (Transform)null, 1f, -1); for (int i = 0; i < honeyLevel; i++) { Vector2 val = Random.insideUnitCircle * 0.5f; Vector3 val2 = m_spawnPoint.position + new Vector3(val.x, 0.25f * (float)i, val.y); Object.Instantiate(m_honeyItem, val2, Quaternion.identity); } ResetLevel(); } } private float GetTimeSinceLastUpdate() { DateTime dateTime = new DateTime(m_nview.GetZDO().GetLong("lastTime", ZNet.instance.GetTime().Ticks)); DateTime time = ZNet.instance.GetTime(); TimeSpan timeSpan = time - dateTime; m_nview.GetZDO().Set("lastTime", time.Ticks); double num = timeSpan.TotalSeconds; if (num < 0.0) { num = 0.0; } return (float)num; } private void ResetLevel() { m_nview.GetZDO().Set("level", 0); } private void IncreseLevel(int i) { int honeyLevel = GetHoneyLevel(); honeyLevel += i; honeyLevel = Mathf.Clamp(honeyLevel, 0, m_maxHoney); m_nview.GetZDO().Set("level", honeyLevel); } private int GetHoneyLevel() { return m_nview.GetZDO().GetInt("level", 0); } private void UpdateBees() { if (GetHoneyLevel() > 0 && Object.op_Implicit((Object)(object)m_hideWhenPicked)) { m_hideWhenPicked.SetActive(true); } if (m_nview.IsOwner()) { float timeSinceLastUpdate = GetTimeSinceLastUpdate(); float @float = m_nview.GetZDO().GetFloat("product", 0f); @float += timeSinceLastUpdate; if (@float > m_secPerUnit) { int i = (int)(@float / m_secPerUnit); IncreseLevel(i); @float = 0f; } m_nview.GetZDO().Set("product", @float); } } } namespace Valharvest { public static class BoneAppetitCompat { private static bool? _isInstalled; public static bool IsInstalled { get { if (!_isInstalled.HasValue) { _isInstalled = Chainloader.PluginInfos.ContainsKey("com.rockerkitten.boneappetit"); Logger.LogInfo((object)("BoneAppetit detection: " + (_isInstalled.Value ? "INSTALLED" : "NOT FOUND"))); } return _isInstalled.Value; } } public static string GetEggItem() { if (!IsInstalled) { return "vh_egg"; } return "rk_egg"; } public static string GetPorkItem() { if (!IsInstalled) { return "RawMeat"; } return "rk_pork"; } public static string GetCookingStation(string stationName, bool useBAStations = true) { if (IsInstalled && useBAStations) { return stationName; } switch (stationName) { case "rk_prep": if (Valharvest.Configurations.Valharvest.UseVanillaPrepTable.Value) { return "piece_preptable"; } return "piece_prep_table"; case "rk_griddle": case "rk_grill": return "piece_cooking_pot"; default: return stationName; } } public static void RemapIngredients(RequirementConfig[] requirements) { if (IsInstalled || requirements == null) { return; } for (int i = 0; i < requirements.Length; i++) { if (requirements[i].Item == "rk_egg") { requirements[i].Item = "vh_egg"; } else if (requirements[i].Item == "rk_pork") { requirements[i].Item = "RawMeat"; } } } } public static class Utils { private const string Name = "name"; private const string Food = "food"; private const string Weight = "weight"; private const string Variants = "variants"; private const string FoodRegen = "foodRegen"; private const string FoodStamina = "foodStamina"; private const string Description = "description"; private const string MaxStackSize = "maxStackSize"; private const string FoodBurnTime = "foodBurnTime"; private const string ConsumeStatusEffect = "consumeStatusEffect"; public static readonly int MainTex = Shader.PropertyToID("_MainTex"); public static readonly int Color = Shader.PropertyToID("_Color"); private static readonly int Cull = Shader.PropertyToID("_Cull"); private static readonly int Cutoff = Shader.PropertyToID("_Cutoff"); private static readonly int Height = Shader.PropertyToID("_Height"); private static readonly int AddSnow = Shader.PropertyToID("_AddSnow"); private static readonly int AddRain = Shader.PropertyToID("_AddRain"); private static readonly int CamCull = Shader.PropertyToID("_CamCull"); private static readonly int Metallic = Shader.PropertyToID("_Metallic"); private static readonly int SwaySpeed = Shader.PropertyToID("_SwaySpeed"); private static readonly int MossNormal = Shader.PropertyToID("_MossNormal"); private static readonly int Glossiness = Shader.PropertyToID("_Glossiness"); private static readonly int RippleSpeed = Shader.PropertyToID("_RippleSpeed"); private static readonly int SwayDistance = Shader.PropertyToID("_SwayDistance"); private static readonly int PushDistance = Shader.PropertyToID("_PushDistance"); private static readonly int MossTransition = Shader.PropertyToID("_MossTransition"); private static readonly int RippleDistance = Shader.PropertyToID("_RippleDistance"); private static readonly int FadeDistanceMin = Shader.PropertyToID("_FadeDistanceMin"); private static readonly int FadeDistanceMax = Shader.PropertyToID("_FadeDistanceMax"); private static readonly int RippleDeadzoneMin = Shader.PropertyToID("_RippleDeadzoneMin"); private static readonly int RippleDeadzoneMax = Shader.PropertyToID("_RippleDeadzoneMax"); public static void ConfigureMaterial(Material material, Shader shader, JsonObject content, Dictionary typeDict, Dictionary getMatItem) { material.shader = shader; foreach (KeyValuePair item in content) { if (!(item.Key == "shader")) { SetMaterialConfigItems(typeDict, item, material, getMatItem); } } } private static void SetMaterialConfigItems(Dictionary typeDict, KeyValuePair materialItem, Material material, Dictionary getMatItem) { //IL_0065: Unknown result type (might be due to invalid IL or missing references) switch (typeDict[materialItem.Value.GetType()]) { case 0: material.SetFloat(getMatItem[materialItem.Key], float.Parse(materialItem.Value.ToString())); break; case 1: { Color val = default(Color); ColorUtility.TryParseHtmlString(materialItem.Value.ToString(), ref val); material.SetColor(Color, val); break; } case 2: material.SetFloat(getMatItem[materialItem.Key], float.Parse(materialItem.Value.ToString())); break; } } public static Dictionary GetTypeDict() { return new Dictionary { { typeof(long), 0 }, { typeof(string), 1 }, { typeof(double), 2 } }; } public static Dictionary GetMatItem() { return new Dictionary { { "glossiness", Glossiness }, { "cutoff", Cutoff }, { "mossNormal", MossNormal }, { "mossTransition", MossTransition }, { "addSnow", AddSnow }, { "addRain", AddRain }, { "height", Height }, { "swaySpeed", SwaySpeed }, { "metallic", Metallic }, { "swayDistance", SwayDistance }, { "rippleSpeed", RippleSpeed }, { "rippleDistance", RippleDistance }, { "rippleDeadzoneMin", RippleDeadzoneMin }, { "rippleDeadzoneMax", RippleDeadzoneMax }, { "pushDistance", PushDistance }, { "camCull", CamCull }, { "cull", Cull }, { "color", Color }, { "fadeDistanceMin", FadeDistanceMin }, { "fadeDistanceMax", FadeDistanceMax } }; } public static void ChangeItemDrop(CustomItem item, string configObject) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BoneAppetitBalance.resources"); if (stream != null) { JsonObject content = SimpleJson.DeserializeObject(SimpleJson.DeserializeObject(new StreamReader(stream).ReadToEnd())[configObject].ToString()); SharedData shared = item.ItemDrop.m_itemData.m_shared; SetItemDropFromContent(content, shared); } } public static void LoadNewFood() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("newFoodsConfig.resources"); if (stream == null) { return; } foreach (KeyValuePair item in SimpleJson.DeserializeObject(new StreamReader(stream).ReadToEnd())) { string key = item.Key; JsonObject val = SimpleJson.DeserializeObject(item.Value.ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject(val["requirements"].ToString()); BoneAppetitCompat.RemapIngredients(requirements); CustomItem val2 = null; try { val2 = new CustomItem(Main.modAssets.LoadAsset(key), true, new ItemConfig { Name = val["name"].ToString(), Enabled = true, Requirements = requirements, CraftingStation = GetCookingStation(val), Amount = Convert.ToInt32(val["amount"].ToString()) }); ChangeFoodDrop(val2, key); } catch (Exception ex) { Logger.LogError((object)("Error while loading " + key + ": " + ex.Message)); } finally { ItemManager.Instance.AddItem(val2); } } PrefabManager.OnVanillaPrefabsAvailable -= LoadNewFood; } private static string GetCookingStation(JsonObject foodObject) { return BoneAppetitCompat.GetCookingStation(foodObject["craftingStation"].ToString(), Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value); } public static void LoadBalancedFood() { if (!BoneAppetitCompat.IsInstalled) { ItemManager.OnItemsRegisteredFejd -= LoadBalancedFood; return; } using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BoneAppetitBalance.resources"); if (stream == null) { return; } foreach (KeyValuePair item in SimpleJson.DeserializeObject(new StreamReader(stream).ReadToEnd())) { string key = item.Key; JsonObject val = SimpleJson.DeserializeObject(item.Value.ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject(val["requirements"].ToString()); BoneAppetitCompat.RemapIngredients(requirements); RegisterFood(key, key, Convert.ToInt32(val["amount"].ToString()), GetCookingStation(val), requirements); } ItemManager.OnItemsRegisteredFejd -= LoadBalancedFood; } private static void ChangeFoodDrop(CustomItem item, string configObject) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("newFoodsConfig.resources"); if (stream != null) { JsonObject content = SimpleJson.DeserializeObject(SimpleJson.DeserializeObject(new StreamReader(stream).ReadToEnd())[configObject].ToString()); SharedData shared = item.ItemDrop.m_itemData.m_shared; SetItemDropFromContent(content, shared); } } private static void SetItemDropFromContent(JsonObject content, SharedData itemDrop) { if (content["name"] != null) { itemDrop.m_name = content["name"].ToString(); } if (content["description"] != null) { itemDrop.m_description = content["description"].ToString(); } if (content["weight"] != null) { itemDrop.m_weight = float.Parse(content["weight"].ToString()); } if (content["maxStackSize"] != null) { itemDrop.m_maxStackSize = int.Parse(content["maxStackSize"].ToString()); } if (content["variants"] != null) { itemDrop.m_variants = int.Parse(content["variants"].ToString()); } if (content["food"] != null) { itemDrop.m_food = float.Parse(content["food"].ToString()); } if (content["foodStamina"] != null) { itemDrop.m_foodStamina = float.Parse(content["foodStamina"].ToString()); } if (content["foodBurnTime"] != null) { itemDrop.m_foodBurnTime = float.Parse(content["foodBurnTime"].ToString()) * 60f; } if (content["foodRegen"] != null) { itemDrop.m_foodRegen = float.Parse(content["foodRegen"].ToString()); } if (content["consumeStatusEffect"] != null) { StatusEffect consumeStatusEffect = Main.modAssets.LoadAsset(content["consumeStatusEffect"].ToString()); itemDrop.m_consumeStatusEffect = consumeStatusEffect; } } private static void RegisterFood(string name, string prefab, int amount, string craftingStation, RequirementConfig[] requirements) { //IL_0021: 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_002d: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown CustomItem item = ItemManager.Instance.GetItem(prefab); ItemManager.Instance.RemoveRecipe("Recipe_" + prefab); try { CustomRecipe val = new CustomRecipe(new RecipeConfig { Item = prefab, Amount = amount, CraftingStation = craftingStation, Requirements = requirements }); ChangeItemDrop(item, prefab); ItemManager.Instance.AddRecipe(val); } catch (Exception ex) { Logger.LogError((object)("Error while loading " + name + ": " + ex.Message)); } } public static string ReadEmbeddedFile(string embeddedName) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedName); if (stream == null) { return null; } return new StreamReader(stream).ReadToEnd(); } } [BepInPlugin("com.frenvius.Valharvest", "Valharvest", "3.3.0")] [BepInDependency("com.jotunn.jotunn", "2.7.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Main : BaseUnityPlugin { public const string ModGuid = "com.frenvius.Valharvest"; public const string ModName = "Valharvest"; public const string Version = "3.3.0"; public static AssetBundle modAssets; public static EffectList loxMilkSfx; public static EffectList boneMealVfx; public static Texture2D newEggTexture; public static Texture2D pizzaPlateTexture; public static Sprite newEggSprite; public static Sprite pizzaSprite; public static bool IsFarmingModInstalled; public static KeyboardShortcut MassPlantShortcut; public GameObject greydwarfFab; public GameObject trollFab; public GameObject goblinFab; public GameObject draugrFab; public GameObject greydwarfBruteFab; public GameObject draugrEliteFab; public GameObject seagullFab; private Harmony _h; public void Awake() { //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Expected O, but got Unknown CreateConfigValues(); AssetLoad(); Loaders.LoadItems(); Loaders.LoadPieces(); PrefabManager.OnVanillaPrefabsAvailable += Utils.LoadNewFood; PrefabManager.OnVanillaPrefabsAvailable += LoadSounds; PrefabManager.OnVanillaPrefabsAvailable += PlantUtils.AddCustomPlantsPrefab; if (BoneAppetitCompat.IsInstalled) { ItemManager.OnItemsRegisteredFejd += Utils.LoadBalancedFood; ItemManager.OnItemsRegisteredFejd += LoadBalance; } ItemManager.OnItemsRegisteredFejd += Loaders.LoadCookingStations; PrefabManager.OnVanillaPrefabsAvailable += Plants.AddCustomPlants; PrefabManager.OnVanillaPrefabsAvailable += CustomDrops; PrefabManager.OnVanillaPrefabsAvailable += CheckIfFarmingModInstalled; PrefabManager.OnVanillaPrefabsAvailable += HandlePrefabComponent.ZNetViewAwakePatch; PrefabManager.OnPrefabsRegistered += HandlePrefabComponent.PrepTableSmokePatch; PrefabManager.OnPrefabsRegistered += HandlePrefabComponent.FoodCrateEffectsPatch; PrefabManager.OnPrefabsRegistered += CustomFeed; PrefabManager.OnPrefabsRegistered += PrepTableRecipeCopier.CopyVanillaPrepTableRecipes; CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new ExportItemsCommand()); if (Valharvest.Configurations.Valharvest.DropEnabled.Value) { PrefabManager.OnVanillaPrefabsAvailable += NewDrops; } _h = new Harmony("mod.valharvest"); _h.PatchAll(); } private void OnDestroy() { Logger.LogInfo((object)"Valharvest: OnDestroy"); _h.UnpatchSelf(); } private static void CheckIfFarmingModInstalled() { //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_00cf: 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_00db: Unknown result type (might be due to invalid IL or missing references) Chainloader.Start(); using (IEnumerator> enumerator = Chainloader.PluginInfos.Where((KeyValuePair plugin) => plugin.Value.Metadata.GUID == "org.bepinex.plugins.farming").GetEnumerator()) { if (enumerator.MoveNext()) { _ = enumerator.Current; IsFarmingModInstalled = true; } } if (IsFarmingModInstalled) { ConfigFile config = Chainloader.PluginInfos["org.bepinex.plugins.farming"].Instance.Config; foreach (ConfigDefinition key in config.Keys) { if (((object)key).ToString().Contains("Toggle Mass Plant")) { ConfigEntryBase val = config[key]; KeyCode val2 = (KeyCode)Enum.Parse(typeof(KeyCode), val.BoxedValue.ToString()); MassPlantShortcut = new KeyboardShortcut(val2, Array.Empty()); } } } PrefabManager.OnVanillaPrefabsAvailable -= CheckIfFarmingModInstalled; } public void CreateConfigValues() { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; new Valharvest.Configurations.Valharvest(((BaseUnityPlugin)this).Config); } public void LoadBalance() { if (!BoneAppetitCompat.IsInstalled) { ItemManager.OnItemsRegistered -= LoadBalance; return; } try { BoneAppetitBalance.SeagullEgg(); BoneAppetitBalance.Kabob(); BoneAppetitBalance.Pizza(); } catch (Exception ex) { Logger.LogError((object)("Error while running OnItemsRegistered: " + ex.Message)); } finally { Logger.LogInfo((object)"Load Complete."); ItemManager.OnItemsRegistered -= LoadBalance; } } public void AssetLoad() { modAssets = AssetUtils.LoadAssetBundleFromResources("valharvest", Assembly.GetExecutingAssembly()); newEggTexture = modAssets.LoadAsset("egg"); newEggSprite = modAssets.LoadAsset("eggsprite"); pizzaPlateTexture = modAssets.LoadAsset("pizza_plate"); pizzaSprite = modAssets.LoadAsset("pizzaSprite"); Logger.LogInfo((object)"Preparing the plants..."); } public void LoadSounds() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_00dc: 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_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_010d: 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) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0140: 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 GameObject val = modAssets.LoadAsset("sfx_pours_milk"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true)); GameObject val2 = modAssets.LoadAsset("sfx_lox_pet_milk"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true)); GameObject val3 = modAssets.LoadAsset("sfx_lox_pet"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val3, true)); GameObject val4 = modAssets.LoadAsset("vfx_bone_meal"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val4, true)); EffectList val5 = new EffectList(); val5.m_effectPrefabs = (EffectData[])(object)new EffectData[2] { new EffectData { m_prefab = val2, m_enabled = true }, new EffectData { m_prefab = val, m_enabled = true } }; loxMilkSfx = val5; val5 = new EffectList(); val5.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = val4, m_enabled = true } }; boneMealVfx = val5; PrefabManager.OnVanillaPrefabsAvailable -= LoadSounds; CookingConversionConfig val6 = new CookingConversionConfig { FromItem = "apple", ToItem = "baked_apple", CookTime = 5f, Station = "piece_cookingstation" }; ItemManager.Instance.AddItemConversion(new CustomItemConversion((ConversionConfig)(object)val6)); } public void NewDrops() { //IL_00f0: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0103: 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_0115: 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_0128: Expected O, but got Unknown //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Expected O, but got Unknown //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Expected O, but got Unknown //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Expected O, but got Unknown greydwarfFab = PrefabManager.Instance.GetPrefab("Greydwarf"); trollFab = PrefabManager.Instance.GetPrefab("Troll"); goblinFab = PrefabManager.Instance.GetPrefab("Goblin"); draugrFab = PrefabManager.Instance.GetPrefab("Draugr"); greydwarfBruteFab = PrefabManager.Instance.GetPrefab("Greydwarf_Elite"); draugrEliteFab = PrefabManager.Instance.GetPrefab("Draugr_Elite"); GameObject prefab = PrefabManager.Instance.GetPrefab("pepper"); GameObject prefab2 = PrefabManager.Instance.GetPrefab("tomato"); GameObject prefab3 = PrefabManager.Instance.GetPrefab("garlic"); GameObject prefab4 = PrefabManager.Instance.GetPrefab("rice"); GameObject prefab5 = PrefabManager.Instance.GetPrefab("potato"); GameObject prefab6 = PrefabManager.Instance.GetPrefab("pumpkin"); greydwarfFab.GetComponent().m_drops.Add(new Drop { m_prefab = prefab, m_amountMin = 1, m_amountMax = 2, m_chance = 0.4f, m_levelMultiplier = true, m_onePerPlayer = false }); trollFab.GetComponent().m_drops.Add(new Drop { m_prefab = prefab3, m_amountMin = 1, m_amountMax = 3, m_chance = 0.4f, m_levelMultiplier = true, m_onePerPlayer = false }); goblinFab.GetComponent().m_drops.Add(new Drop { m_prefab = prefab4, m_amountMin = 1, m_amountMax = 1, m_chance = 0.4f, m_levelMultiplier = true, m_onePerPlayer = false }); draugrFab.GetComponent().m_drops.Add(new Drop { m_prefab = prefab2, m_amountMin = 1, m_amountMax = 1, m_chance = 0.4f, m_levelMultiplier = true, m_onePerPlayer = false }); greydwarfBruteFab.GetComponent().m_drops.Add(new Drop { m_prefab = prefab5, m_amountMin = 1, m_amountMax = 1, m_chance = 0.4f, m_levelMultiplier = true, m_onePerPlayer = false }); draugrEliteFab.GetComponent().m_drops.Add(new Drop { m_prefab = prefab6, m_amountMin = 1, m_amountMax = 1, m_chance = 0.4f, m_levelMultiplier = true, m_onePerPlayer = false }); PrefabManager.OnVanillaPrefabsAvailable -= NewDrops; } public void CustomDrops() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) if (!BoneAppetitCompat.IsInstalled) { try { GameObject prefab = PrefabManager.Instance.GetPrefab("Seagal"); if ((Object)(object)prefab != (Object)null) { GameObject prefab2 = PrefabManager.Instance.GetPrefab(BoneAppetitCompat.GetEggItem()); if ((Object)(object)prefab2 != (Object)null) { DropOnDestroyed component = prefab.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_dropWhenDestroyed.m_drops.Add(new DropData { m_item = prefab2, m_stackMin = 1, m_stackMax = 2, m_weight = 0.75f }); Logger.LogInfo((object)"Added vh_egg drop to seagulls (BoneAppetit not installed)"); } } } } catch (Exception ex) { Logger.LogWarning((object)("Failed to add egg drops to seagulls: " + ex.Message)); } } PrefabManager.OnVanillaPrefabsAvailable -= CustomDrops; } public void AddConsumableItemsToCreature(string[] items, string creature) { MonsterAI component = PrefabManager.Instance.GetPrefab(creature).GetComponent(); foreach (string text in items) { GameObject prefab = PrefabManager.Instance.GetPrefab(text); component.m_consumeItems.Add(prefab.GetComponent()); } } public void CustomFeed() { string[] items = new string[3] { "apple", "tomato", "potato" }; AddConsumableItemsToCreature(items, "Boar"); string[] items2 = new string[1] { BoneAppetitCompat.GetPorkItem() }; AddConsumableItemsToCreature(items2, "Wolf"); PrefabManager.OnVanillaPrefabsAvailable -= CustomFeed; } } } namespace Valharvest.WorldGen { public static class Plants { private const string Min = "min"; private const string Max = "max"; private const string Biome = "biome"; private const string InForest = "inForest"; private const string BiomeArea = "biomeArea"; private const string GroupRadius = "groupRadius"; private const string GroupSizeMin = "groupSizeMin"; private const string GroupSizeMax = "groupSizeMax"; private const string MinAltitude = "minAltitude"; private const string MaxAltitude = "maxAltitude"; private const string ForestThresholdMin = "forestThresholdMin"; private const string ForestThresholdMax = "forestThresholdMax"; private const Biome Swamp = 2; private const Biome Plains = 16; private const Biome Meadows = 1; private const Biome Mountain = 4; private const Biome Mistlands = 512; private const Biome BlackForest = 8; private const BiomeArea Edge = 1; private const BiomeArea Median = 2; private const BiomeArea Everything = 3; public static void AddCustomPlants() { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown string text = Utils.ReadEmbeddedFile("plantsLocations.resources"); if (text == null) { return; } foreach (KeyValuePair item in SimpleJson.DeserializeObject(text)) { GameObject val = PrefabManager.Instance.CreateClonedPrefab(item.Key + "_wild", item.Key); JsonObject content = SimpleJson.DeserializeObject(item.Value.ToString()); try { ZoneManager.Instance.AddCustomVegetation(new CustomVegetation(val, true, GetVegetationConfig(content))); } catch (Exception ex) { Logger.LogError((object)("Error while loading " + item.Key + ": " + ex.Message)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= AddCustomPlants; } } } private static VegetationConfig GetVegetationConfig(JsonObject content) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) VegetationConfig val = new VegetationConfig(); Dictionary biome = GetBiome(); Dictionary biomeArea = GetBiomeArea(); if (content["min"] != null) { val.Min = float.Parse(content["min"].ToString()); } if (content["max"] != null) { val.Max = float.Parse(content["max"].ToString()); } if (content["groupSizeMin"] != null) { val.GroupSizeMin = int.Parse(content["groupSizeMin"].ToString()); } if (content["groupSizeMax"] != null) { val.GroupSizeMax = int.Parse(content["groupSizeMax"].ToString()); } if (content["groupRadius"] != null) { val.GroupRadius = float.Parse(content["groupRadius"].ToString()); } if (content["minAltitude"] != null) { val.MinAltitude = float.Parse(content["minAltitude"].ToString()); } if (content["maxAltitude"] != null) { val.MaxAltitude = float.Parse(content["maxAltitude"].ToString()); } if (content["biome"] != null) { val.Biome = biome[content["biome"].ToString()]; } if (content["biomeArea"] != null) { val.BiomeArea = biomeArea[content["biomeArea"].ToString()]; } if (content["inForest"] != null) { val.InForest = Convert.ToBoolean(content["inForest"].ToString()); } if (content["forestThresholdMin"] != null) { val.ForestThresholdMin = float.Parse(content["forestThresholdMin"].ToString()); } if (content["forestThresholdMax"] != null) { val.ForestThresholdMax = float.Parse(content["forestThresholdMax"].ToString()); } return val; } private static Dictionary GetBiome() { return new Dictionary { { "swamp", (Biome)2 }, { "plains", (Biome)16 }, { "meadows", (Biome)1 }, { "mountain", (Biome)4 }, { "mistlands", (Biome)512 }, { "black_forest", (Biome)8 } }; } private static Dictionary GetBiomeArea() { return new Dictionary { { "edge", (BiomeArea)1 }, { "median", (BiomeArea)2 }, { "everything", (BiomeArea)3 } }; } } public static class PlantUtils { public static void AddCustomPlantsPrefab() { //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Expected O, but got Unknown string text = Utils.ReadEmbeddedFile("plants.resources"); if (text == null) { return; } foreach (KeyValuePair item in SimpleJson.DeserializeObject(text)) { Dictionary assetBundle = Loaders.GetAssetBundle(); JsonObject val = SimpleJson.DeserializeObject(item.Value.ToString()); string key = val["assetBundle"].ToString(); object obj = val["dropConfig"]; object obj2 = val["respawnConfig"]; Dictionary> dropConfigs = Valharvest.Configurations.Valharvest.GetDropConfigs(); Dictionary> respawnTimeConfigs = Valharvest.Configurations.Valharvest.GetRespawnTimeConfigs(); GameObject val2 = assetBundle[key].LoadAsset(item.Key); LoadPlantMaterials(val2, val); try { if (obj != null) { ConfigEntry val3 = dropConfigs[obj.ToString()]; val2.GetComponent().m_amount = val3.Value; } if (obj2 != null) { ConfigEntry val4 = respawnTimeConfigs[obj2.ToString()]; val2.GetComponent().m_respawnTimeMinutes = val4.Value * 60; } if (val["crafting"] != null) { CustomPiece val5 = Loaders.CreatePieceRecipe(val2, val); PieceManager.Instance.AddPiece(val5); } else { PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true)); } } catch (Exception ex) { Logger.LogError((object)("Error while loading " + item.Key + ": " + ex.Message)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= AddCustomPlantsPrefab; } } } private static void LoadPlantMaterials(GameObject plantPrefab, JsonObject plantObject) { JsonObject val = SimpleJson.DeserializeObject(plantObject["materials"].ToString()); foreach (Renderer renderer in ShaderHelper.GetRenderers(plantPrefab)) { Material[] sharedMaterials = renderer.sharedMaterials; foreach (Material val2 in sharedMaterials) { if (!((Object)(object)val2 == (Object)null)) { string name = ((Object)val2).name; if (val.ContainsKey(name) && !string.IsNullOrEmpty(val[name].ToString())) { Dictionary typeDict = Utils.GetTypeDict(); Dictionary matItem = Utils.GetMatItem(); JsonObject val3 = SimpleJson.DeserializeObject(val[name].ToString()); Shader prefab = Cache.GetPrefab(val3["shader"].ToString()); Texture mainTexture = val2.mainTexture; Utils.ConfigureMaterial(val2, prefab, val3, typeDict, matItem); val2.SetTexture(Utils.MainTex, mainTexture); } } } } } } } namespace Valharvest.Scripts { public static class BoneAppetitBalance { public static void SeagullEgg() { try { foreach (Material item in from rend in ShaderHelper.GetRenderers(PrefabManager.Instance.GetPrefab("rk_egg")) from mat in rend.materials where mat.HasProperty("_MainTex") select mat) { item.SetTexture(Utils.MainTex, (Texture)(object)Main.newEggTexture); } ItemDrop itemDrop = ItemManager.Instance.GetItem("rk_egg").ItemDrop; itemDrop.m_itemData.m_shared.m_description = "A small egg."; itemDrop.m_itemData.m_shared.m_icons[0] = Main.newEggSprite; } catch (Exception ex) { Logger.LogError((object)("Error while loading SeagullEgg: " + ex.Message)); } finally { Logger.LogInfo((object)"SeagullEgg Loaded."); } } public static void Kabob() { CustomItem item = ItemManager.Instance.GetItem("rk_kabob"); if (Valharvest.Configurations.Valharvest.KabobName.Value) { item.ItemDrop.m_itemData.m_shared.m_name = "Kebab"; } } public static void Pizza() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) CustomItem item = ItemManager.Instance.GetItem("rk_pizza"); Color val = default(Color); Color val2 = default(Color); foreach (Renderer renderer in ShaderHelper.GetRenderers(PrefabManager.Instance.GetPrefab("rk_pizza"))) { string name = ((Object)renderer).name; if (!(name == "pizza")) { if (name == "Tarelka001") { Material[] materials = renderer.materials; foreach (Material obj in materials) { ColorUtility.TryParseHtmlString("#855B41", ref val); obj.SetTexture(Utils.MainTex, (Texture)(object)Main.pizzaPlateTexture); obj.SetColor(Utils.Color, val); } } } else { Material[] materials = renderer.materials; foreach (Material obj2 in materials) { ColorUtility.TryParseHtmlString("#FFFFFF", ref val2); obj2.SetColor(Utils.Color, val2); } } } item.ItemDrop.m_itemData.m_shared.m_icons[0] = Main.pizzaSprite; } } [HarmonyPatch] public static class BoneAppetitNotice { [CompilerGenerated] private static class <>O { public static PopupButtonCallback <0>__OnOk; } [CompilerGenerated] private sealed class d__4 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; private float 5__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__4(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown //IL_00b6: 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_00c1: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__2 = 0f; goto IL_0061; case 1: <>1__state = -1; 5__2 += 0.2f; goto IL_0061; case 2: { <>1__state = -1; break; } IL_0061: if (!UnifiedPopup.IsAvailable() && 5__2 < 10f) { <>2__current = (object)new WaitForSeconds(0.2f); <>1__state = 1; return true; } if (!UnifiedPopup.IsAvailable()) { return false; } break; } if (UnifiedPopup.IsVisible()) { <>2__current = null; <>1__state = 2; return true; } object obj = <>O.<0>__OnOk; if (obj == null) { PopupButtonCallback val = OnOk; <>O.<0>__OnOk = val; obj = (object)val; } UnifiedPopup.Push((PopupBase)new WarningPopup("$valharvest_ba_notice_title", "$valharvest_ba_notice_body", (PopupButtonCallback)obj, true)); return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private const float MaxWaitSeconds = 10f; private const float PollInterval = 0.2f; private static bool _shownThisSession; [HarmonyPostfix] [HarmonyPatch(typeof(FejdStartup), "Awake")] public static void FejdStartupAwakePostfix(FejdStartup __instance) { if (!_shownThisSession && BoneAppetitCompat.IsInstalled && !Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value && !Valharvest.Configurations.Valharvest.BoneAppetitNoticeShown.Value) { _shownThisSession = true; ((MonoBehaviour)__instance).StartCoroutine(ShowWhenAvailable()); } } [IteratorStateMachine(typeof(d__4))] private static IEnumerator ShowWhenAvailable() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__4(0); } private static void OnOk() { Valharvest.Configurations.Valharvest.BoneAppetitNoticeShown.Value = true; UnifiedPopup.Pop(); } } public static class ConsumableItemExtractor { private static HashSet GetValharvestPrefabNames() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) HashSet hashSet = new HashSet(); try { foreach (string key in ((JsonObject)SimpleJson.DeserializeObject(Utils.ReadEmbeddedFile("items.resources"))).Keys) { hashSet.Add(key); } } catch { } try { foreach (string key2 in ((JsonObject)SimpleJson.DeserializeObject(Utils.ReadEmbeddedFile("newFoodsConfig.resources"))).Keys) { hashSet.Add(key2); } } catch { } try { foreach (string key3 in ((JsonObject)SimpleJson.DeserializeObject(Utils.ReadEmbeddedFile("plants.resources"))).Keys) { hashSet.Add(key3); } } catch { } return hashSet; } public static void GenerateConsumableItemList() { Logger.LogInfo((object)"Starting item extraction..."); if (!Object.op_Implicit((Object)(object)ObjectDB.instance)) { Logger.LogError((object)"ObjectDB not available. Make sure you're in-game."); return; } JsonArray val = ExtractAllItems(); File.WriteAllText("itemdrops.json", ((object)val).ToString()); Logger.LogInfo((object)$"Wrote itemdrops.json with {((List)(object)val).Count} items"); JsonArray val2 = ExtractAllRecipes(); File.WriteAllText("recipes.json", ((object)val2).ToString()); Logger.LogInfo((object)$"Wrote recipes.json with {((List)(object)val2).Count} recipes"); Logger.LogInfo((object)"Item extraction complete!"); } private static JsonArray ExtractAllItems() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Expected I4, but got Unknown //IL_0661: Unknown result type (might be due to invalid IL or missing references) //IL_0679: Unknown result type (might be due to invalid IL or missing references) JsonArray val = new JsonArray(); HashSet hashSet = new HashSet(); HashSet valharvestPrefabNames = GetValharvestPrefabNames(); string text = "icons"; if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } int num = 0; foreach (ItemType value in Enum.GetValues(typeof(ItemType))) { foreach (ItemDrop allItem in ObjectDB.instance.GetAllItems(value, "")) { if ((Object)(object)allItem == (Object)null || allItem.m_itemData == null || allItem.m_itemData.m_shared == null) { continue; } string name = ((Object)((Component)allItem).gameObject).name; if (hashSet.Contains(name) || valharvestPrefabNames.Contains(name)) { continue; } hashSet.Add(name); JsonObject val3 = new JsonObject(); SharedData shared = allItem.m_itemData.m_shared; val3.Add("var_name", (object)(shared.m_name ?? "")); val3.Add("raw_name", (object)Localization.instance.Localize(shared.m_name ?? "")); val3.Add("true_name", (object)name); JsonObject val4 = new JsonObject(); val4.Add("raw_name", (object)Localization.instance.Localize(shared.m_name ?? "")); val4.Add("var_name", (object)(shared.m_name ?? "")); val4.Add("item_type_name", (object)((object)(ItemType)(ref shared.m_itemType)).ToString()); val4.Add("item_type", (object)(int)shared.m_itemType); val4.Add("description", (object)Localization.instance.Localize(shared.m_description ?? "")); val4.Add("prefab_name", (object)name); val4.Add("food", (object)shared.m_food); val4.Add("food_burn_time", (object)shared.m_foodBurnTime); val4.Add("food_regen", (object)shared.m_foodRegen); val4.Add("food_stamina", (object)shared.m_foodStamina); val4.Add("armor", (object)shared.m_armor); val4.Add("armor_per_level", (object)shared.m_armorPerLevel); val4.Add("attack_force", (object)shared.m_attackForce); val4.Add("backstab_bonus", (object)shared.m_backstabBonus); val4.Add("block_power", (object)shared.m_blockPower); val4.Add("block_power_per_level", (object)shared.m_blockPowerPerLevel); val4.Add("deflection_force", (object)shared.m_deflectionForce); val4.Add("deflection_force_per_level", (object)shared.m_deflectionForcePerLevel); val4.Add("ai_attack_interval", (object)shared.m_aiAttackInterval); val4.Add("ai_attack_max_angle", (object)shared.m_aiAttackMaxAngle); val4.Add("ai_attack_range", (object)shared.m_aiAttackRange); val4.Add("ai_attack_range_min", (object)shared.m_aiAttackRangeMin); val4.Add("ai_prioritized", (object)shared.m_aiPrioritized); val4.Add("ai_target_type", (object)((object)(AiTarget)(ref shared.m_aiTargetType)).ToString()); val4.Add("ai_when_flying", (object)shared.m_aiWhenFlying); val4.Add("ai_when_swiming", (object)shared.m_aiWhenSwiming); val4.Add("ai_when_walking", (object)shared.m_aiWhenWalking); val4.Add("animation_state", (object)((object)(AnimationState)(ref shared.m_animationState)).ToString()); val4.Add("blockable", (object)shared.m_blockable); val4.Add("can_be_reparied", (object)shared.m_canBeReparied); val4.Add("destroy_broken", (object)shared.m_destroyBroken); val4.Add("dodgeable", (object)shared.m_dodgeable); val4.Add("durability_drain", (object)shared.m_durabilityDrain); val4.Add("durability_per_level", (object)shared.m_durabilityPerLevel); val4.Add("equip_duration", (object)shared.m_equipDuration); val4.Add("helmet_hide_hair", (object)((object)(HelmetHairType)(ref shared.m_helmetHideHair)).ToString()); val4.Add("max_durability", (object)shared.m_maxDurability); val4.Add("max_quality", (object)shared.m_maxQuality); val4.Add("max_stack_size", (object)shared.m_maxStackSize); val4.Add("movement_modifier", (object)shared.m_movementModifier); val4.Add("quest_item", (object)shared.m_questItem); val4.Add("set_size", (object)shared.m_setSize); val4.Add("teleportable", (object)shared.m_teleportable); val4.Add("timed_block_bonus", (object)shared.m_timedBlockBonus); val4.Add("tool_tier", (object)shared.m_toolTier); val4.Add("use_durability", (object)shared.m_useDurability); val4.Add("use_durability_drain", (object)shared.m_useDurabilityDrain); val4.Add("value", (object)shared.m_value); val4.Add("variants", (object)shared.m_variants); val4.Add("weight", (object)shared.m_weight); val4.Add("ammo_type", (object)(shared.m_ammoType ?? "")); val4.Add("skill_type", (object)((object)(SkillType)(ref shared.m_skillType)).ToString()); val4.Add("damages", (object)ExtractDamageData(shared.m_damages)); val4.Add("damages_per_level", (object)ExtractDamageDataWithPrefix(shared.m_damagesPerLevel)); val4.Add("status_effects", (object)ExtractStatusEffects(shared)); val4.Add("set_name", (object)(shared.m_setName ?? "")); val4.Add("set_status_effect", (object)(((Object)(object)shared.m_setStatusEffect != (Object)null) ? ((Object)shared.m_setStatusEffect).name : "")); val4.Add("food_eitr", (object)shared.m_foodEitr); if (shared.m_icons != null && shared.m_icons.Length != 0 && (Object)(object)shared.m_icons[0] != (Object)null) { val4.Add("icon", (object)(name + ".png")); if (ExportItemIcon(shared, name, text)) { num++; } } val3.Add("shared_data", (object)val4); ((List)(object)val).Add((object)val3); } } Logger.LogInfo((object)$"Exported {num} icons to {text}/"); return val; } private static JsonArray ExtractAllRecipes() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Expected O, but got Unknown JsonArray val = new JsonArray(); HashSet valharvestPrefabNames = GetValharvestPrefabNames(); if (ObjectDB.instance.m_recipes == null) { return val; } foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe == (Object)null || (Object)(object)recipe.m_item == (Object)null) { continue; } string name = ((Object)((Component)recipe.m_item).gameObject).name; if (valharvestPrefabNames.Contains(name)) { continue; } JsonObject val2 = new JsonObject(); SharedData shared = recipe.m_item.m_itemData.m_shared; val2.Add("raw_name", (object)Localization.instance.Localize(shared.m_name ?? "")); val2.Add("var_name", (object)(shared.m_name ?? "")); val2.Add("true_name", (object)(((Object)recipe).name ?? "")); val2.Add("enabled", (object)recipe.m_enabled); val2.Add("min_station_level", (object)recipe.m_minStationLevel); val2.Add("amount", (object)recipe.m_amount); if ((Object)(object)recipe.m_craftingStation != (Object)null) { val2.Add("raw_crafting_station_name", (object)Localization.instance.Localize(recipe.m_craftingStation.m_name ?? "")); val2.Add("true_crafting_station_name", (object)(((Object)recipe.m_craftingStation).name ?? "")); } else { val2.Add("raw_crafting_station_name", (object)""); val2.Add("true_crafting_station_name", (object)""); } JsonArray val3 = new JsonArray(); if (recipe.m_resources != null) { Requirement[] resources = recipe.m_resources; foreach (Requirement val4 in resources) { if (val4 != null && !((Object)(object)val4.m_resItem == (Object)null)) { JsonObject val5 = new JsonObject(); SharedData shared2 = val4.m_resItem.m_itemData.m_shared; val5.Add("amount", (object)val4.m_amount); val5.Add("amount_per_level", (object)val4.m_amountPerLevel); val5.Add("raw_name", (object)Localization.instance.Localize(shared2.m_name ?? "")); val5.Add("var_name", (object)(shared2.m_name ?? "")); val5.Add("true_name", (object)(((Object)((Component)val4.m_resItem).gameObject).name ?? "")); val5.Add("recover", (object)val4.m_recover); ((List)(object)val3).Add((object)val5); } } } val2.Add("requirements", (object)val3); ((List)(object)val).Add((object)val2); } return val; } private static JsonObject ExtractDamageData(DamageTypes damages) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_0079: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Expected O, but got Unknown JsonObject val = new JsonObject(); val.Add("damage", (object)damages.m_damage); val.Add("blunt", (object)damages.m_blunt); val.Add("slash", (object)damages.m_slash); val.Add("pierce", (object)damages.m_pierce); val.Add("chop", (object)damages.m_chop); val.Add("pickaxe", (object)damages.m_pickaxe); val.Add("fire", (object)damages.m_fire); val.Add("frost", (object)damages.m_frost); val.Add("lightning", (object)damages.m_lightning); val.Add("poison", (object)damages.m_poison); val.Add("spirit", (object)damages.m_spirit); return val; } private static JsonObject ExtractDamageDataWithPrefix(DamageTypes damages) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_0079: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Expected O, but got Unknown JsonObject val = new JsonObject(); val.Add("m_damage", (object)damages.m_damage); val.Add("m_blunt", (object)damages.m_blunt); val.Add("m_slash", (object)damages.m_slash); val.Add("m_pierce", (object)damages.m_pierce); val.Add("m_chop", (object)damages.m_chop); val.Add("m_pickaxe", (object)damages.m_pickaxe); val.Add("m_fire", (object)damages.m_fire); val.Add("m_frost", (object)damages.m_frost); val.Add("m_lightning", (object)damages.m_lightning); val.Add("m_poison", (object)damages.m_poison); val.Add("m_spirit", (object)damages.m_spirit); return val; } private static JsonArray ExtractStatusEffects(SharedData shared) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown JsonArray val = new JsonArray(); if ((Object)(object)shared.m_attackStatusEffect != (Object)null) { ((List)(object)val).Add((object)((Object)shared.m_attackStatusEffect).name); } if ((Object)(object)shared.m_consumeStatusEffect != (Object)null) { ((List)(object)val).Add((object)((Object)shared.m_consumeStatusEffect).name); } if ((Object)(object)shared.m_equipStatusEffect != (Object)null) { ((List)(object)val).Add((object)((Object)shared.m_equipStatusEffect).name); } if ((Object)(object)shared.m_setStatusEffect != (Object)null) { ((List)(object)val).Add((object)((Object)shared.m_setStatusEffect).name); } return val; } private static bool ExportItemIcon(SharedData shared, string prefabName, string outputDir) { if (shared.m_icons == null || shared.m_icons.Length == 0) { return false; } Sprite val = shared.m_icons[0]; if ((Object)(object)val == (Object)null || (Object)(object)val.texture == (Object)null) { return false; } try { Texture2D val2 = MakeTextureReadable(val); if ((Object)(object)val2 == (Object)null) { return false; } byte[] bytes = ImageConversion.EncodeToPNG(val2); File.WriteAllBytes(Path.Combine(outputDir, prefabName + ".png"), bytes); Object.Destroy((Object)(object)val2); return true; } catch (Exception ex) { Logger.LogWarning((object)("Failed to export icon for " + prefabName + ": " + ex.Message)); return false; } } private static Texture2D MakeTextureReadable(Sprite sprite) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown Texture2D texture = sprite.texture; Rect textureRect = sprite.textureRect; RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0); Graphics.Blit((Texture)(object)texture, temporary); RenderTexture active = RenderTexture.active; RenderTexture.active = temporary; int num = Mathf.FloorToInt(((Rect)(ref textureRect)).x); int num2 = Mathf.FloorToInt(((Rect)(ref textureRect)).y); int num3 = Mathf.FloorToInt(((Rect)(ref textureRect)).width); int num4 = Mathf.FloorToInt(((Rect)(ref textureRect)).height); Texture2D val = new Texture2D(num3, num4, (TextureFormat)5, false); val.ReadPixels(new Rect((float)num, (float)num2, (float)num3, (float)num4), 0, 0); val.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); return val; } } public class ExportItemsCommand : ConsoleCommand { public override string Name => "exportitems"; public override string Help => "Exports all game items to itemdrops.json and recipes to recipes.json in the Valheim directory"; public override void Run(string[] args) { Logger.LogInfo((object)"Running exportitems command..."); ConsumableItemExtractor.GenerateConsumableItemList(); } } public class CultivatedGround : Heightmap { private void Awake() { } private void Update() { } private void OnEnable() { Regenerate(); } private void Regenerate() { Generate(); } private void Generate() { Initialize(); } public void Initialize() { //IL_004e: 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_005f: Expected O, but got Unknown int num = base.m_width + 1; int num2 = num * num; if (base.m_heights.Count != num2) { base.m_heights.Clear(); for (int i = 0; i < num2; i++) { base.m_heights.Add(0f); } base.m_paintMask = new Texture2D(base.m_width, base.m_width) { wrapMode = (TextureWrapMode)1 }; } } } [HarmonyPatch] public static class DeepFireCheckPatch { [HarmonyPatch(typeof(CraftingStation), "CheckFire")] private static class CheckFirePatch { private static bool Prefix(CraftingStation __instance, ref bool ___m_haveFire) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if (!IsTarget((Object)(object)__instance)) { return true; } GameObject haveFireObject = __instance.m_haveFireObject; Collider val = (((Object)(object)haveFireObject != (Object)null) ? haveFireObject.GetComponent() : null); bool flag; if ((Object)(object)val != (Object)null) { flag = HasBurningInVolume(val); } else { Vector3 val2 = (((Object)(object)haveFireObject != (Object)null) ? haveFireObject.transform.position : ((Component)__instance).transform.position); float num = ((Valharvest.Configurations.Valharvest.CookingPotFireCheckRadius != null) ? Valharvest.Configurations.Valharvest.CookingPotFireCheckRadius.Value : 0.5f); flag = (Object)(object)EffectArea.IsPointInsideArea(val2, (Type)8, num) != (Object)null; } ___m_haveFire = flag; if ((Object)(object)haveFireObject != (Object)null) { haveFireObject.SetActive(flag); } return false; } } private static int _characterTriggerMask; private static readonly Collider[] _hits = (Collider[])(object)new Collider[32]; private static int CharacterTriggerMask { get { if (_characterTriggerMask == 0) { _characterTriggerMask = LayerMask.GetMask(new string[1] { "character_trigger" }); } return _characterTriggerMask; } } private static bool IsTarget(Object instance) { if (instance != (Object)null && instance.name != null) { return instance.name.StartsWith("piece_cooking_pot"); } return false; } private static bool HasBurningInVolume(Collider volume) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0066: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)volume).transform; Vector3 lossyScale = transform.lossyScale; int num = 0; BoxCollider val = (BoxCollider)(object)((volume is BoxCollider) ? volume : null); if (val != null) { Vector3 val2 = transform.TransformPoint(val.center); Vector3 val3 = default(Vector3); ((Vector3)(ref val3))..ctor(Mathf.Abs(val.size.x * lossyScale.x) * 0.5f, Mathf.Abs(val.size.y * lossyScale.y) * 0.5f, Mathf.Abs(val.size.z * lossyScale.z) * 0.5f); num = Physics.OverlapBoxNonAlloc(val2, val3, _hits, transform.rotation, CharacterTriggerMask, (QueryTriggerInteraction)2); } else { SphereCollider val4 = (SphereCollider)(object)((volume is SphereCollider) ? volume : null); if (val4 != null) { Vector3 val5 = transform.TransformPoint(val4.center); float num2 = val4.radius * Mathf.Max(new float[3] { Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z) }); num = Physics.OverlapSphereNonAlloc(val5, num2, _hits, CharacterTriggerMask, (QueryTriggerInteraction)2); } else { CapsuleCollider val6 = (CapsuleCollider)(object)((volume is CapsuleCollider) ? volume : null); if (val6 != null) { Bounds bounds = ((Collider)val6).bounds; num = Physics.OverlapBoxNonAlloc(((Bounds)(ref bounds)).center, ((Bounds)(ref bounds)).extents, _hits, Quaternion.identity, CharacterTriggerMask, (QueryTriggerInteraction)2); } else { Bounds bounds2 = volume.bounds; num = Physics.OverlapBoxNonAlloc(((Bounds)(ref bounds2)).center, ((Bounds)(ref bounds2)).extents, _hits, Quaternion.identity, CharacterTriggerMask, (QueryTriggerInteraction)2); } } } for (int i = 0; i < num; i++) { EffectArea component = ((Component)_hits[i]).GetComponent(); if ((Object)(object)component != (Object)null && (component.m_type & 8) != 0) { return true; } } return false; } } [HarmonyPatch] public class EggAndFeatherDrop { [HarmonyPostfix] [HarmonyPatch(typeof(TreeBase), "SpawnLog")] public static void TreeBaseSpawnLog_Patch(TreeBase __instance) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) string name = ((Object)__instance.m_logPrefab).name; if (((IList)new string[6] { "PineTree_log", "PineTree_logOLD", "FirTree_log", "beech_log", "Birch_log", "Oak_log" }).Contains((object?)name) && Random.value < 0.15f) { GameObject prefab = ZNetScene.instance.GetPrefab("Feathers"); GameObject prefab2 = ZNetScene.instance.GetPrefab(BoneAppetitCompat.GetEggItem()); int num = Random.Range(1, 8); int num2 = Random.Range(1, 3); for (int i = 0; i < num; i++) { Object.Instantiate(prefab, ((Component)__instance).transform.position, Quaternion.identity); } for (int j = 0; j < num2; j++) { Object.Instantiate(prefab2, ((Component)__instance).transform.position, Quaternion.identity); } } } } public class FixPlantHealth : SlowUpdate { private const float GrowRadiusOverride = 0.4f; private const Biome BiomeOverride = 895; public override void Awake() { ((SlowUpdate)this).Awake(); } public override void SUpdate(float currentTime, Vector2i referenceZone) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) Plant component = ((Component)this).GetComponent(); Vector3 position = ((Component)this).transform.position; if (IsPlantValid(component, currentTime) && RaisedBed.CheckIfItemBellowIsCultivatedGround(position)) { ApplyPlantOverrides(component); } } private bool IsPlantValid(Plant plant, float currentTime) { if (plant.m_nview.IsValid()) { return currentTime <= plant.m_updateTime; } return false; } private void ApplyPlantOverrides(Plant plant) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) plant.m_tolerateHeat = true; plant.m_tolerateCold = true; plant.m_biome = (Biome)895; plant.m_growRadius = 0.4f; } } public class FoodCrate : MonoBehaviour { [CompilerGenerated] private sealed class d__14 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public FoodCrate <>4__this; private ZDO 5__2; private int 5__3; private int 5__4; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__14(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0120: 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_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) int num = <>1__state; FoodCrate foodCrate = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; <>2__current = null; <>1__state = 2; return true; case 2: <>1__state = -1; <>2__current = null; <>1__state = 3; return true; case 3: <>1__state = -1; if ((Object)(object)foodCrate._nview == (Object)null || !foodCrate._nview.IsValid() || !foodCrate._nview.IsOwner()) { return false; } 5__2 = foodCrate._nview.GetZDO(); if (5__2.GetBool("vh_grounded", false)) { return false; } 5__3 = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" }); 5__4 = 0; break; case 4: <>1__state = -1; 5__4++; break; } if (5__4 < 24) { Vector3 position = ((Component)foodCrate).transform.position; RaycastHit[] array = Physics.RaycastAll(position + Vector3.up * 0.1f, Vector3.down, 50f, 5__3); Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance)); float num2 = float.NaN; RaycastHit[] array2 = array; for (int i = 0; i < array2.Length; i++) { RaycastHit val = array2[i]; if (!((Object)(object)((Component)((RaycastHit)(ref val)).collider).transform.root == (Object)(object)((Component)foodCrate).transform)) { num2 = ((RaycastHit)(ref val)).point.y; break; } } if (!float.IsNaN(num2) && position.y - num2 > 0.05f) { position.y = num2; ((Component)foodCrate).transform.position = position; 5__2.SetPosition(position); } <>2__current = null; <>1__state = 4; return true; } 5__2.Set("vh_grounded", true); return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public const string VH_PILE_ITEM_KEY = "vh_pile_item"; public const string VH_MIGRATED_KEY = "vh_migrated"; private const string VH_GROUNDED_KEY = "vh_grounded"; private const string RPC_REFRESH = "VH_RefreshPile"; private const string MAT_PREFIX = "Pile"; private const float GroundSnapEpsilon = 0.05f; private const int GroundSettlePasses = 24; private static Dictionary _materialCache; private Container _container; private ZNetView _nview; private GameObject[] _piles; private void Awake() { _container = ((Component)this).GetComponent(); _nview = ((Component)this).GetComponent(); Transform val = ((Component)this).transform.Find("model"); if ((Object)(object)val != (Object)null) { GameObject[] array = new GameObject[4]; Transform obj = val.Find("pile_1_25"); array[0] = ((obj != null) ? ((Component)obj).gameObject : null); Transform obj2 = val.Find("pile_2_50"); array[1] = ((obj2 != null) ? ((Component)obj2).gameObject : null); Transform obj3 = val.Find("pile_3_75"); array[2] = ((obj3 != null) ? ((Component)obj3).gameObject : null); Transform obj4 = val.Find("pile_4_100"); array[3] = ((obj4 != null) ? ((Component)obj4).gameObject : null); _piles = (GameObject[])(object)array; } ZNetView nview = _nview; if (nview != null) { nview.Register("VH_RefreshPile", (Action)delegate { RefreshVisual(); }); } } private void Start() { if (_container?.m_inventory != null) { Inventory inventory = _container.m_inventory; inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(OnInventoryChanged)); } ((MonoBehaviour)this).StartCoroutine(GroundOnceDeferred()); RefreshVisual(); } private void OnDestroy() { if (_container?.m_inventory != null) { Inventory inventory = _container.m_inventory; inventory.m_onChanged = (Action)Delegate.Remove(inventory.m_onChanged, new Action(OnInventoryChanged)); } } [IteratorStateMachine(typeof(d__14))] private IEnumerator GroundOnceDeferred() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__14(0) { <>4__this = this }; } private void OnInventoryChanged() { if ((Object)(object)_nview == (Object)null || !_nview.IsValid() || !_nview.IsOwner()) { return; } List allItems = _container.m_inventory.GetAllItems(); ZDO zDO = _nview.GetZDO(); string @string = zDO.GetString("vh_pile_item", ""); if (allItems.Count == 0) { if (!string.IsNullOrEmpty(@string)) { zDO.Set("vh_pile_item", ""); } } else if (string.IsNullOrEmpty(@string)) { string text = ResolvePrefabName(allItems[0]); if (!string.IsNullOrEmpty(text)) { zDO.Set("vh_pile_item", text); } } _nview.InvokeRPC(ZNetView.Everybody, "VH_RefreshPile", Array.Empty()); } private void RefreshVisual() { if (_piles == null || _container?.m_inventory == null) { return; } for (int i = 0; i < _piles.Length; i++) { if ((Object)(object)_piles[i] != (Object)null) { _piles[i].SetActive(false); } } int count = _container.m_inventory.GetAllItems().Count; if (count == 0) { return; } int num = _container.m_inventory.GetWidth() * _container.m_inventory.GetHeight(); float num2 = ((num > 0) ? ((float)count / (float)num) : 0f); int num3 = ((!(num2 <= 0.25f)) ? ((num2 <= 0.5f) ? 1 : ((num2 <= 0.75f) ? 2 : 3)) : 0); GameObject val = _piles[num3]; if ((Object)(object)val == (Object)null) { return; } val.SetActive(true); Material pileMaterial = GetPileMaterial(((Object)(object)_nview != (Object)null && _nview.IsValid()) ? _nview.GetZDO().GetString("vh_pile_item", "") : ""); if (!((Object)(object)pileMaterial == (Object)null)) { Renderer component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.sharedMaterial = pileMaterial; } } } private static string ResolvePrefabName(ItemData item) { if ((Object)(object)item?.m_dropPrefab != (Object)null) { return ((Object)item.m_dropPrefab).name; } string text = item?.m_shared?.m_name; if (!string.IsNullOrEmpty(text) && text.StartsWith("$") && text.EndsWith("_name")) { return text.Substring(1, text.Length - "$_name".Length + 1); } return null; } private static Material GetPileMaterial(string itemPrefabName) { if (string.IsNullOrEmpty(itemPrefabName)) { return null; } if (_materialCache == null) { BuildCache(); } string key = "Pile" + char.ToUpper(itemPrefabName[0]) + itemPrefabName.Substring(1); _materialCache.TryGetValue(key, out var value); return value; } private static void BuildCache() { _materialCache = new Dictionary(StringComparer.OrdinalIgnoreCase); if ((Object)(object)Main.modAssets == (Object)null) { Logger.LogWarning((object)"[FoodCrate] modAssets is null; can't build pile material cache"); return; } Material[] array = Main.modAssets.LoadAllAssets(); foreach (Material val in array) { if (!((Object)(object)val == (Object)null) && ((Object)val).name.StartsWith("Pile")) { string key = ((Object)val).name.Split(new char[1] { '_' })[0]; _materialCache[key] = val; } } Logger.LogInfo((object)$"[FoodCrate] Cached {_materialCache.Count} pile materials"); } } [HarmonyPatch] public static class HandlePrefabComponent { [HarmonyPrefix] [HarmonyPatch(typeof(MonsterAI), "Awake")] public static void MonsterAIAwakePatch(MonsterAI __instance) { if (((Object)((Component)__instance).gameObject).name.Contains("Lox")) { ((Component)__instance).gameObject.AddComponent(); } } public static void ZNetViewAwakePatch() { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown GameObject prefab = PrefabManager.Instance.GetPrefab("water_well"); if (!Object.op_Implicit((Object)(object)prefab)) { return; } Transform val = prefab.gameObject.transform.Find("water"); Transform val2 = prefab.gameObject.transform.Find("spawnpoint"); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null) { CustomBeehive customBeehive = prefab.gameObject.AddComponent(); customBeehive.m_hideWhenPicked = ((Component)val).gameObject; customBeehive.m_spawnPoint = val2; customBeehive.m_honeyItem = PrefabManager.Instance.GetPrefab("water_bucket").GetComponent(); EffectList val3 = new EffectList(); if (val3.m_effectPrefabs.Length == 0) { val3.m_effectPrefabs = (EffectData[])(object)new EffectData[1]; } val3.m_effectPrefabs[0] = new EffectData { m_prefab = PrefabManager.Instance.GetPrefab("sfx_ship_waterimpact"), m_enabled = true }; customBeehive.m_spawnEffect = val3; } } public static void PrepTableSmokePatch() { if (Valharvest.Configurations.Valharvest.PrepTableSmokeEnabled.Value) { return; } GameObject prefab = PrefabManager.Instance.GetPrefab("piece_prep_table"); if (!((Object)(object)prefab == (Object)null)) { Transform val = prefab.transform.Find("connectionEffectPoint/prep/SmokeSpawner"); if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(false); } } } public static void FoodCrateEffectsPatch() { GameObject prefab = PrefabManager.Instance.GetPrefab("vh_piece_food_crate"); if (!((Object)(object)prefab == (Object)null)) { GameObject prefab2 = PrefabManager.Instance.GetPrefab("vfx_Place_wood_pole"); GameObject prefab3 = PrefabManager.Instance.GetPrefab("sfx_build_hammer_wood"); GameObject prefab4 = PrefabManager.Instance.GetPrefab("vfx_SawDust"); GameObject prefab5 = PrefabManager.Instance.GetPrefab("sfx_wood_hit"); GameObject prefab6 = PrefabManager.Instance.GetPrefab("vfx_SawDust"); GameObject prefab7 = PrefabManager.Instance.GetPrefab("sfx_wood_destroyed"); Piece component = prefab.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_placeEffect = BuildEffectList(prefab2, prefab3); } WearNTear component2 = prefab.GetComponent(); if ((Object)(object)component2 != (Object)null) { component2.m_hitEffect = BuildEffectList(prefab4, prefab5); component2.m_destroyedEffect = BuildEffectList(prefab6, prefab7); } } } private static EffectList BuildEffectList(params GameObject[] effects) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_0032: Expected O, but got Unknown List list = new List(); foreach (GameObject val in effects) { if (!((Object)(object)val == (Object)null)) { list.Add(new EffectData { m_prefab = val, m_enabled = true }); } } return new EffectList { m_effectPrefabs = list.ToArray() }; } } public class InteractFertilizer : MonoBehaviour, Interactable { private ZNetView _nview; private void Awake() { _nview = ((Component)this).gameObject.GetComponent(); } public bool Interact(Humanoid user, bool hold, bool alt) { return false; } public bool UseItem(Humanoid user, ItemData item) { Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); Plant component = ((Component)this).gameObject.GetComponent(); if (!SetPlantTime(component, item)) { return false; } inventory.RemoveOneItem(item); GrowPlant(component); return true; } private bool SetPlantTime(Plant plant, ItemData item) { bool num = ((Object)item.m_dropPrefab).name == "bonemeal"; bool flag = ((Object)item.m_dropPrefab).name == "water_bucket"; double num2 = plant.m_growTime; int num3 = (num ? 5 : 2); if (!num && !flag) { return false; } long @long = _nview.GetZDO().GetLong("plantTime", ZNet.instance.GetTime().Ticks); long num4 = (long)(num2 * 10000000.0 / (double)num3); long num5 = @long - num4; if (num5 < 0) { num5 = 0L; } _nview.GetZDO().Set("plantTime", num5); SendPlantEffect(plant); return true; } private static void SendPlantEffect(Plant plant) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) float num = Random.Range((float)((double)plant.m_minScale * 0.5), (float)((double)plant.m_maxScale * 0.5)); Quaternion val = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f); Main.boneMealVfx.Create(((Component)plant).transform.position, val, (Transform)null, num, -1); } public void GrowPlant(Plant plant) { //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Invalid comparison between Unknown and I4 //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Invalid comparison between Unknown and I4 //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Invalid comparison between Unknown and I4 //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Invalid comparison between Unknown and I4 //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Invalid comparison between Unknown and I4 if (plant.m_nview.IsValid()) { plant.m_updateTime = Time.time; double num = plant.TimeSincePlanted(); float growTime = plant.GetGrowTime(); if (Object.op_Implicit((Object)(object)plant.m_healthyGrown)) { bool flag = num > (double)growTime * 0.5; plant.m_healthy.SetActive(!flag && (int)plant.m_status == 0); plant.m_unhealthy.SetActive(!flag && (int)plant.m_status > 0); plant.m_healthyGrown.SetActive(flag && (int)plant.m_status == 0); plant.m_unhealthyGrown.SetActive(flag && (int)plant.m_status > 0); } else { plant.m_healthy.SetActive((int)plant.m_status == 0); plant.m_unhealthy.SetActive((int)plant.m_status > 0); } if (plant.m_nview.IsOwner() && !(num <= (double)growTime)) { plant.Grow(); } } } } public class LegacyBoxMigrator : MonoBehaviour { [CompilerGenerated] private sealed class d__4 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public LegacyBoxMigrator <>4__this; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__4(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) int num = <>1__state; LegacyBoxMigrator legacyBoxMigrator = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: { <>1__state = -1; if ((Object)(object)legacyBoxMigrator._nview == (Object)null || !legacyBoxMigrator._nview.IsValid() || !legacyBoxMigrator._nview.IsOwner()) { return false; } string prefabName = Utils.GetPrefabName(((Component)legacyBoxMigrator).gameObject); if (!BoxToItem.TryGetValue(prefabName, out var value)) { return false; } if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null) { return false; } GameObject prefab = ZNetScene.instance.GetPrefab("vh_piece_food_crate"); if ((Object)(object)prefab == (Object)null) { Logger.LogWarning((object)("[LegacyBoxMigrator] vh_piece_food_crate not found; skipping " + prefabName)); return false; } Quaternion val = Quaternion.Euler(0f, ((Component)legacyBoxMigrator).transform.eulerAngles.y, 0f); GameObject val2 = Object.Instantiate(prefab, ((Component)legacyBoxMigrator).transform.position, val); Container component = val2.GetComponent(); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(value); if ((Object)(object)component != (Object)null && (Object)(object)itemPrefab != (Object)null) { ItemDrop component2 = itemPrefab.GetComponent(); int num2 = ((!((Object)(object)component2 != (Object)null)) ? 1 : component2.m_itemData.m_quality); component.GetInventory().AddItem(value, 50, num2, 0, 0L, "", false); component.Save(); ZNetView component3 = val2.GetComponent(); ZDO val3 = ((component3 != null) ? component3.GetZDO() : null); if (val3 != null) { val3.Set("vh_pile_item", value); val3.Set("vh_migrated", true); } Logger.LogInfo((object)$"[LegacyBoxMigrator] {prefabName} -> vh_piece_food_crate ({value} x{50})"); } else { Logger.LogWarning((object)("[LegacyBoxMigrator] " + prefabName + ": missing Container or item prefab '" + value + "'")); } Piece component4 = val2.GetComponent(); if ((Object)(object)component4 != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null) { component4.SetCreator(Player.m_localPlayer.GetPlayerID()); } ZNetScene.instance.Destroy(((Component)legacyBoxMigrator).gameObject); return false; } } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private const int MigrateAmount = 50; private static readonly Dictionary BoxToItem = new Dictionary { { "piece_appleBox", "apple" }, { "piece_pepperBox", "pepper" }, { "piece_garlicBox", "garlic" }, { "piece_potatoBox", "potato" }, { "piece_saltBox", "salt" }, { "piece_tomatoBox", "tomato" } }; private ZNetView _nview; private void Awake() { _nview = ((Component)this).GetComponent(); if (!((Object)(object)_nview == (Object)null)) { ((MonoBehaviour)this).StartCoroutine(MigrateDeferred()); } } [IteratorStateMachine(typeof(d__4))] private IEnumerator MigrateDeferred() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__4(0) { <>4__this = this }; } } public static class Loaders { private static readonly string[] LegacyBoxes = new string[6] { "piece_appleBox", "piece_pepperBox", "piece_garlicBox", "piece_potatoBox", "piece_saltBox", "piece_tomatoBox" }; public static void LoadItems() { //IL_0073: Unknown result type (might be due to invalid IL or missing references) string text = Utils.ReadEmbeddedFile("items.resources"); if (text == null) { return; } foreach (KeyValuePair item in SimpleJson.DeserializeObject(text)) { Dictionary assetBundle = GetAssetBundle(); JsonObject val = SimpleJson.DeserializeObject(item.Value.ToString()); GameObject val2 = assetBundle[val["assetBundle"].ToString()].LoadAsset(item.Key); try { CustomItem val3 = (CustomItem)((val["crafting"] != null) ? ((object)CreateItemRecipe(val2, val)) : ((object)new CustomItem(val2, true))); SharedData shared = val3.ItemDrop.m_itemData.m_shared; SetItemDrop(val, shared); ItemManager.Instance.AddItem(val3); } catch (Exception ex) { Logger.LogError((object)("Error while loading " + item.Key + ": " + ex.Message)); } } } public static void LoadPieces() { string text = Utils.ReadEmbeddedFile("pieces.resources"); if (text == null) { return; } foreach (KeyValuePair item in SimpleJson.DeserializeObject(text)) { if (BoneAppetitCompat.IsInstalled && Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value) { string key = item.Key; if ((key == "piece_cooking_pot" || key == "piece_prep_table") ? true : false) { continue; } } if (Valharvest.Configurations.Valharvest.UseVanillaPrepTable.Value) { string key = item.Key; if ((key == "piece_prep_table" || key == "vh_piece_prep_table_ext1") ? true : false) { continue; } } Dictionary assetBundle = GetAssetBundle(); JsonObject val = SimpleJson.DeserializeObject(item.Value.ToString()); GameObject val2 = assetBundle[val["assetBundle"].ToString()].LoadAsset(item.Key); if (item.Key == "vh_piece_food_crate" && (Object)(object)val2.GetComponent() == (Object)null) { val2.AddComponent(); } bool flag = Array.IndexOf(LegacyBoxes, item.Key) >= 0; if (flag && (Object)(object)val2.GetComponent() == (Object)null) { val2.AddComponent(); } try { CustomPiece val3 = CreatePieceRecipe(val2, val, !flag); Piece piece = val3.Piece; SetPieceInfo(val, piece); PieceManager.Instance.AddPiece(val3); } catch (Exception ex) { Logger.LogError((object)("Error while loading " + item.Key + ": " + ex.Message)); } } Logger.LogInfo((object)"Loaded pieces"); } public static void LoadCookingStations() { if (BoneAppetitCompat.IsInstalled && !Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value) { PieceManager.Instance.RemovePiece("rk_prep"); PieceManager.Instance.RemovePiece("rk_griddle"); PieceManager.Instance.RemovePiece("rk_grill"); } } public static Dictionary GetAssetBundle() { return new Dictionary { { "valharvest", Main.modAssets } }; } public static void SetItemDrop(JsonObject content, SharedData itemDrop) { if (content["name"] != null) { itemDrop.m_name = content["name"].ToString(); } if (content["description"] != null) { itemDrop.m_description = content["description"].ToString(); } } public static void SetPieceInfo(JsonObject content, Piece piece) { if (content["name"] != null) { piece.m_name = content["name"].ToString(); } if (content["description"] != null) { piece.m_description = content["description"].ToString(); } } public static CustomItem CreateItemRecipe(GameObject itemPrefab, JsonObject itemObject) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown JsonObject val = SimpleJson.DeserializeObject(itemObject["crafting"].ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject(val["requirements"].ToString()); BoneAppetitCompat.RemapIngredients(requirements); string stationName = val["craftingStation"].ToString(); return new CustomItem(itemPrefab, true, new ItemConfig { Name = itemObject["name"].ToString(), Enabled = true, Amount = Convert.ToInt32(val["amount"].ToString()), CraftingStation = BoneAppetitCompat.GetCookingStation(stationName, Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value), Requirements = requirements }); } public static CustomPiece CreatePieceRecipe(GameObject piecePrefab, JsonObject pieceObject, bool enabled = true) { //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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown JsonObject val = SimpleJson.DeserializeObject(pieceObject["crafting"].ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject(val["requirements"].ToString()); PieceConfig val2 = new PieceConfig { Name = pieceObject["name"].ToString(), Enabled = enabled, AllowedInDungeons = (bool)val["allowedInDungeons"], PieceTable = val["pieceTable"].ToString(), CraftingStation = val["craftingStation"]?.ToString(), Requirements = requirements }; if (val.ContainsKey("extendStation")) { val2.ExtendStation = val["extendStation"].ToString(); } return new CustomPiece(piecePrefab, true, val2); } } [HarmonyPatch(typeof(Tameable), "Interact")] public static class InteractPatch { public static bool Prefix(Tameable __instance, ref bool __runOriginal) { if (!((((Object)((Component)__instance).gameObject).name == "Lox(Clone)") | ((Object)((Component)__instance).gameObject).name.Contains("Lox"))) { return __runOriginal = true; } if (!Input.GetKey((KeyCode)308)) { return __runOriginal = true; } __runOriginal = false; if (!__instance.m_nview.IsValid()) { return false; } MilkLox component = ((Component)__instance).gameObject.GetComponent(); if (component.GetMilkLevel() <= 0) { return __runOriginal = true; } CheckAbleToAddItem(component, component.loxPoint); return true; } private static void CheckAbleToAddItem(MilkLox loxComponent, Transform loxPoint) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = ((Humanoid)Player.m_localPlayer).m_inventory; int milkLevel = loxComponent.GetMilkLevel(); if (milkLevel <= 0) { return; } if (inventory.HaveEmptySlot()) { if (GetItemOnInventory("$empty_bottle_name") != null) { loxComponent.SpawnEffect.Create(loxPoint.position, Quaternion.identity, (Transform)null, 1f, -1); AddItemToPlayer(loxComponent, milkLevel); } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$piece_itemstand_missingitem", 0, (Sprite)null); } } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null); } } public static ItemData GetItemOnInventory(string name) { return ((IEnumerable)((Humanoid)Player.m_localPlayer).m_inventory.m_inventory).FirstOrDefault((Func)((ItemData item) => item.m_shared.m_name == name)); } private static void AddItemToPlayer(MilkLox loxComponent, int milkLevel) { Inventory inventory = ((Humanoid)Player.m_localPlayer).m_inventory; ItemData itemOnInventory = GetItemOnInventory("$empty_bottle_name"); int num = 0; for (int i = 0; i < milkLevel; i++) { if (inventory.HaveEmptySlot()) { if (itemOnInventory == null) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$piece_itemstand_missingitem", 0, (Sprite)null); break; } if (inventory.RemoveOneItem(itemOnInventory)) { loxComponent.nview.InvokeRPC("ExtractMilk", Array.Empty()); num++; } } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null); } } loxComponent.nview.InvokeRPC("ResetLevel", new object[1] { num }); } } [HarmonyPatch(typeof(Tameable), "GetHoverText")] public static class HoverTextPatch { public static void Postfix(ref string __result, Tameable __instance) { if (!((Object)(object)__instance.m_character == (Object)null) && __instance.m_character.IsTamed() && ((((Object)((Component)__instance).gameObject).name == "Lox(Clone)") | ((Object)((Component)__instance).gameObject).name.Contains("Lox"))) { int milkLevel = ((Component)__instance).gameObject.GetComponent().GetMilkLevel(); if (milkLevel > 0) { __result += Localization.instance.Localize("\n\nLox Milk ( $milk_bottle_name x " + milkLevel + " )\n[L-Alt + $KEY_Use] $lox_milk_extract"); } else { __result += Localization.instance.Localize("\n\nLox Milk ( $piece_container_empty )"); } } } } public class MilkLox : MonoBehaviour { private const int MaxMilk = 3; private const float SecPerUnit = 800f; public Transform loxPoint; [FormerlySerializedAs("_nview")] public ZNetView nview; private readonly CustomItem _milkBottleFab = ItemManager.Instance.GetItem("milk_bottle"); public readonly EffectList SpawnEffect = Main.loxMilkSfx; private void Awake() { nview = ((Component)this).GetComponent(); loxPoint = ((Component)this).transform; if (nview.GetZDO() != null) { if (nview.IsOwner() && nview.GetZDO().GetLong("lastMilkTime", 0L) == 0L) { nview.GetZDO().Set("lastMilkTime", ZNet.instance.GetTime().Ticks); } nview.Register("ExtractMilk", (Action)RPC_ExtractMilk); nview.Register("ResetLevel", (Action)RPC_ResetLevel); ((MonoBehaviour)this).InvokeRepeating("UpdateMilk", 0f, 10f); } } private void RPC_ExtractMilk(long caller) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_003a: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (nview.IsOwner()) { Vector2 val = Random.insideUnitCircle * 0.5f; Vector3 val2 = loxPoint.position + new Vector3(val.x, 0.25f, val.y); Object.Instantiate(_milkBottleFab.ItemDrop, val2, Quaternion.identity); } } private void RPC_ResetLevel(long caller, int level) { if (nview.IsOwner()) { int milkLevel = GetMilkLevel(); nview.GetZDO().Set("milkLevel", milkLevel - level); } } private float GetTimeSinceLastUpdate() { DateTime dateTime = new DateTime(nview.GetZDO().GetLong("lastMilkTime", ZNet.instance.GetTime().Ticks)); DateTime time = ZNet.instance.GetTime(); TimeSpan timeSpan = time - dateTime; nview.GetZDO().Set("lastMilkTime", time.Ticks); double num = timeSpan.TotalSeconds; if (num < 0.0) { num = 0.0; } return (float)num; } private void IncreaseLevel(int i) { int milkLevel = GetMilkLevel(); milkLevel += i; milkLevel = Mathf.Clamp(milkLevel, 0, 3); nview.GetZDO().Set("milkLevel", milkLevel); } public int GetMilkLevel() { return nview.GetZDO().GetInt("milkLevel", 0); } public void UpdateMilk() { if (nview.IsOwner()) { float timeSinceLastUpdate = GetTimeSinceLastUpdate(); float @float = nview.GetZDO().GetFloat("product", 0f); @float += timeSinceLastUpdate; if (@float > 800f) { int i = (int)(@float / 800f); IncreaseLevel(i); @float = 0f; } nview.GetZDO().Set("product", @float); } } } [HarmonyPatch] public static class PlantProgress { [HarmonyPatch(typeof(Pickable), "SetPicked")] public static class FixPickableTime { public class PickState { public bool picked; public long picked_time; } [HarmonyPrefix] public static void Prefix(bool picked, ZNetView ___m_nview, bool ___m_picked, ref PickState __state, Pickable __instance) { if (!((Object)((Component)__instance).gameObject).name.ToLower().Contains("vine") && !((Object)(object)___m_nview == (Object)null) && ___m_nview.GetZDO() != null) { __state = new PickState { picked_time = ___m_nview.GetZDO().GetLong(ZDOVars.s_pickedTime, 0L), picked = ___m_picked }; } } [HarmonyPostfix] public static void Postfix(bool picked, ZNetView ___m_nview, bool ___m_picked, ref PickState __state, Pickable __instance) { if (__state != null && !((Object)((Component)__instance).gameObject).name.ToLower().Contains("vine") && __state.picked == ___m_picked && (Object)(object)___m_nview != (Object)null && ___m_nview.GetZDO() != null) { ___m_nview.GetZDO().Set(ZDOVars.s_pickedTime, __state.picked_time); } } } private static readonly List PickableList = new List { "RaspberryBush(Clone)", "BlueberryBush(Clone)", "CloudberryBush(Clone)", "apple_tree(Clone)" }; private static string GetColour(double percentage) { if (percentage >= 25.0) { if (percentage <= 49.0) { return "orange"; } if (percentage >= 50.0) { if (percentage <= 74.0) { return "yellow"; } if (percentage >= 75.0 && percentage <= 100.0) { return "green"; } } } return "red"; } [HarmonyPostfix] [HarmonyPatch(typeof(Plant), "GetHoverText")] public static string PlantGetHoverText_Patch(string __result, Plant __instance) { if ((Object)(object)__instance == (Object)null) { return __result; } if (!Valharvest.Configurations.Valharvest.PlantProgressEnabled.Value) { return __result; } double num = Mathf.Floor((float)__instance.TimeSincePlanted() / __instance.GetGrowTime() * 100f); string colour = GetColour(num); string text = decimal.Round((decimal)num, 2, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture); string text2 = "" + text + "%"; return __result.Replace(" )", ", " + text2 + " )"); } [HarmonyPostfix] [HarmonyPatch(typeof(Pickable), "GetHoverText")] public static string BerryBushPickable_Patch(string __result, Pickable __instance) { if (!PickableList.Contains(((Object)__instance).name)) { return __result; } if (!Valharvest.Configurations.Valharvest.PickableProgressEnabled.Value) { return __result; } DateTime dateTime = new DateTime(__instance.m_nview.GetZDO().GetLong("picked_time", 0L)); double num = (ZNet.instance.GetTime() - dateTime).TotalMinutes / (double)__instance.m_respawnTimeMinutes * 100.0; if (num > 99.98999786376953) { return __result; } string colour = GetColour(num); string text = decimal.Round((decimal)num, 2).ToString(CultureInfo.InvariantCulture); string text2 = "" + text + "%"; return __result + " " + Localization.instance.Localize(__instance.GetHoverName()) + " ( " + text2 + " )"; } } public static class PrepTableRecipeCopier { private static bool _redirected; public static void CopyVanillaPrepTableRecipes() { if (_redirected) { return; } if (BoneAppetitCompat.IsInstalled && Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value) { Logger.LogInfo((object)"PrepTableRecipeCopier: Skipped (using BoneAppetit stations)"); PrefabManager.OnPrefabsRegistered -= CopyVanillaPrepTableRecipes; return; } if (Valharvest.Configurations.Valharvest.UseVanillaPrepTable.Value) { Logger.LogInfo((object)"PrepTableRecipeCopier: Skipped (using vanilla prep table)"); PrefabManager.OnPrefabsRegistered -= CopyVanillaPrepTableRecipes; return; } GameObject prefab = PrefabManager.Instance.GetPrefab("piece_preptable"); GameObject prefab2 = PrefabManager.Instance.GetPrefab("piece_prep_table"); if ((Object)(object)prefab == (Object)null || (Object)(object)prefab2 == (Object)null) { Logger.LogWarning((object)"PrepTableRecipeCopier: Could not find prep table prefabs"); PrefabManager.OnPrefabsRegistered -= CopyVanillaPrepTableRecipes; return; } CraftingStation component = prefab.GetComponent(); CraftingStation component2 = prefab2.GetComponent(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null) { Logger.LogWarning((object)"PrepTableRecipeCopier: Missing CraftingStation component"); PrefabManager.OnPrefabsRegistered -= CopyVanillaPrepTableRecipes; return; } int num = 0; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (!((Object)(object)recipe == (Object)null) && !((Object)(object)recipe.m_craftingStation != (Object)(object)component)) { recipe.m_craftingStation = component2; recipe.m_minStationLevel = 2; num++; } } _redirected = true; Logger.LogInfo((object)$"PrepTableRecipeCopier: Redirected {num} recipes to custom prep table"); PrefabManager.OnPrefabsRegistered -= CopyVanillaPrepTableRecipes; } } [HarmonyPatch] public class RaisedBed { private static readonly string[] PlantsArray = new string[15] { "Pickable_Barley", "Pickable_Carrot", "Pickable_Dandelion", "Pickable_Flax", "Pickable_Mushroom", "Pickable_Mushroom_blue", "Pickable_Mushroom_yellow", "Pickable_Onion", "Pickable_SeedCarrot", "Pickable_SeedOnion", "Pickable_SeedTurnip", "Pickable_Thistle", "Pickable_Turnip", "Pickable_Mushroom_Magecap", "Pickable_Mushroom_JotunPuffs" }; private static readonly Collider[] pieceColliders = (Collider[])(object)new Collider[2000]; private static bool massPlanting = true; private static readonly List m_tempPieces = new List(); private static readonly List m_tempSnapPoints1 = new List(); private static readonly List m_tempSnapPoints2 = new List(); [HarmonyPostfix] [HarmonyPriority(0)] [HarmonyAfter(new string[] { "mod.valheim_plus", "org.bepinex.plugins.farming", "com.odinplusqol.mod", "BepIn.Sarcen.Fa rmGrid", "Harmony.Sarcen.FarmGrid", "infinity_hammer", "org.bepinex.plugins.conversionsizespeed" })] [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] private static void UpdatePlacementGrid(Player __instance, bool flashGuardStone) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) GameObject placementGhost = __instance.m_placementGhost; if ((Object)(object)placementGhost == (Object)null) { return; } Plant component = placementGhost.GetComponent(); Piece component2 = placementGhost.GetComponent(); if ((Object)(object)component == (Object)null) { return; } if (Main.IsFarmingModInstalled) { KeyboardShortcut massPlantShortcut = Main.MassPlantShortcut; if (((KeyboardShortcut)(ref massPlantShortcut)).IsDown()) { massPlanting = !massPlanting; } } if (!IsPlantPlantable((Component)(object)component)) { return; } float cultivatedGroundHeight = GetCultivatedGroundHeight((Component)(object)component, __instance); Vector3 position = placementGhost.transform.position; component2.SetInvalidPlacementHeightlight(false); __instance.m_placementStatus = (PlacementStatus)0; if (Main.IsFarmingModInstalled) { KeyboardShortcut massPlantShortcut2 = Main.MassPlantShortcut; if (massPlanting) { component2.SetInvalidPlacementHeightlight(true); __instance.m_placementStatus = (PlacementStatus)1; string text = Localization.instance.Localize("$msg_TurnMassPlantingOff"); ((Character)__instance).Message((MessageType)2, text + ((object)(KeyboardShortcut)(ref massPlantShortcut2)).ToString() + " key", 0, (Sprite)null); } } Vector3 position2 = default(Vector3); ((Vector3)(ref position2))..ctor(position.x, cultivatedGroundHeight, position.z); placementGhost.transform.position = position2; if (GetClosestSnapPoints((Component)(object)placementGhost.transform, 0.5f, out var a, out var b, __instance, ((Component)component).transform)) { Vector3 position3 = b.position - (a.position - placementGhost.transform.position); if (!IsPlantOverlapping((Component)(object)component)) { placementGhost.transform.position = position3; return; } component2.SetInvalidPlacementHeightlight(true); __instance.m_placementStatus = (PlacementStatus)1; } } private static bool GetClosestSnapPoints(Component ghost, float maxSnapDistance, out Transform a, out Transform b, Player player, Transform plant) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) m_tempSnapPoints1.Clear(); m_tempSnapPoints1.Add(plant); m_tempSnapPoints2.Clear(); m_tempPieces.Clear(); GetSnapPoints(ghost.transform.position, 10f, m_tempSnapPoints2, m_tempPieces); float num = 9999999f; a = null; b = null; Transform val = default(Transform); float num2 = default(float); foreach (Transform item in m_tempSnapPoints1) { if (player.FindClosestSnappoint(item.position, m_tempSnapPoints2, maxSnapDistance, ref val, ref num2) && num2 < num) { num = num2; a = item; b = val; } } return (Object)(object)a != (Object)null; } private static bool IsPlantOverlapping(Component plant) { //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_000e: Unknown result type (might be due to invalid IL or missing references) Bounds bounds = plant.GetComponent().bounds; int num = Physics.OverlapSphereNonAlloc(((Bounds)(ref bounds)).center, 0.2f, pieceColliders); for (int i = 0; i < num; i++) { Collider val = pieceColliders[i]; if (!((Object)(object)val == (Object)null) && !(((Object)val).name == ((Object)plant).name) && !((Object)(object)((Component)val).gameObject.GetComponent() == (Object)null)) { return true; } } return false; } private static void GetSnapPoints(Vector3 point, float radius, ICollection points, ICollection pieces) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (Piece.s_pieceRayMask == 0) { Piece.s_pieceRayMask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" }); } int num = Physics.OverlapSphereNonAlloc(point, radius, pieceColliders, Piece.s_pieceRayMask); for (int i = 0; i < num; i++) { Piece componentInParent = ((Component)pieceColliders[i]).GetComponentInParent(); if (!((Object)(object)componentInParent == (Object)null) && ((Object)componentInParent).name.Contains("cultivatedGround")) { GetSnapPoints(points, (Component)(object)componentInParent); pieces.Add(componentInParent); } } } private static void GetSnapPoints(ICollection points, Component piece) { for (int i = 0; i < piece.transform.childCount; i++) { Transform child = piece.transform.GetChild(i); if (((Object)child).name.Contains("_snapplant")) { points.Add(child); } } } private static float GetCultivatedGroundHeight(Component plant, Player player) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) Vector3 position = plant.transform.position; Piece hoveringPiece = player.m_hoveringPiece; if ((Object)(object)hoveringPiece == (Object)null) { return position.y; } if (((Object)hoveringPiece).name.Contains("cultivatedGround")) { return ((Component)((Component)hoveringPiece).GetComponentInChildren()).transform.position.y; } Vector3 position2 = ((Component)hoveringPiece).transform.position; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(position2.x, position2.y + 3f, position2.z); RaycastHit val2 = ((IEnumerable)(from x in Physics.RaycastAll(new Ray(val, Vector3.down)) orderby Vector3.Distance(((RaycastHit)(ref x)).point, position) select x)).FirstOrDefault((Func)((RaycastHit x) => ((Object)((Component)((RaycastHit)(ref x)).collider).gameObject).name == "Cultivated_ground_piece")); if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null)) { return ((RaycastHit)(ref val2)).point.y; } return position.y; } [HarmonyPrefix] [HarmonyPatch(typeof(Piece), "Awake")] private static void SetFakeComponent(Piece __instance) { Collider[] componentsInChildren = ((Component)((Component)__instance).transform).GetComponentsInChildren(); foreach (Collider val in componentsInChildren) { if (((Object)((Component)val).gameObject).name == "Cultivated_ground_piece") { ((Component)val).gameObject.AddComponent(); } } } [HarmonyPostfix] [HarmonyPriority(0)] [HarmonyPatch(typeof(Heightmap), "IsCultivated")] private static bool PatchIsCultivated(bool __result, Vector3 worldPos) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Plant.m_roofMask = 0; Plant.m_spaceMask = 0; if (!CheckIfItemBellowIsCultivatedGround(worldPos)) { return __result; } Plant.m_roofMask = LayerMask.GetMask(new string[1] { "" }); Plant.m_spaceMask = LayerMask.GetMask(new string[2] { "Default", "piece_nonsolid" }); return true; } private static bool IsPlantPlantable(Component plant) { //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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Vector3 position = plant.transform.position; return CheckIfItemBellowIsCultivatedGround(new Vector3(position.x, position.y + 1f, position.z)); } public static bool CheckIfItemBellowIsCultivatedGround(Vector3 position) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) int mask = LayerMask.GetMask(new string[1] { "piece" }); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(position.x, position.y + 100f, position.z); return Physics.RaycastAll(new Ray(val, Vector3.down), 1000f, mask).Any((RaycastHit hit) => ((Object)((Component)((RaycastHit)(ref hit)).collider).gameObject).name == "Cultivated_ground_piece"); } [HarmonyPrefix] [HarmonyPatch(typeof(Pickable), "Awake")] public static void FixPlantPhysics(Pickable __instance) { if (PlantsArray.Any(((Object)__instance).name.Contains)) { StaticPhysics component = ((Component)__instance).gameObject.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_checkSolids = true; } } } [HarmonyPrefix] [HarmonyPriority(0)] [HarmonyAfter(new string[] { "mod.valheim_plus", "org.bepinex.plugins.farming", "com.odinplusqol.mod", "BepIn.Sarcen.FarmGrid", "Harmony.Sarcen.FarmGrid" })] [HarmonyPatch(typeof(Plant), "Awake")] public static void FixPlantHealth(Plant __instance) { ((Component)__instance).gameObject.AddComponent(); } } [HarmonyPatch] public static class ReturnEmptyBottle { [HarmonyPatch(typeof(Player), "ConsumeResources")] private static class ConsumeResourcesPatch { private static bool Prefix(Player __instance, IEnumerable requirements, int qualityLevel) { foreach (Requirement requirement in requirements) { if (!Object.op_Implicit((Object)(object)requirement.m_resItem)) { continue; } int amount = requirement.GetAmount(qualityLevel); if (amount > 0 && !(requirement.m_resItem.m_itemData.m_shared.m_name != "$milk_bottle_name")) { Inventory inventory = ((Humanoid)__instance).GetInventory(); ItemData itemOnInventory = InteractPatch.GetItemOnInventory("$empty_bottle_name"); if (inventory.HaveEmptySlot()) { AddEmptyMilkBottle(__instance, qualityLevel, inventory, amount); return true; } if (itemOnInventory != null && inventory.CanAddItem(itemOnInventory, amount)) { AddEmptyMilkBottle(__instance, qualityLevel, inventory, amount); return true; } ((Character)__instance).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null); return true; } } return true; } private static void AddEmptyMilkBottle(Player instance, int qualityLevel, Inventory inventory, int totalRequirement) { inventory.AddItem("empty_bottle", totalRequirement, qualityLevel, 0, 0L, instance.GetPlayerName(), false); } } [HarmonyPatch(typeof(Player), "RemovePiece")] private static class RemovePiecePatch { public static bool Prefix(Player __instance, ref bool __runOriginal) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_003f: Unknown result type (might be due to invalid IL or missing references) RaycastHit val = default(RaycastHit); if (!Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, __instance.m_removeRayMask) || !(Vector3.Distance(((RaycastHit)(ref val)).point, ((Character)__instance).m_eye.position) < __instance.m_maxPlaceDistance)) { return __runOriginal; } Piece componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null || componentInParent.m_name != "$piece_milk_can_name") { return __runOriginal; } Requirement[] resources = componentInParent.m_resources; foreach (Requirement val2 in resources) { if (Object.op_Implicit((Object)(object)val2.m_resItem) && !(val2.m_resItem.m_itemData.m_shared.m_name != "$milk_bottle_name")) { Inventory inventory = ((Humanoid)__instance).GetInventory(); ItemData itemOnInventory = InteractPatch.GetItemOnInventory("$empty_bottle_name"); if (itemOnInventory == null) { ((Character)__instance).Message((MessageType)2, "$msg_donthaveany $empty_bottle_name", 0, (Sprite)null); __runOriginal = false; return false; } int amount = val2.GetAmount(0); int num = inventory.CountItems(itemOnInventory.m_shared.m_name, -1, true); if (num < amount) { ((Character)__instance).Message((MessageType)2, $"$enough_empty_bottle. Need {amount - num} more.", 0, (Sprite)null); __runOriginal = false; return false; } inventory.RemoveItem(itemOnInventory.m_shared.m_name, amount, -1, true); } } return __runOriginal = true; } } } [HarmonyPatch] public static class SaltDrop { [HarmonyPatch(typeof(DropOnDestroyed), "OnDestroyed")] public static class DropOnDestroyedOnDestroyedPatch { [HarmonyPrefix] private static void Prefix(ref DropOnDestroyed __instance) { _dropTableObject = ((Object)((Component)__instance).gameObject).name; } [HarmonyPostfix] private static void Postfix(ref DropOnDestroyed __instance) { _dropTableObject = ""; } } private static string _dropTableObject = ""; [HarmonyPostfix] [HarmonyPatch(typeof(DropTable), "GetDropList", new Type[] { })] public static void DropTableGetDropList_Patch(ref List __result) { if ((Environment.StackTrace.Contains("MineRock") || (Environment.StackTrace.Contains("DropOnDestroyed") && _dropTableObject.Contains("Rock"))) && (double)Random.value < (double)Valharvest.Configurations.Valharvest.SaltDropPercentage.Value / 100.0) { GameObject prefab = ZNetScene.instance.GetPrefab("salt"); __result.Add(prefab); } } } [HarmonyPatch] public class UseFertilizer { private static readonly string[] PickableArray = new string[2] { "Thistle", "apple" }; [HarmonyPrefix] [HarmonyPatch(typeof(Plant), "Awake")] public static void AddPlantFertilizer(Plant __instance) { ((Component)__instance).gameObject.AddComponent(); } [HarmonyPrefix] [HarmonyPatch(typeof(Pickable), "UseItem")] private static bool AddThistleFertilizer(Pickable __instance, ref bool __result, Humanoid user, ItemData item) { __result = true; if (!PickableArray.Any(((Object)__instance).name.Contains)) { return true; } if (!IsPickablePickable(__instance)) { return true; } Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory(); if (!SetPickableTime(__instance, item)) { return false; } inventory.RemoveOneItem(item); GrowPickable(__instance); return false; } private static bool SetPickableTime(Pickable pickable, ItemData item) { ZNetView nview = pickable.m_nview; bool num = ((Object)item.m_dropPrefab).name == "bonemeal"; bool flag = ((Object)item.m_dropPrefab).name == "water_bucket"; double num2 = pickable.m_respawnTimeMinutes; int num3 = (num ? 8 : 4); if (!num && !flag) { return false; } long @long = nview.GetZDO().GetLong(ZDOVars.s_pickedTime, ZNet.instance.GetTime().Ticks); long num4 = (long)(num2 * 60.0 * 10000000.0 / (double)num3); long num5 = @long - num4; if (num5 < 0) { num5 = 0L; } nview.GetZDO().Set("picked_time", num5); SendPickableEffect(pickable); return true; } private static void SendPickableEffect(Pickable pickable) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) float num = Random.Range(0.5f, 0.5f); Quaternion val = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f); Main.boneMealVfx.Create(((Component)pickable).transform.position, val, (Transform)null, num, -1); } private static bool IsPickablePickable(Pickable pickable) { ZNetView nview = pickable.m_nview; if (!nview.IsValid()) { return false; } DateTime dateTime = new DateTime(nview.GetZDO().GetLong(ZDOVars.s_pickedTime, 0L)); return (ZNet.instance.GetTime() - dateTime).TotalMinutes <= (double)pickable.m_respawnTimeMinutes; } private static void GrowPickable(Pickable pickable) { if (!IsPickablePickable(pickable)) { pickable.SetPicked(false); } } } public static class Vector3Ext { public static Vector3 xz(this Vector3 v) { //IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.x, 0f, v.z); } } } namespace Valharvest.Configurations { public class Valharvest { public static ConfigEntry KabobName; public static ConfigEntry DropEnabled; public static ConfigEntry AppleDropAmount; public static ConfigEntry AppleRespawnTime; public static ConfigEntry SaltDropPercentage; public static ConfigEntry PlantProgressEnabled; public static ConfigEntry PickableProgressEnabled; public static ConfigEntry UseBoneAppetitCookingStations; public static ConfigEntry UseVanillaPrepTable; public static ConfigEntry PrepTableSmokeEnabled; public static ConfigEntry CookingPotFireCheckRadius; public static ConfigEntry BoneAppetitNoticeShown; public ConfigEntry GarlicChance; public ConfigEntry PepperChance; public ConfigEntry RiceChance; public static Dictionary> GetDropConfigs() { return new Dictionary> { { "AppleDropAmount", AppleDropAmount } }; } public static Dictionary> GetRespawnTimeConfigs() { return new Dictionary> { { "AppleRespawnTime", AppleRespawnTime } }; } internal Valharvest(ConfigFile config) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //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_0063: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_008c: 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_0099: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_00f8: 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_0105: Expected O, but got Unknown //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Expected O, but got Unknown //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Expected O, but got Unknown //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Expected O, but got Unknown //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Expected O, but got Unknown //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Expected O, but got Unknown //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Expected O, but got Unknown //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Expected O, but got Unknown //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Expected O, but got Unknown //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Expected O, but got Unknown KabobName = config.Bind("Kabob", "Enable", true, new ConfigDescription("Change Kabob name to Kebab", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); DropEnabled = config.Bind("Vegetables Drop", "Enable", false, new ConfigDescription("Keep vegetables in monster drops", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); PlantProgressEnabled = config.Bind("Plant Progress", "EnableOnPlants", true, new ConfigDescription("Enable showing plant growth progress on plants", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); PickableProgressEnabled = config.Bind("Plant Progress", "EnableOnPickable", true, new ConfigDescription("Enable showing plant growth progress on pickable", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); AppleDropAmount = config.Bind("Drop Amount", "AppleQuantity", 1, new ConfigDescription("Amount of drop Apple from apple tree", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); AppleRespawnTime = config.Bind("Respawn Time", "AppleRespawnTime", 5, new ConfigDescription("Time in hours for apple tree to respawn apples", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); SaltDropPercentage = config.Bind("Salt", "Enable", 35, new ConfigDescription("Chance of drop Salt", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); UseBoneAppetitCookingStations = config.Bind("Bone Appetit", "UseBoneAppetitCookingStations", false, new ConfigDescription("When BoneAppetit is installed, use its cooking stations instead of Valharvest's. Has no effect if BoneAppetit is not installed.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); UseVanillaPrepTable = config.Bind("Cooking Stations", "UseVanillaPrepTable", false, new ConfigDescription("Use vanilla prep table (piece_preptable) instead of Valharvest's custom table. When enabled, all Valharvest recipes will be added to the vanilla prep table and the custom prep table will not be available.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); PrepTableSmokeEnabled = config.Bind("Cooking Stations", "PrepTableSmoke", true, new ConfigDescription("Enable smoke effects on the preparation table", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); CookingPotFireCheckRadius = config.Bind("Cooking Stations", "CookingPotFireCheckRadius", 0.5f, new ConfigDescription("Overlap-sphere radius used to detect fire under piece_cooking_pot. The detection origin is the FireCheckPoint child (move it in the prefab to control depth). Vanilla uses 0.25.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); BoneAppetitNoticeShown = config.Bind("Bone Appetit", "NoticeShown", false, new ConfigDescription("Internal flag: tracks whether the one-time BoneAppetit cooking-stations notice has already been dismissed by the user.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { Browsable = false } })); } } }