Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Valharvest v3.2.2
plugins/Valharvest.dll
Decompiled a week ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.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 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("3.2.2.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("3.2.2.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<ZNetView>(); 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<long>)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[<color=yellow><b>$KEY_Use</b></color>] $water_well_extract"); } return Localization.instance.Localize(m_name + " ( $piece_container_empty )\n[<color=yellow><b>$KEY_Use</b></color>] $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<object>()); } 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<ItemDrop>(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<Type, int> typeDict, Dictionary<string, int> getMatItem) { material.shader = shader; foreach (KeyValuePair<string, object> item in content) { if (!(item.Key == "shader")) { SetMaterialConfigItems(typeDict, item, material, getMatItem); } } } private static void SetMaterialConfigItems(Dictionary<Type, int> typeDict, KeyValuePair<string, object> materialItem, Material material, Dictionary<string, int> 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<Type, int> GetTypeDict() { return new Dictionary<Type, int> { { typeof(long), 0 }, { typeof(string), 1 }, { typeof(double), 2 } }; } public static Dictionary<string, int> GetMatItem() { return new Dictionary<string, int> { { "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<JsonObject>(SimpleJson.DeserializeObject<JsonObject>(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<string, object> item in SimpleJson.DeserializeObject<JsonObject>(new StreamReader(stream).ReadToEnd())) { string key = item.Key; JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject<RequirementConfig[]>(val["requirements"].ToString()); BoneAppetitCompat.RemapIngredients(requirements); CustomItem val2 = null; try { val2 = new CustomItem(Main.modAssets.LoadAsset<GameObject>(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<string, object> item in SimpleJson.DeserializeObject<JsonObject>(new StreamReader(stream).ReadToEnd())) { string key = item.Key; JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject<RequirementConfig[]>(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<JsonObject>(SimpleJson.DeserializeObject<JsonObject>(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<StatusEffect>(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.2.2")] [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.2.2"; 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_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: 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 += 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<KeyValuePair<string, PluginInfo>> enumerator = Chainloader.PluginInfos.Where((KeyValuePair<string, PluginInfo> 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<KeyCode>()); } } } 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<Texture2D>("egg"); newEggSprite = modAssets.LoadAsset<Sprite>("eggsprite"); pizzaPlateTexture = modAssets.LoadAsset<Texture2D>("pizza_plate"); pizzaSprite = modAssets.LoadAsset<Sprite>("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<GameObject>("sfx_pours_milk"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true)); GameObject val2 = modAssets.LoadAsset<GameObject>("sfx_lox_pet_milk"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true)); GameObject val3 = modAssets.LoadAsset<GameObject>("sfx_lox_pet"); PrefabManager.Instance.AddPrefab(new CustomPrefab(val3, true)); GameObject val4 = modAssets.LoadAsset<GameObject>("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<CharacterDrop>().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<CharacterDrop>().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<CharacterDrop>().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<CharacterDrop>().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<CharacterDrop>().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<CharacterDrop>().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<DropOnDestroyed>(); 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<MonsterAI>(); foreach (string text in items) { GameObject prefab = PrefabManager.Instance.GetPrefab(text); component.m_consumeItems.Add(prefab.GetComponent<ItemDrop>()); } } 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<string, object> item in SimpleJson.DeserializeObject<JsonObject>(text)) { GameObject val = PrefabManager.Instance.CreateClonedPrefab(item.Key + "_wild", item.Key); JsonObject content = SimpleJson.DeserializeObject<JsonObject>(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<string, Biome> biome = GetBiome(); Dictionary<string, BiomeArea> 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<string, Biome> GetBiome() { return new Dictionary<string, Biome> { { "swamp", (Biome)2 }, { "plains", (Biome)16 }, { "meadows", (Biome)1 }, { "mountain", (Biome)4 }, { "mistlands", (Biome)512 }, { "black_forest", (Biome)8 } }; } private static Dictionary<string, BiomeArea> GetBiomeArea() { return new Dictionary<string, BiomeArea> { { "edge", (BiomeArea)1 }, { "median", (BiomeArea)2 }, { "everything", (BiomeArea)3 } }; } } public static class PlantUtils { public static void AddCustomPlantsPrefab() { //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown string text = Utils.ReadEmbeddedFile("plants.resources"); if (text == null) { return; } foreach (KeyValuePair<string, object> item in SimpleJson.DeserializeObject<JsonObject>(text)) { Dictionary<string, AssetBundle> assetBundle = Loaders.GetAssetBundle(); JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString()); string key = val["assetBundle"].ToString(); object obj = val["dropConfig"]; object obj2 = val["respawnConfig"]; Dictionary<string, ConfigEntry<int>> dropConfigs = Valharvest.Configurations.Valharvest.GetDropConfigs(); Dictionary<string, ConfigEntry<int>> respawnTimeConfigs = Valharvest.Configurations.Valharvest.GetRespawnTimeConfigs(); GameObject val2 = assetBundle[key].LoadAsset<GameObject>(item.Key); LoadPlantMaterials(val2, val); try { if (obj != null) { ConfigEntry<int> val3 = dropConfigs[obj.ToString()]; val2.GetComponent<Pickable>().m_amount = val3.Value; } if (obj2 != null) { ConfigEntry<int> val4 = respawnTimeConfigs[obj2.ToString()]; val2.GetComponent<Pickable>().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<JsonObject>(plantObject["materials"].ToString()); foreach (Renderer renderer in ShaderHelper.GetRenderers(plantPrefab)) { Material[] materials = renderer.materials; foreach (Material val2 in materials) { string name = ((Object)val2).name; string text = name.Substring(0, name.Length - " (Instance)".Length); if (val.ContainsKey(text) && !string.IsNullOrEmpty(val[text].ToString())) { Dictionary<Type, int> typeDict = Utils.GetTypeDict(); Dictionary<string, int> matItem = Utils.GetMatItem(); JsonObject val3 = SimpleJson.DeserializeObject<JsonObject>(val[text].ToString()); Shader prefab = Cache.GetPrefab<Shader>(val3["shader"].ToString()); Texture mainTexture = val2.mainTexture; Utils.ConfigureMaterial(val2, prefab, val3, typeDict, matItem); val2.SetTexture(Utils.MainTex, mainTexture); } } } } } } namespace Valharvest.Scripts { [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<MilkLox>(); } } 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>(); customBeehive.m_hideWhenPicked = ((Component)val).gameObject; customBeehive.m_spawnPoint = val2; customBeehive.m_honeyItem = PrefabManager.Instance.GetPrefab("water_bucket").GetComponent<ItemDrop>(); 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 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; } } public static class ConsumableItemExtractor { private static HashSet<string> 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<string> hashSet = new HashSet<string>(); 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>)(object)val).Count} items"); JsonArray val2 = ExtractAllRecipes(); File.WriteAllText("recipes.json", ((object)val2).ToString()); Logger.LogInfo((object)$"Wrote recipes.json with {((List<object>)(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<string> hashSet = new HashSet<string>(); HashSet<string> 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>)(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<string> 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>)(object)val3).Add((object)val5); } } } val2.Add("requirements", (object)val3); ((List<object>)(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>)(object)val).Add((object)((Object)shared.m_attackStatusEffect).name); } if ((Object)(object)shared.m_consumeStatusEffect != (Object)null) { ((List<object>)(object)val).Add((object)((Object)shared.m_consumeStatusEffect).name); } if ((Object)(object)shared.m_equipStatusEffect != (Object)null) { ((List<object>)(object)val).Add((object)((Object)shared.m_equipStatusEffect).name); } if ((Object)(object)shared.m_setStatusEffect != (Object)null) { ((List<object>)(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 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<GameObject>(prefab, ((Component)__instance).transform.position, Quaternion.identity); } for (int j = 0; j < num2; j++) { Object.Instantiate<GameObject>(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<Plant>(); 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 InteractFertilizer : MonoBehaviour, Interactable { private ZNetView _nview; private void Awake() { _nview = ((Component)this).gameObject.GetComponent<ZNetView>(); } 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<Plant>(); 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 static class Loaders { 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<string, object> item in SimpleJson.DeserializeObject<JsonObject>(text)) { Dictionary<string, AssetBundle> assetBundle = GetAssetBundle(); JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString()); GameObject val2 = assetBundle[val["assetBundle"].ToString()].LoadAsset<GameObject>(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<string, object> item in SimpleJson.DeserializeObject<JsonObject>(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<string, AssetBundle> assetBundle = GetAssetBundle(); JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString()); GameObject piecePrefab = assetBundle[val["assetBundle"].ToString()].LoadAsset<GameObject>(item.Key); try { CustomPiece val2 = CreatePieceRecipe(piecePrefab, val); Piece piece = val2.Piece; SetPieceInfo(val, piece); PieceManager.Instance.AddPiece(val2); } 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<string, AssetBundle> GetAssetBundle() { return new Dictionary<string, AssetBundle> { { "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<JsonObject>(itemObject["crafting"].ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject<RequirementConfig[]>(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) { //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<JsonObject>(pieceObject["crafting"].ToString()); RequirementConfig[] requirements = SimpleJson.DeserializeObject<RequirementConfig[]>(val["requirements"].ToString()); PieceConfig val2 = new PieceConfig { Name = pieceObject["name"].ToString(), Enabled = true, 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<MilkLox>(); 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<ItemData>)((Humanoid)Player.m_localPlayer).m_inventory.m_inventory).FirstOrDefault((Func<ItemData, bool>)((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<object>()); 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<MilkLox>().GetMilkLevel(); if (milkLevel > 0) { __result += Localization.instance.Localize("\n\nLox Milk ( $milk_bottle_name x " + milkLevel + " )\n[<b><color=yellow>L-Alt + $KEY_Use</color></b>] $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<ZNetView>(); 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<long>)RPC_ExtractMilk); nview.Register<int>("ResetLevel", (Action<long, int>)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<ItemDrop>(_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<string> PickableList = new List<string> { "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 = "<color=" + colour + ">" + text + "%</color>"; 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 = "<color=" + colour + ">" + text + "%</color>"; 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>(); CraftingStation component2 = prefab2.GetComponent<CraftingStation>(); 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<Piece> m_tempPieces = new List<Piece>(); private static readonly List<Transform> m_tempSnapPoints1 = new List<Transform>(); private static readonly List<Transform> m_tempSnapPoints2 = new List<Transform>(); [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<Plant>(); Piece component2 = placementGhost.GetComponent<Piece>(); 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<Collider>().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<Plant>() == (Object)null)) { return true; } } return false; } private static void GetSnapPoints(Vector3 point, float radius, ICollection<Transform> points, ICollection<Piece> 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_pie