Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of TillValhalla v2.4.21
plugins\TillValhalla.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using TMPro; using TillValhalla.Configurations; using TillValhalla.Configurations.Sections; using TillValhalla.GameClasses; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("TillValhalla")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("TillValhalla")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] internal static class GameObjectAssistant { private static Dictionary<int, Stopwatch> stopwatches = new Dictionary<int, Stopwatch>(); public static Stopwatch GetStopwatch(GameObject o) { int instanceID = ((Object)o).GetInstanceID(); if (!stopwatches.TryGetValue(instanceID, out var value)) { value = new Stopwatch(); stopwatches[instanceID] = value; } return value; } public static T GetChildComponentByName<T>(string name, GameObject objected) where T : Component { T[] componentsInChildren = objected.GetComponentsInChildren<T>(true); foreach (T val in componentsInChildren) { if (((Object)((Component)val).gameObject).name == name) { return val; } } return default(T); } } public class HotBarUtils { public static bool IgnoreKeyPresses(bool extra = false) { if (!extra) { if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog()) { Chat instance = Chat.instance; if (instance == null) { return false; } return instance.HasFocus(); } return true; } if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog()) { Chat instance2 = Chat.instance; if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible()) { TextViewer instance3 = TextViewer.instance; if (instance3 == null) { return false; } return instance3.IsVisible(); } } return true; } public static bool CheckKeyDown(string value) { try { return Input.GetKeyDown(value.ToLower()); } catch { return false; } } } namespace TillValhalla { [BepInPlugin("kwilson.TillValhalla", "TillValhalla", "2.4.21")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class TillValhalla : BaseUnityPlugin { public static class WoodDefinitions { public static readonly string FineWoodName = "$item_finewood"; public static readonly string RoundLogName = "$item_roundlog"; } [HarmonyPatch(typeof(Terminal), "InputText")] private static class InputText_Patch { private static bool Prefix(Terminal __instance) { if (!Configuration.modisenabled.Value) { return true; } string text = ((TMP_InputField)__instance.m_input).text; if (text.ToLower().Equals("hotbarswitch reset")) { ((BaseUnityPlugin)context).Config.Reload(); ((BaseUnityPlugin)context).Config.Save(); Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue(); Traverse.Create((object)__instance).Method("AddString", new object[1] { "hotbar switch config reloaded" }).GetValue(); return false; } return true; } } public const string PluginGUID = "kwilson.TillValhalla"; public const string PluginName = "TillValhalla"; public const string PluginVersion = "2.4.21"; public readonly Harmony _harmony = new Harmony("kwilson.TillValhalla"); private AssetBundle undestructablewallbundle; private AssetBundle testspritebundle; private static TillValhalla context; private Texture2D Textureprefab; private Sprite wings; private Sprite varpaint1; private CustomLocalization Localization; public static List<string> whitelist = new List<string>(); public static Dictionary<string, AudioClip> SFX = new Dictionary<string, AudioClip>(); public static Dictionary<string, Dictionary<string, AudioClip>> SFXList = new Dictionary<string, Dictionary<string, AudioClip>>(); private void Awake() { context = this; Configuration.Awake((BaseUnityPlugin)(object)this); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Game Configuration"); if (!Configuration.modisenabled.Value) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Error while loading configuration file."); return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Configuration file successfully loaded"); LoadConfigs(); _harmony.PatchAll(); AddLocalizations(); LoadSFX(); PrefabManager.OnVanillaPrefabsAvailable += ModifyVanillaItems; PrefabManager.OnVanillaPrefabsAvailable += DropTableAdd.surtingcoredropadd; PrefabManager.OnVanillaPrefabsAvailable += AddItemsandprefabs; } private void Update() { if (!Configuration.modisenabled.Value || HotBarUtils.IgnoreKeyPresses(extra: true) || !HotBarUtils.CheckKeyDown(inventoryconfiguration.hotKey.Value)) { return; } int height = ((Humanoid)Player.m_localPlayer).GetInventory().GetHeight(); int num = Math.Max(1, Math.Min(height, inventoryconfiguration.rowsToSwitch.Value)); List<ItemData> value = Traverse.Create((object)((Humanoid)Player.m_localPlayer).GetInventory()).Field("m_inventory").GetValue<List<ItemData>>(); for (int i = 0; i < value.Count; i++) { if (value[i].m_gridPos.y < num) { value[i].m_gridPos.y--; if (value[i].m_gridPos.y < 0) { value[i].m_gridPos.y = num - 1; } } } Traverse.Create((object)((Humanoid)Player.m_localPlayer).GetInventory()).Method("Changed", Array.Empty<object>()).GetValue(); } private void LoadSFX() { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Audio"); ((BaseUnityPlugin)this).Logger.LogInfo((object)text); if (Directory.Exists(text)) { SFX.Clear(); SFXList.Clear(); if (Directory.Exists(Path.Combine(text, "SFX"))) { CollectAudioFiles(Path.Combine(text, "SFX"), SFX, SFXList); } else { Directory.CreateDirectory(Path.Combine(text, "SFX")); } } else { Directory.CreateDirectory(text); Directory.CreateDirectory(Path.Combine(text, "SFX")); } } private void CollectAudioFiles(string path, Dictionary<string, AudioClip> customDict, Dictionary<string, Dictionary<string, AudioClip>> customDictDict) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Checking folder " + Path.GetFileName(path))); string[] files = Directory.GetFiles(path); foreach (string path2 in files) { PreloadClipCoroutine(path2, (AudioType)0, customDict); } files = Directory.GetDirectories(path); foreach (string path3 in files) { string fileName = Path.GetFileName(path3); string[] files2 = Directory.GetFiles(path3); customDictDict[fileName] = new Dictionary<string, AudioClip>(); string[] array = files2; foreach (string path4 in array) { PreloadClipCoroutine(path4, (AudioType)0, customDictDict[fileName]); } if (files2.Length == 1 && files2[0].ToLower().EndsWith(".txt")) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(files2[0]); if (customDictDict.ContainsKey(fileNameWithoutExtension)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("\tLinking music folder " + fileName + " to folder " + fileNameWithoutExtension)); customDictDict[fileName] = customDictDict[fileNameWithoutExtension]; } } } } private void PreloadClipCoroutine(string path, AudioType audioType, Dictionary<string, AudioClip> whichDict) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Invalid comparison between Unknown and I4 //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown if (path.EndsWith(".txt") || !Path.HasExtension(path)) { return; } try { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Path: " + path)); UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(new Uri(path).AbsoluteUri, audioType); try { UnityWebRequestAsyncOperation val = audioClip.SendWebRequest(); while (!((AsyncOperation)val).isDone) { } if ((int)audioClip.result != 1) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Failed to load audio clip. Error: " + audioClip.error + ", URL: " + audioClip.url)); return; } DownloadHandlerAudioClip val2 = (DownloadHandlerAudioClip)audioClip.downloadHandler; AudioClip val3 = ((val2 != null) ? val2.audioClip : null); if ((Object)(object)val3 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Audio clip is null. Response data: " + ((DownloadHandler)val2).text)); return; } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); if (!whichDict.ContainsKey(fileNameWithoutExtension)) { whichDict[fileNameWithoutExtension] = val3; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Added audio clip '" + fileNameWithoutExtension + "' to dictionary.")); } } finally { ((IDisposable)audioClip)?.Dispose(); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Exception occurred while loading audio clip: " + ex.Message)); } } private void AddLocalizations() { Localization = LocalizationManager.Instance.GetLocalization(); CustomLocalization localization = Localization; string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "fire_wood_chest_name", "Firewood Chest" }, { "fire_wood_chest_description", "Chest for storing wood for the fires to pull from." } }); } private void AddItemsandprefabs() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) PieceConfig val = new PieceConfig(); val.Name = "$fire_wood_chest_name"; val.Description = "$fire_wood_chest_description"; val.PieceTable = "Hammer"; val.Category = "Crafting"; PieceManager.Instance.AddPiece(new CustomPiece("firewood_chest", "piece_chest_wood", val)); PieceManager.Instance.GetPiece("firewood_chest").PiecePrefab.GetComponent<Container>().m_name = "$fire_wood_chest_name"; PieceManager.Instance.GetPiece("firewood_chest").PiecePrefab.GetComponent<Transform>().localScale = new Vector3(0.5f, 0.5f, 0.5f); PrefabManager.OnVanillaPrefabsAvailable -= AddItemsandprefabs; } private void LoadConfigs() { try { GameConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Game Configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Game Configuration"); } try { BeehiveConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load beehive configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Beehive Configuration"); } try { ItemDropConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load ItemDrop configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded ItemDrop Configuration"); } try { inventoryconfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Inventory Configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Inventory Configuration"); } try { ShipConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Ship Configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Ship Configuration"); } try { CraftingStationConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load CraftingStation configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded CraftingStation Configuration"); } try { gatherconfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Gather configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Gather Configuration"); } try { FireplaceConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Fireplace configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Fireplace Configuration"); } try { PlayerConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Player configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Player Configuration"); } try { PlantConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Plant configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Plant Configuration"); } try { containerconfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Container configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Container Configuration"); } try { SmelterConfiguration.Awake((BaseUnityPlugin)(object)this); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Smelter configuration"); } finally { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Smelter Configuration"); } try { SapCollectorConfiguration.Awake((BaseUnityPlugin)(object)this); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Sap Collection Configuration"); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load Sap collection configuration"); } try { ZSFXConfiguration.Awake((BaseUnityPlugin)(object)this); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded ZSFX Configuration"); } catch { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load ZSFX configuration"); } SynchronizationManager.OnConfigurationSynchronized += delegate(object obj15, ConfigurationSynchronizationEventArgs attr) { if (attr.InitialSynchronization) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Initial Config sync event received"); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Config sync event received"); } }; } private void ModifyVanillaItems() { try { GameObject prefab = PrefabManager.Instance.GetPrefab("SwordCheat"); prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_damages.m_slash = 0f; prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_damages.m_chop = 0f; prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_damages.m_pickaxe = 0f; } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)$"Error while adding variant item: {arg}"); } finally { PrefabManager.OnVanillaPrefabsAvailable -= ModifyVanillaItems; } } } internal static class helper { public static float applyModifierValue(float targetValue, float value) { if (value <= -100f) { value = -100f; } float num = targetValue; if (value >= 0f) { return targetValue + targetValue / 100f * value; } return targetValue - targetValue / 100f * (value * -1f); } public static int Clamp(int value, int min, int max) { return Math.Min(max, Math.Max(min, value)); } public static float Clamp(float value, float min, float max) { return Math.Min(max, Math.Max(min, value)); } } internal static class InventoryAssistant { public static List<Container> GetNearbyFireWoodChests(GameObject target, float range, bool checkWard = true) { //IL_0046: 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) string[] array = new string[1] { "piece" }; array = new string[3] { "piece", "item", "vehicle" }; IOrderedEnumerable<Collider> orderedEnumerable = from x in Physics.OverlapSphere(target.transform.position, range, LayerMask.GetMask(array)) orderby Vector3.Distance(((Component)x).gameObject.transform.position, target.transform.position) select x; List<Container> list = new List<Container>(); foreach (Collider item in orderedEnumerable) { try { Container componentInParent = ((Component)item).GetComponentInParent<Container>(); bool flag = componentInParent.CheckAccess(Player.m_localPlayer.GetPlayerID()); if (checkWard) { flag = flag && PrivateArea.CheckAccess(((Component)item).gameObject.transform.position, 0f, false, true); } Piece componentInParent2 = ((Component)componentInParent).GetComponentInParent<Piece>(); _ = (Object)(object)((Component)componentInParent).GetComponentInParent<Vagon>() != (Object)null; _ = (Object)(object)((Component)componentInParent).GetComponentInParent<Ship>() != (Object)null; if ((Object)(object)componentInParent2 != (Object)null && flag && componentInParent.GetInventory() != null && componentInParent2.IsPlacedByPlayer() && componentInParent.m_name == "$fire_wood_chest_name") { list.Add(componentInParent); } } catch { } } return list; } public static List<Container> GetNearbyChests(GameObject target, float range, bool checkWard = true) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[1] { "piece" }; if (CraftingStationConfiguration.craftFromCarts.Value || CraftingStationConfiguration.craftFromShips.Value) { array = new string[3] { "piece", "item", "vehicle" }; } IOrderedEnumerable<Collider> orderedEnumerable = from x in Physics.OverlapSphere(target.transform.position, range, LayerMask.GetMask(array)) orderby Vector3.Distance(((Component)x).gameObject.transform.position, target.transform.position) select x; List<Container> list = new List<Container>(); foreach (Collider item in orderedEnumerable) { try { Container componentInParent = ((Component)item).GetComponentInParent<Container>(); bool flag = componentInParent.CheckAccess(Player.m_localPlayer.GetPlayerID()); if (checkWard) { flag = flag && PrivateArea.CheckAccess(((Component)item).gameObject.transform.position, 0f, false, true); } Piece componentInParent2 = ((Component)componentInParent).GetComponentInParent<Piece>(); bool flag2 = (Object)(object)((Component)componentInParent).GetComponentInParent<Vagon>() != (Object)null; bool flag3 = (Object)(object)((Component)componentInParent).GetComponentInParent<Ship>() != (Object)null; if ((Object)(object)componentInParent2 != (Object)null && flag && componentInParent.GetInventory() != null && (!flag2 || CraftingStationConfiguration.craftFromCarts.Value) && (!flag3 || CraftingStationConfiguration.craftFromShips.Value) && (componentInParent2.IsPlacedByPlayer() || (flag3 && CraftingStationConfiguration.craftFromShips.Value)) && componentInParent.m_name != "$fire_wood_chest_name") { list.Add(componentInParent); } } catch { } } return list; } public static List<Container> GetNearbyChestsWithItem(GameObject target, float range, ItemData itemInfo, bool checkWard = true) { List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); List<Container> list = new List<Container>(); foreach (Container item in nearbyChests) { if (ChestContainsItem(item, itemInfo)) { list.Add(item); } } return list; } public static bool ChestContainsItem(Container chest, ItemData needle) { foreach (ItemData allItem in chest.GetInventory().GetAllItems()) { if (allItem.m_shared.m_name == needle.m_shared.m_name) { return true; } } return false; } public static bool ChestContainsItem(Container chest, string needle) { foreach (ItemData allItem in chest.GetInventory().GetAllItems()) { if (allItem.m_shared.m_name == needle) { return true; } } return false; } public static List<ItemData> GetNearbyChestItems(GameObject target, float range = 10f, bool checkWard = true) { List<ItemData> list = new List<ItemData>(); foreach (Container nearbyChest in GetNearbyChests(target, range, checkWard)) { foreach (ItemData allItem in nearbyChest.GetInventory().GetAllItems()) { list.Add(allItem); } } return list; } public static List<ItemData> GetNearbyChestItemsByContainerList(List<Container> nearbyChests) { List<ItemData> list = new List<ItemData>(); foreach (Container nearbyChest in nearbyChests) { list.AddRange(nearbyChest.GetInventory().GetAllItems()); } return list; } public static int GetItemAmountInItemList(List<ItemData> itemList, ItemData needle) { int num = 0; foreach (ItemData item in itemList) { if (item.m_shared.m_name == needle.m_shared.m_name) { num += item.m_stack; } } return num; } public static int GetItemAmountInItemList(List<ItemData> itemList, string needle) { int num = 0; foreach (ItemData item in itemList) { if (item.m_shared.m_name == needle) { num += item.m_stack; } } return num; } public static int RemoveItemInAmountFromAllNearbyChests(GameObject target, float range, ItemData needle, int amount, bool checkWard = true) { List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); GetItemAmountInItemList(GetNearbyChestItemsByContainerList(nearbyChests), needle); if (amount == 0) { return 0; } int num = 0; foreach (Container item in nearbyChests) { if (num != amount) { int num2 = RemoveItemFromChest(item, needle, amount); num += num2; amount -= num2; } } return num; } public static int RemoveFireWoodItemInAmountFromAllNearbyChests(GameObject target, float range, ItemData needle, int amount, bool checkWard = true) { List<Container> nearbyFireWoodChests = GetNearbyFireWoodChests(target, range, checkWard); GetItemAmountInItemList(GetNearbyChestItemsByContainerList(nearbyFireWoodChests), needle); if (amount == 0) { return 0; } int num = 0; foreach (Container item in nearbyFireWoodChests) { if (num != amount) { int num2 = RemoveItemFromChest(item, needle, amount); num += num2; amount -= num2; } } return num; } public static int RemoveItemInAmountFromAllNearbyChests(GameObject target, float range, string needle, int amount, bool checkWard = true) { List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); GetItemAmountInItemList(GetNearbyChestItemsByContainerList(nearbyChests), needle); if (amount == 0) { return 0; } int num = 0; foreach (Container item in nearbyChests) { if (num != amount) { int num2 = RemoveItemFromChest(item, needle, amount); num += num2; amount -= num2; } } return num; } public static int RemoveItemFromChest(Container chest, ItemData needle, int amount = 1) { if (!ChestContainsItem(chest, needle)) { return 0; } int num = 0; List<ItemData> allItems = chest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { if (item.m_shared.m_name == needle.m_shared.m_name) { int num2 = Mathf.Min(item.m_stack, amount); item.m_stack -= num2; amount -= num2; num += num2; if (amount <= 0) { break; } } } if (num == 0) { return 0; } allItems.RemoveAll((ItemData x) => x.m_stack <= 0); chest.m_inventory.m_inventory = allItems; ConveyContainerToNetwork(chest); return num; } public static int RemoveItemFromChest(Container chest, string needle, int amount = 1) { if (!ChestContainsItem(chest, needle)) { return 0; } int num = 0; List<ItemData> allItems = chest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { if (item.m_shared.m_name == needle) { int num2 = Mathf.Min(item.m_stack, amount); item.m_stack -= num2; amount -= num2; num += num2; if (amount <= 0) { break; } } } if (num == 0) { return 0; } allItems.RemoveAll((ItemData x) => x.m_stack <= 0); chest.m_inventory.m_inventory = allItems; ConveyContainerToNetwork(chest); return num; } public static void ConveyContainerToNetwork(Container c) { c.Save(); c.GetInventory().Changed(false, false); } } } namespace TillValhalla.GameClasses { [HarmonyPatch(typeof(CookingStation), "FindCookableItem")] public static class CookingStation_FindCookableItem_Transpiler { private static List<Container> nearbyChests = null; private static MethodInfo method_PullCookableItemFromNearbyChests = AccessTools.Method(typeof(CookingStation_FindCookableItem_Transpiler), "PullCookableItemFromNearbyChests", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown if (!CraftingStationConfiguration.craftFromChests.Value || CraftingStationConfiguration.disableCookingStation.Value) { return instructions; } List<CodeInstruction> list = instructions.ToList(); bool flag = false; for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldnull) { list[i] = new CodeInstruction(OpCodes.Ldarg_0, (object)null) { labels = list[i].labels }; list.Insert(++i, new CodeInstruction(OpCodes.Call, (object)method_PullCookableItemFromNearbyChests)); flag = true; break; } } if (!flag) { ZLog.LogError((object)"Failed to apply CookingStation_FindCookableItem_Transpiler"); return instructions; } return list.AsEnumerable(); } private static ItemData PullCookableItemFromNearbyChests(CookingStation station) { if (station.GetFreeSlot() == -1) { return null; } Stopwatch stopwatch = GameObjectAssistant.GetStopwatch(((Component)station).gameObject); int num = helper.Clamp(3, 1, 10) * 1000; if (!stopwatch.IsRunning || stopwatch.ElapsedMilliseconds > num) { nearbyChests = InventoryAssistant.GetNearbyChests(((Component)station).gameObject, helper.Clamp(CraftingStationConfiguration.craftFromChestRange.Value, 1, 50), !CraftingStationConfiguration.ignorePrivateAreaCheck.Value); stopwatch.Restart(); } foreach (ItemConversion item in station.m_conversion) { ItemData itemData = item.m_from.m_itemData; foreach (Container nearbyChest in nearbyChests) { if (nearbyChest.GetInventory().HaveItem(itemData.m_shared.m_name, true)) { InventoryAssistant.RemoveItemFromChest(nearbyChest, itemData); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(((Object)((Component)item.m_from).gameObject).name); ZNetView.m_forceDisableInit = true; GameObject obj = Object.Instantiate<GameObject>(itemPrefab); ZNetView.m_forceDisableInit = false; return obj.GetComponent<ItemDrop>().m_itemData; } } } return null; } } [HarmonyPatch(typeof(Container), "Awake")] public static class Container_Awake_Patch { private static void Postfix(Container __instance, ref Inventory ___m_inventory) { if (!containerconfiguration.enabled.Value && !Configuration.modisenabled.Value) { return; } if ((Object)(object)__instance == (Object)null || ___m_inventory == null || !Object.op_Implicit((Object)(object)((Component)__instance).transform.parent)) { if (___m_inventory != null) { string name = ___m_inventory.m_name; ref int width = ref ___m_inventory.m_width; ref int height = ref ___m_inventory.m_height; switch (name) { case "$piece_chestprivate": height = helper.Clamp(containerconfiguration.privateChestCol.Value, 2, 20); width = helper.Clamp(containerconfiguration.privateChestRows.Value, 3, 8); break; case "$piece_chestwood": height = helper.Clamp(containerconfiguration.woodChestInventoryCol.Value, 2, 10); width = helper.Clamp(containerconfiguration.woodChestInventoryRows.Value, 3, 8); break; case "$piece_chest": height = helper.Clamp(containerconfiguration.ironChestCol.Value, 3, 20); width = helper.Clamp(containerconfiguration.ironChestRows.Value, 3, 8); break; case "$piece_chestblackmetal": height = helper.Clamp(containerconfiguration.blackMetalChestCol.Value, 3, 20); width = helper.Clamp(containerconfiguration.blackMetalChestRows.Value, 3, 8); break; } } } else { string name2 = ((Object)((Component)__instance).transform.parent).name; _ = ___m_inventory.m_name; ref int width2 = ref ___m_inventory.m_width; ref int height2 = ref ___m_inventory.m_height; if (name2.Contains("Karve")) { height2 = helper.Clamp(containerconfiguration.karveChestCol.Value, 2, 30); width2 = helper.Clamp(containerconfiguration.karveChestRows.Value, 2, 8); } else if (name2.Contains("VikingShip")) { height2 = helper.Clamp(containerconfiguration.vikingshipChestCol.Value, 3, 30); width2 = helper.Clamp(containerconfiguration.vikingshipChestRows.Value, 6, 8); } else if (name2.Contains("Cart")) { height2 = helper.Clamp(containerconfiguration.cartChestCol.Value, 3, 30); width2 = helper.Clamp(containerconfiguration.cartChestRows.Value, 6, 8); } } } } [HarmonyPatch(typeof(CraftingStation), "Start")] public static class CraftingStation_Awake_Patch { public static void Postfix(CraftingStation __instance) { __instance.m_craftRequireRoof = CraftingStationConfiguration.craftingroofrequired.Value; __instance.m_rangeBuild = CraftingStationConfiguration.workbenchcraftingRange.Value; } } [HarmonyPatch(typeof(Piece), "Awake")] public static class Piece_Awake_Patch { public static void Postfix(Piece __instance) { if (__instance.m_name.Contains("_ext") && !CraftingStationConfiguration.UpgradeSpaceRequirementEnabled.Value) { __instance.m_spaceRequirement = 0f; } } } [HarmonyPatch(typeof(DropTable), "GetDropList", new Type[] { typeof(int) })] public static class DropTable_GetDropList_Patch { private static float originalDropChance; private static void Prefix(ref DropTable __instance, ref List<GameObject> __result, int amount) { originalDropChance = __instance.m_dropChance; if (gatherconfiguration.enabled.Value && gatherconfiguration.Dropchance.Value != 0f) { float num = helper.applyModifierValue(__instance.m_dropChance, gatherconfiguration.Dropchance.Value); if (num >= 1f) { num = 1f; } if (num <= 0f) { num = 0f; } if (__instance.m_dropChance != 1f) { __instance.m_dropChance = num; } } } private static void Postfix(ref DropTable __instance, ref List<GameObject> __result, int amount) { __instance.m_dropChance = originalDropChance; if (!gatherconfiguration.enabled.Value && ItemDropConfiguration.ValuableItems.Value == 0f) { return; } int num = 0; GameObject item = null; int num2 = 0; GameObject item2 = null; int num3 = 0; GameObject item3 = null; int num4 = 0; GameObject item4 = null; int num5 = 0; GameObject item5 = null; int num6 = 0; GameObject item6 = null; int num7 = 0; GameObject item7 = null; int num8 = 0; GameObject item8 = null; int num9 = 0; GameObject item9 = null; int num10 = 0; GameObject item10 = null; int num11 = 0; GameObject item11 = null; int num12 = 0; GameObject item12 = null; int num13 = 0; GameObject item13 = null; int num14 = 0; GameObject item14 = null; int num15 = 0; GameObject item15 = null; int num16 = 0; GameObject item16 = null; int num17 = 0; GameObject item17 = null; List<GameObject> list = new List<GameObject>(); foreach (GameObject item18 in __result) { switch (((Object)item18).name) { case "Wood": num++; item = item18; break; case "RoundLog": num2++; item2 = item18; break; case "Stone": num3++; item3 = item18; break; case "IronScrap": num4++; item4 = item18; break; case "TinOre": num5++; item5 = item18; break; case "CopperOre": num6++; item6 = item18; break; case "SilverOre": num7++; item7 = item18; break; case "ElderBark": num8++; item8 = item18; break; case "FineWood": num9++; item9 = item18; break; case "YggdrasilWood": num10++; item10 = item18; break; case "SoftTissue": num12++; item12 = item18; break; case "BlackMarble": num13++; item13 = item18; break; case "Amber": num14++; item14 = item18; break; case "AmberPearl": case "AmberPeral": num15++; item15 = item18; break; case "Coins": case "AncientCoin": num16++; item16 = item18; break; case "Ruby": num17++; item17 = item18; break; default: list.Add(item18); break; } } for (int i = 0; (float)i < helper.applyModifierValue(num, gatherconfiguration.wood.Value); i++) { list.Add(item); } for (int j = 0; (float)j < helper.applyModifierValue(num2, gatherconfiguration.coreWood.Value); j++) { list.Add(item2); } for (int k = 0; (float)k < helper.applyModifierValue(num3, gatherconfiguration.stone.Value); k++) { list.Add(item3); } for (int l = 0; (float)l < helper.applyModifierValue(num4, gatherconfiguration.ironScrap.Value); l++) { list.Add(item4); } for (int m = 0; (float)m < helper.applyModifierValue(num5, gatherconfiguration.tinOre.Value); m++) { list.Add(item5); } for (int n = 0; (float)n < helper.applyModifierValue(num6, gatherconfiguration.copperOre.Value); n++) { list.Add(item6); } for (int num18 = 0; (float)num18 < helper.applyModifierValue(num7, gatherconfiguration.silverOre.Value); num18++) { list.Add(item7); } for (int num19 = 0; (float)num19 < helper.applyModifierValue(num8, gatherconfiguration.elderBark.Value); num19++) { list.Add(item8); } for (int num20 = 0; (float)num20 < helper.applyModifierValue(num9, gatherconfiguration.fineWood.Value); num20++) { list.Add(item9); } for (int num21 = 0; (float)num21 < helper.applyModifierValue(num11, gatherconfiguration.chitin.Value); num21++) { list.Add(item11); } for (int num22 = 0; (float)num22 < helper.applyModifierValue(num10, gatherconfiguration.YggdrasilWood.Value); num22++) { list.Add(item10); } for (int num23 = 0; (float)num23 < helper.applyModifierValue(num12, gatherconfiguration.SoftTissue.Value); num23++) { list.Add(item12); } for (int num24 = 0; (float)num24 < helper.applyModifierValue(num13, gatherconfiguration.BlackMarble.Value); num24++) { list.Add(item13); } for (int num25 = 0; (float)num25 < helper.applyModifierValue(num14, ItemDropConfiguration.ValuableItems.Value); num25++) { list.Add(item14); } for (int num26 = 0; (float)num26 < helper.applyModifierValue(num15, ItemDropConfiguration.ValuableItems.Value); num26++) { list.Add(item15); } for (int num27 = 0; (float)num27 < helper.applyModifierValue(num16, ItemDropConfiguration.ValuableItems.Value); num27++) { list.Add(item16); } for (int num28 = 0; (float)num28 < helper.applyModifierValue(num17, ItemDropConfiguration.ValuableItems.Value); num28++) { list.Add(item17); } __result = list; } } [HarmonyPatch(typeof(DropTable), "GetDropListItems")] public static class DropTable_GetDropListItems_Patch { private static readonly HashSet<string> ValuablePrefabNames = new HashSet<string>(StringComparer.Ordinal) { "Amber", "AmberPearl", "AmberPeral", "AncientCoin", "Coins", "Ruby" }; private static void Postfix(List<ItemData> __result) { if (!Configuration.modisenabled.Value || ItemDropConfiguration.ValuableItems.Value == 0f || __result == null) { return; } foreach (ItemData item in __result) { if (!((Object)(object)item?.m_dropPrefab == (Object)null)) { string text = ((Object)item.m_dropPrefab).name; int num = text.IndexOf("(Clone)", StringComparison.Ordinal); if (num >= 0) { text = text.Substring(0, num); } if (ValuablePrefabNames.Contains(text)) { int val = (int)Math.Round(helper.applyModifierValue(item.m_stack, ItemDropConfiguration.ValuableItems.Value)); item.m_stack = Math.Max(1, val); } } } } } public class DropTableAdd { public static void surtingcoredropadd() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: 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_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Expected O, but got Unknown //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013c: 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) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Expected O, but got Unknown try { GameObject prefab = PrefabManager.Instance.GetPrefab("SurtlingCore"); GameObject prefab2 = PrefabManager.Instance.GetPrefab("GreydwarfEye"); CharacterDrop component = PrefabManager.Instance.GetPrefab("Greydwarf").GetComponent<CharacterDrop>(); CharacterDrop component2 = PrefabManager.Instance.GetPrefab("Greydwarf_Elite").GetComponent<CharacterDrop>(); CharacterDrop component3 = PrefabManager.Instance.GetPrefab("Greydwarf_Shaman").GetComponent<CharacterDrop>(); PrefabManager.Instance.GetPrefab("Greyling").GetComponent<CharacterDrop>().m_drops.Add(new Drop { m_amountMax = 3, m_amountMin = 1, m_chance = 5f, m_levelMultiplier = true, m_onePerPlayer = false, m_prefab = prefab2 }); component.m_drops.Add(new Drop { m_amountMax = 2, m_amountMin = 0, m_chance = 20f, m_levelMultiplier = true, m_onePerPlayer = false, m_prefab = prefab }); component2.m_drops.Add(new Drop { m_amountMax = 2, m_amountMin = 1, m_chance = 25f, m_levelMultiplier = true, m_onePerPlayer = false, m_prefab = prefab }); component3.m_drops.Add(new Drop { m_amountMax = 2, m_amountMin = 1, m_chance = 20f, m_levelMultiplier = true, m_onePerPlayer = false, m_prefab = prefab }); } catch { Logger.LogError((object)"Failed to load surtling drop tables"); } finally { PrefabManager.OnVanillaPrefabsAvailable -= surtingcoredropadd; } } } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] public static class Character_Drop_Add { [HarmonyPrefix] private static bool MultiplyLoot(CharacterDrop __instance, ref List<KeyValuePair<GameObject, int>> __result) { List<KeyValuePair<GameObject, int>> list = new List<KeyValuePair<GameObject, int>>(); int num = ((!Object.op_Implicit((Object)(object)__instance.m_character)) ? 1 : Mathf.Max(1, (int)Mathf.Pow(2f, (float)(__instance.m_character.GetLevel() - 1)))); foreach (Drop drop in __instance.m_drops) { if ((Object)(object)drop.m_prefab == (Object)null) { continue; } float num2 = drop.m_chance; if (drop.m_levelMultiplier) { num2 *= (float)num; } if (!(Random.value <= num2)) { continue; } int num3 = Random.Range(drop.m_amountMin, drop.m_amountMax); if (drop.m_levelMultiplier) { num3 *= num; } if (drop.m_onePerPlayer) { num3 = ZNet.instance.GetNrOfPlayers(); } if (num3 <= 0 || !((Object)(object)drop.m_prefab != (Object)null)) { continue; } switch (((Object)drop.m_prefab).name) { case "BlackMetalScrap": { float num10 = helper.applyModifierValue(num3, gatherconfiguration.BlackMetalScrap.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num10))); break; } case "GreydwarfEye": { if (num3 == 0) { num3 = 1; } float num20 = helper.applyModifierValue(num3, gatherconfiguration.GreydwarfEye.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num20))); break; } case "RawMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num11 = helper.applyModifierValue(num3, gatherconfiguration.RawMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num11))); break; } case "DeerMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num6 = helper.applyModifierValue(num3, gatherconfiguration.DeerMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num6))); break; } case "HareMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num18 = helper.applyModifierValue(num3, gatherconfiguration.HareMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num18))); break; } case "LoxMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num7 = helper.applyModifierValue(num3, gatherconfiguration.LoxMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num7))); break; } case "NeckTail": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num8 = helper.applyModifierValue(num3, gatherconfiguration.NeckTail.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num8))); break; } case "BugMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num15 = helper.applyModifierValue(num3, gatherconfiguration.BugMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num15))); break; } case "SerpentMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num16 = helper.applyModifierValue(num3, gatherconfiguration.SerpentMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num16))); break; } case "WolfMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num19 = helper.applyModifierValue(num3, gatherconfiguration.WolfMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num19))); break; } case "ChickenMeat": { if (num3 == 0 && gatherconfiguration.FoodDropMinimumEnabled.Value) { num3 = 1; } float num14 = helper.applyModifierValue(num3, gatherconfiguration.ChickenMeat.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num14))); break; } case "DeerHide": { if (num3 == 0 && ItemDropConfiguration.HideAlwaysDropOneEnabled.Value) { num3 = 1; } float num12 = helper.applyModifierValue(num3, ItemDropConfiguration.DeerHide.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num12))); break; } case "ScaleHide": { if (num3 == 0 && ItemDropConfiguration.HideAlwaysDropOneEnabled.Value) { num3 = 1; } float num21 = helper.applyModifierValue(num3, ItemDropConfiguration.ScaleHide.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num21))); break; } case "LoxPelt": { if (num3 == 0 && ItemDropConfiguration.HideAlwaysDropOneEnabled.Value) { num3 = 1; } float num17 = helper.applyModifierValue(num3, ItemDropConfiguration.LoxPelt.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num17))); break; } case "WolfPelt": { if (num3 == 0 && ItemDropConfiguration.HideAlwaysDropOneEnabled.Value) { num3 = 1; } float num13 = helper.applyModifierValue(num3, ItemDropConfiguration.WolfPelt.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num13))); break; } case "LeatherScraps": { if (num3 == 0 && ItemDropConfiguration.HideAlwaysDropOneEnabled.Value) { num3 = 1; } float num9 = helper.applyModifierValue(num3, ItemDropConfiguration.LeatherScraps.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num9))); break; } case "Bloodbag": { if (num3 == 0 && ItemDropConfiguration.HideAlwaysDropOneEnabled.Value) { num3 = 1; } float num5 = helper.applyModifierValue(num3, ItemDropConfiguration.Bloodbag.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num5))); break; } case "AncientCoin": case "Amber": case "Coins": case "AmberPearl": case "AmberPeral": case "Ruby": { float num4 = helper.applyModifierValue(num3, ItemDropConfiguration.ValuableItems.Value); list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, (int)Math.Round(num4))); break; } default: list.Add(new KeyValuePair<GameObject, int>(drop.m_prefab, num3)); break; } } __result = list; return false; } } public static class FirePlaceDefinitions { public static readonly string FirePitName = "$piece_fire"; public static readonly string BonfireName = "$piece_bonfire"; public static readonly string HearthName = "$piece_hearth"; } [HarmonyPatch(typeof(Fireplace), "Awake")] public static class Fireplace_Awake_Patch { private static void Postfix(Fireplace __instance) { if (__instance.m_name.Contains("torch")) { __instance.m_infiniteFuel = FireplaceConfiguration.TorchInfiniteFuel.Value; } else if (__instance.m_name.Contains("sconce")) { __instance.m_infiniteFuel = FireplaceConfiguration.TorchInfiniteFuel.Value; } else if (__instance.m_name.Contains("Brazier")) { __instance.m_infiniteFuel = FireplaceConfiguration.BrazierInfiniteFuel.Value; } else if (__instance.m_name.Equals(FirePlaceDefinitions.FirePitName)) { __instance.m_infiniteFuel = FireplaceConfiguration.FireplaceInfiniteFuel.Value; } else if (__instance.m_name.Equals(FirePlaceDefinitions.HearthName)) { __instance.m_infiniteFuel = FireplaceConfiguration.FireplaceInfiniteFuel.Value; } else if (__instance.m_name.Equals(FirePlaceDefinitions.BonfireName)) { __instance.m_infiniteFuel = FireplaceConfiguration.FireplaceInfiniteFuel.Value; } } } [HarmonyPatch(typeof(Fireplace), "UpdateFireplace")] public static class Fireplace_UpdateSmelter_Patch { private static readonly MethodInfo method_RPC_AddFuel = AccessTools.GetDeclaredMethods(typeof(Fireplace)).FirstOrDefault((MethodInfo m) => m.Name == "RPC_AddFuel"); private static void Prefix(Fireplace __instance) { if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsOwner()) { return; } Stopwatch stopwatch = GameObjectAssistant.GetStopwatch(((Component)__instance).gameObject); if (stopwatch.IsRunning && stopwatch.ElapsedMilliseconds < 1000) { return; } stopwatch.Restart(); float value = 0f; bool flag = false; if (__instance.m_name.Equals(FirePlaceDefinitions.FirePitName)) { if (!FireplaceConfiguration.FireplaceIsEnabled.Value || !FireplaceConfiguration.FireplaceAutoFuel.Value) { return; } value = FireplaceConfiguration.FireplaceAutoRange.Value; flag = false; } else if (__instance.m_name.Equals(FirePlaceDefinitions.HearthName)) { if (!FireplaceConfiguration.FireplaceIsEnabled.Value || !FireplaceConfiguration.FireplaceAutoFuel.Value) { return; } value = FireplaceConfiguration.FireplaceAutoRange.Value; flag = false; } else if (__instance.m_name.Equals(FirePlaceDefinitions.BonfireName)) { if (!FireplaceConfiguration.FireplaceIsEnabled.Value || !FireplaceConfiguration.FireplaceAutoFuel.Value) { return; } value = FireplaceConfiguration.FireplaceAutoRange.Value; flag = false; } else if (__instance.m_name.Contains("torch")) { if (!FireplaceConfiguration.FireplaceIsEnabled.Value || !FireplaceConfiguration.TorchAutoFuel.Value) { return; } value = FireplaceConfiguration.TorchAutoRange.Value; flag = false; } else if (__instance.m_name.Contains("brazier")) { if (!FireplaceConfiguration.FireplaceIsEnabled.Value || !FireplaceConfiguration.BrazierAutoFuel.Value) { return; } value = FireplaceConfiguration.BrazierAutoRange.Value; flag = false; } value = helper.Clamp(value, 1f, 50f); int num = (int)__instance.m_maxFuel - (int)Math.Ceiling(__instance.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f)); if (Object.op_Implicit((Object)(object)__instance.m_fuelItem) && num > 0) { ItemData itemData = __instance.m_fuelItem.m_itemData; int num2 = InventoryAssistant.RemoveFireWoodItemInAmountFromAllNearbyChests(((Component)__instance).gameObject, value, itemData, num, !flag); for (int i = 0; i < num2; i++) { InvokeAddFuelRpc(__instance); } if (num2 > 0 && Configuration.enableDebugLogging != null && Configuration.enableDebugLogging.Value) { ZLog.Log((object)("Added " + num2 + " fuel(" + itemData.m_shared.m_name + ") in " + __instance.m_name)); } } } private static void InvokeAddFuelRpc(Fireplace fireplace) { fireplace.m_nview.InvokeRPC("RPC_AddFuel", BuildRpcPayload(method_RPC_AddFuel)); } private static object[] BuildRpcPayload(MethodInfo rpcMethod) { if (rpcMethod == null) { return new object[0]; } List<object> list = new List<object>(); ParameterInfo[] parameters = rpcMethod.GetParameters(); foreach (ParameterInfo parameterInfo in parameters) { if (!(parameterInfo.ParameterType == typeof(long))) { list.Add(GetDefaultRpcValue(parameterInfo.ParameterType)); } } return list.ToArray(); } private static object GetDefaultRpcValue(Type parameterType) { if (parameterType == typeof(bool)) { return false; } if (parameterType == typeof(int)) { return 1; } if (parameterType == typeof(float)) { return 1f; } if (parameterType == typeof(string)) { return string.Empty; } if (!parameterType.IsValueType) { return null; } return Activator.CreateInstance(parameterType); } } [HarmonyPatch(typeof(Game), "UpdateRespawn")] public static class Player_UpdateRespawn_Transpiler { [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { string operand = GameConfiguration.firstspawnmessage.Value.ToString(); List<CodeInstruction> list = instructions.ToList(); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldstr) { list[i].operand = operand; return list.AsEnumerable(); } } return instructions; } } [HarmonyPatch(typeof(Location), "IsInsideNoBuildLocation")] public static class Location_IsInsideNoBuildLocation_Patch { public static bool Prefix(ref bool __result) { if (GameConfiguration.DisableBuildRestrictions.Value && GameConfiguration.enabled.Value) { __result = false; return false; } return true; } } [HarmonyPatch(typeof(Inventory), "TopFirst")] public static class Inventory_TopFirst_Patch { public static bool Prefix(ref bool __result) { if (inventoryconfiguration.enabled.Value && inventoryconfiguration.toptobottomfill.Value) { __result = true; return false; } return true; } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] public static class Inventory_Constructor_Patch { private const int playerInventoryMaxRows = 20; private const int playerInventoryMinRows = 4; public static void Prefix(string name, ref int w, ref int h) { if (!inventoryconfiguration.enabled.Value) { return; } if (name == "Inventory") { h = helper.Clamp(inventoryconfiguration.playerinventoryrows.Value, 4, 20); } else if (name == "Grave") { if (PlayerInventorySize.LastPlayerInventoryHeight > 0) { h = PlayerInventorySize.LastPlayerInventoryHeight; } else { h = helper.Clamp(inventoryconfiguration.playerinventoryrows.Value, 4, 20); } } } } [HarmonyPatch(typeof(TombStone), "Awake")] public static class TombStone_Awake_Patch { private const int playerInventoryMaxRows = 20; private const int playerInventoryMinRows = 4; public static void Postfix(TombStone __instance) { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown if (!inventoryconfiguration.enabled.Value || (Object)(object)__instance == (Object)null) { return; } Container component = ((Component)__instance).GetComponent<Container>(); if ((Object)(object)component == (Object)null) { return; } int num = ((PlayerInventorySize.LastPlayerInventoryHeight > 0) ? PlayerInventorySize.LastPlayerInventoryHeight : helper.Clamp(inventoryconfiguration.playerinventoryrows.Value, 4, 20)); component.m_width = 8; component.m_height = num; if (component.m_inventory != null && component.m_inventory.GetHeight() < num) { List<ItemData> list = new List<ItemData>(component.m_inventory.GetAllItems()); Inventory val = new Inventory("Grave", component.m_inventory.m_bkg, component.m_width, component.m_height); foreach (ItemData item in list) { val.AddItem(item); } component.m_inventory = val; ZNetView component2 = ((Component)component).GetComponent<ZNetView>(); if ((Object)(object)component2 != (Object)null && component2.IsValid()) { component.Save(); } } PlayerInventorySize.LastPlayerInventoryHeight = 0; } } [HarmonyPatch(typeof(Container), "Awake")] public static class Container_Awake_Grave_Patch { private const int playerInventoryMaxRows = 20; private const int playerInventoryMinRows = 4; public static void Postfix(Container __instance) { if (inventoryconfiguration.enabled.Value && !((Object)(object)__instance == (Object)null) && (Object)(object)((Component)__instance).GetComponent<TombStone>() != (Object)null) { int height = ((PlayerInventorySize.LastPlayerInventoryHeight > 0) ? PlayerInventorySize.LastPlayerInventoryHeight : helper.Clamp(inventoryconfiguration.playerinventoryrows.Value, 4, 20)); __instance.m_width = 8; __instance.m_height = height; } } } [HarmonyPatch(typeof(Inventory), "MoveAll")] public static class Inventory_MoveAll_Patch { private static void Prefix(ref Inventory __instance, ref Inventory fromInventory) { foreach (ItemData item in new List<ItemData>(fromInventory.GetAllItems())) { if (item.m_shared.m_maxStackSize <= 1) { continue; } foreach (ItemData item2 in __instance.m_inventory) { if (item2.m_shared.m_name == item.m_shared.m_name && item2.m_quality == item.m_quality) { int num = Math.Min(item2.m_shared.m_maxStackSize - item2.m_stack, item.m_stack); item2.m_stack += num; if (item.m_stack == num) { fromInventory.RemoveItem(item); break; } item.m_stack -= num; } } } } } public static class Inventory_NearbyChests_Cache { public static List<Container> chests = new List<Container>(); public static readonly Stopwatch delta = new Stopwatch(); } public static class PlayerInventorySize { public static int LastPlayerInventoryHeight; } [HarmonyPatch(typeof(InventoryGui), "Show")] public class InventoryGui_Show_Patch { private const float OneRowSize = 70.5f; private const int DefaultPlayerInventoryRows = 4; private const int MaxVisiblePlayerInventoryRows = 5; private const int MaxPlayerInventoryRows = 20; private const int MinPlayerInventoryRows = 4; private static float lastValue; private static bool baselineCaptured; private static float playerBaseHeight; private static Vector2 containerBaseOffsetMax; private static Vector2 containerBaseOffsetMin; public static void Postfix(ref InventoryGui __instance) { if (inventoryconfiguration.enabled.Value) { int num = CalculateInventoryRows(inventoryconfiguration.playerinventoryrows.Value); int num2 = CalculateVisibleInventoryRows(num); EnsurePlayerInventoryRows(num); CaptureLayoutBaseline(__instance); ResizePlayerInventory(__instance, num2); RepositionContainerInventory(__instance, num2); ConfigurePlayerInventoryScrollbar(__instance, num > num2); } } private static void EnsurePlayerInventoryRows(int inventoryRows) { Player localPlayer = Player.m_localPlayer; Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null); if (val != null && val.GetHeight() != inventoryRows) { Traverse.Create((object)val).Field("m_height").SetValue((object)inventoryRows); Traverse.Create((object)val).Method("Changed", Array.Empty<object>()).GetValue(); } } private static void CaptureLayoutBaseline(InventoryGui inventoryGui) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (!baselineCaptured) { RectTransform player = inventoryGui.m_player; RectTransform container = inventoryGui.m_container; Rect rect = player.rect; playerBaseHeight = ((Rect)(ref rect)).height; containerBaseOffsetMax = container.offsetMax; containerBaseOffsetMin = container.offsetMin; baselineCaptured = true; } } private static void ResizePlayerInventory(InventoryGui inventoryGui, int inventoryRows) { RectTransform player = inventoryGui.m_player; float num = (float)(inventoryRows - 4) * 70.5f; float num2 = playerBaseHeight + num; player.SetSizeWithCurrentAnchors((Axis)1, num2); } private static void RepositionContainerInventory(InventoryGui inventoryGui, int inventoryRows) { //IL_0028: 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) RectTransform container = inventoryGui.m_container; float num = (float)(inventoryRows - 4) * 70.5f; container.offsetMax = new Vector2(containerBaseOffsetMax.x, containerBaseOffsetMax.y - num); container.offsetMin = new Vector2(containerBaseOffsetMin.x, containerBaseOffsetMin.y - num); } private static void ConfigurePlayerInventoryScrollbar(InventoryGui inventoryGui, bool enableScrolling) { GameObject gameObject = ((Component)inventoryGui.m_playerGrid).gameObject; InventoryGrid component = gameObject.GetComponent<InventoryGrid>(); if ((Object)(object)component.m_scrollbar == (Object)null) { CreateAndConfigureScrollbar(inventoryGui, gameObject, component); } ScrollRect component2 = gameObject.GetComponent<ScrollRect>(); if ((Object)(object)component2 != (Object)null) { ((Behaviour)component2).enabled = enableScrolling; component2.vertical = enableScrolling; if (!enableScrolling) { component2.verticalNormalizedPosition = 1f; } } if ((Object)(object)component.m_scrollbar != (Object)null) { ((Component)component.m_scrollbar).gameObject.SetActive(enableScrolling); if (!enableScrolling) { component.m_scrollbar.value = 1f; } } } private static void CreateAndConfigureScrollbar(InventoryGui inventoryGui, GameObject playerGrid, InventoryGrid inventoryGrid) { Scrollbar scrollbar = GetScrollbar(CreateScrollbarGameObject(playerGrid)); ConfigureScrollRect(playerGrid.AddComponent<ScrollRect>(), scrollbar, playerGrid, inventoryGui, inventoryGrid); CacheScrollbarValue(scrollbar); } private static GameObject CreateScrollbarGameObject(GameObject playerGrid) { GameObject obj = Object.Instantiate<GameObject>(((Component)InventoryGui.instance.m_containerGrid.m_scrollbar).gameObject, playerGrid.transform.parent); ((Object)obj).name = "PlayerScroll"; return obj; } private static void ConfigureScrollRect(ScrollRect scrollRect, Scrollbar scrollbar, GameObject playerGrid, InventoryGui inventoryGui, InventoryGrid inventoryGrid) { EnableRectMask(playerGrid); ConfigureScrollRectProperties(scrollRect, scrollbar, playerGrid, inventoryGui, inventoryGrid); ConfigureScrollbarReference(scrollbar, inventoryGrid); SetScrollRectBehavior(scrollRect); } private static void EnableRectMask(GameObject playerGrid) { ((Behaviour)playerGrid.GetComponent<RectMask2D>()).enabled = true; } private static void ConfigureScrollRectProperties(ScrollRect scrollRect, Scrollbar scrollbar, GameObject playerGrid, InventoryGui inventoryGui, InventoryGrid inventoryGrid) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) RectTransform component = playerGrid.GetComponent<RectTransform>(); scrollRect.content = inventoryGrid.m_gridRoot; scrollRect.viewport = ((Component)inventoryGui.m_player).GetComponentInChildren<RectTransform>(); scrollRect.verticalScrollbar = scrollbar; component.offsetMax = new Vector2(800f, component.offsetMax.y); component.anchoredPosition = new Vector2(0f, 1f); } private static void ConfigureScrollbarReference(Scrollbar scrollbar, InventoryGrid inventoryGrid) { inventoryGrid.m_scrollbar = scrollbar; } private static void SetScrollRectBehavior(ScrollRect scrollRect) { scrollRect.horizontal = false; scrollRect.movementType = (MovementType)2; scrollRect.scrollSensitivity = 70.5f; scrollRect.inertia = false; scrollRect.verticalScrollbarVisibility = (ScrollbarVisibility)1; } private static void CacheScrollbarValue(Scrollbar scrollbar) { lastValue = scrollbar.value; } private static Scrollbar GetScrollbar(GameObject gameObject) { return gameObject.GetComponent<Scrollbar>(); } private static int CalculateInventoryRows(int configuredRows) { return Math.Min(20, Math.Max(4, configuredRows)); } private static int CalculateVisibleInventoryRows(int inventoryRows) { return Math.Min(5, inventoryRows); } } [HarmonyPatch(typeof(InventoryGui), "RepairOneItem")] public static class InventoryGui_RepairOneItem_Transpiler { [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown if (!PlayerConfiguration.enabled.Value) { return instructions; } List<CodeInstruction> list = instructions.ToList(); if (PlayerConfiguration.autorepair.Value) { for (int i = 0; i < list.Count; i++) { if (list[i].operand is MethodInfo methodInfo && methodInfo.DeclaringType == typeof(EffectList) && methodInfo.Name == "Create") { int num = methodInfo.GetParameters().Length + ((!methodInfo.IsStatic) ? 1 : 0); list[i] = new CodeInstruction(OpCodes.Pop, (object)null); for (int j = 1; j < num; j++) { list.Insert(i + j, new CodeInstruction(OpCodes.Pop, (object)null)); } list.Insert(i + num, new CodeInstruction(OpCodes.Ldnull, (object)null)); i += num; } } } return list.AsEnumerable(); } } [HarmonyPatch(typeof(InventoryGui), "DoCrafting")] public static class InventoryGui_DoCrafting_Transpiler { private static MethodInfo method_Player_Inventory_RemoveItem = AccessTools.Method(typeof(Inventory), "RemoveItem", new Type[4] { typeof(string), typeof(int), typeof(int), typeof(bool) }, (Type[])null); private static MethodInfo method_UseItemFromInventoryOrChest = AccessTools.Method(typeof(InventoryGui_DoCrafting_Transpiler), "UseItemFromInventoryOrChest", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions) { if (!CraftingStationConfiguration.craftFromChests.Value) { return instructions; } List<CodeInstruction> list = instructions.ToList(); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], method_Player_Inventory_RemoveItem)) { list[i].opcode = OpCodes.Call; list[i].operand = method_UseItemFromInventoryOrChest; } } return list.AsEnumerable(); } private static void UseItemFromInventoryOrChest(Inventory playerInventory, string itemName, int quantity, int quality, bool worldLevelBased) { if (playerInventory.CountItems(itemName, quality, true) >= quantity) { playerInventory.RemoveItem(itemName, quantity, quality, worldLevelBased); return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { playerInventory.RemoveItem(itemName, quantity, quality, worldLevelBased); return; } CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation(); GameObject val = ((currentCraftingStation != null) ? ((Component)currentCraftingStation).gameObject : null); if (!Object.op_Implicit((Object)(object)val) || !CraftingStationConfiguration.craftFromWorkbench.Value) { val = ((Component)localPlayer).gameObject; } List<Container> nearbyChests = InventoryAssistant.GetNearbyChests(val, helper.Clamp(CraftingStationConfiguration.craftFromChestRange.Value, 1, 50), !CraftingStationConfiguration.ignorePrivateAreaCheck.Value); int num = quantity; foreach (Container item in nearbyChests) { if (item.GetInventory().CountItems(itemName, quality, true) > 0) { num -= InventoryAssistant.RemoveItemFromChest(item, itemName, num); if (num == 0) { break; } } } } } [HarmonyPatch(typeof(InventoryGui), "SetupRequirement")] public static class InventoryGui_SetupRequirement_Patch { private static bool Prefix(Transform elementRoot, Requirement req, Player player, bool craft, int quality, ref bool __result) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) if (!CraftingStationConfiguration.craftFromChests.Value) { return true; } Image component = ((Component)((Component)elementRoot).transform.Find("res_icon")).GetComponent<Image>(); TMP_Text component2 = ((Component)((Component)elementRoot).transform.Find("res_name")).GetComponent<TMP_Text>(); TMP_Text component3 = ((Component)((Component)elementRoot).transform.Find("res_amount")).GetComponent<TMP_Text>(); UITooltip component4 = ((Component)elementRoot).GetComponent<UITooltip>(); if ((Object)(object)req.m_resItem != (Object)null) { ((Component)component).gameObject.SetActive(true); ((Component)component2).gameObject.SetActive(true); ((Component)component3).gameObject.SetActive(true); component.sprite = req.m_resItem.m_itemData.GetIcon(); ((Graphic)component).color = Color.white; component4.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name); component2.text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name); int num = ((Humanoid)player).GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name, -1, true); int amount = req.GetAmount(quality); if (amount <= 0) { InventoryGui.HideRequirement(elementRoot); __result = false; return false; } if (CraftingStationConfiguration.craftFromChests.Value) { CraftingStation currentCraftingStation = player.GetCurrentCraftingStation(); GameObject val = ((currentCraftingStation != null) ? ((Component)currentCraftingStation).gameObject : null); Stopwatch stopwatch; if (!Object.op_Implicit((Object)(object)val) || !CraftingStationConfiguration.craftFromWorkbench.Value) { val = ((Component)player).gameObject; stopwatch = Inventory_NearbyChests_Cache.delta; } else { stopwatch = GameObjectAssistant.GetStopwatch(val); } int num2 = helper.Clamp(3, 1, 10) * 1000; if (!stopwatch.IsRunning || stopwatch.ElapsedMilliseconds > num2) { Inventory_NearbyChests_Cache.chests = InventoryAssistant.GetNearbyChests(val, helper.Clamp(CraftingStationConfiguration.craftFromChestRange.Value, 1f, 50f)); stopwatch.Restart(); } num += InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(Inventory_NearbyChests_Cache.chests), req.m_resItem.m_itemData); } component3.text = num + "/" + amount; if (num < amount) { ((Graphic)component3).color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white); } else { ((Graphic)component3).color = Color.white; } component3.fontSize = 14f; if (component3.text.Length > 5) { component3.fontSize -= (float)(component3.text.Length - 5); } } __result = true; return false; } } [HarmonyPatch(typeof(InventoryGui), "UpdateRepair")] public static class InventoryGui_UpdateRepair_Patch { [HarmonyPrefix] public static void Prefix(InventoryGui __instance) { //IL_0053: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!PlayerConfiguration.enabled.Value || !PlayerConfiguration.autorepair.Value) { return; } CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation(); if ((Object)(object)currentCraftingStation != (Object)null) { int num = 0; while (__instance.HaveRepairableItems()) { __instance.RepairOneItem(); num++; } if (num > 0) { currentCraftingStation.m_repairItemDoneEffects.Create(((Component)currentCraftingStation).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); } } } } [HarmonyPatch(typeof(Plant), "HaveGrowSpace")] public class Plant_HaveGrowSpace_Patch { public static bool Postfix(bool __result) { __result = !PlantConfiguration.needgrowspace.Value; return __result; } } [HarmonyPatch(typeof(Plant), "Awake")] public static class Plant_Awake_Patch { public static void Postfix(Plant __instance) { __instance.m_needCultivatedGround = PlantConfiguration.needcultivatedground.Value; Component componentInParent = ((Component)__instance).GetComponentInParent(typeof(Piece)); ((Piece)((componentInParent is Piece) ? componentInParent : null)).m_cultivatedGroundOnly = PlantConfiguration.needcultivatedground.Value; } } [HarmonyPatch(typeof(ItemDrop), "Awake")] public static class ItemDrop_Awake_Patch { public static void Postfix(ItemDrop __instance) { if (ItemDropConfiguration.noteleportprevention.Value && Configuration.modisenabled.Value) { __instance.m_itemData.m_shared.m_teleportable = true; } if (!Configuration.modisenabled.Value) { return; } string text = ((object)Unsafe.As<ItemType, ItemType>(ref __instance.m_itemData.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString(); float num = helper.applyModifierValue(__instance.m_itemData.m_shared.m_maxStackSize, inventoryconfiguration.maxstacksizemultiplier.Value); switch (((object)Unsafe.As<ItemType, ItemType>(ref __instance.m_itemData.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString()) { case "Consumable": case "Material": case "Ammo": __instance.m_itemData.m_shared.m_maxStackSize = (int)Math.Round(num); break; } if (__instance.m_itemData.m_shared.m_movementModifier != 0f) { if (ItemDropConfiguration.disableMovementModifier.Value) { __instance.m_itemData.m_shared.m_movementModifier = 0f; } else if (ItemDropConfiguration.movementmodifier.Value != 0f) { float movementModifier = helper.applyModifierValue(__instance.m_itemData.m_shared.m_movementModifier, ItemDropConfiguration.movementmodifier.Value); __instance.m_itemData.m_shared.m_movementModifier = movementModifier; } } } } [HarmonyPatch(typeof(Beehive), "Awake")] public static class Beehive_Awake_Patch { private static void Postfix(Beehive __instance) { if (BeehiveConfiguration.enabled.Value && Configuration.modisenabled.Value) { __instance.m_maxHoney = BeehiveConfiguration.beehivemaxhoney.Value; __instance.m_secPerUnit = BeehiveConfiguration.beehiveHoneyProductionSpeed.Value; } } } [HarmonyPatch(typeof(ResourceRoot), "Awake")] public class ResourceRoot_Awake_Patch { public static void Postfix(ResourceRoot __instance) { if (SapCollectorConfiguration.enabled.Value || Configuration.modisenabled.Value) { __instance.m_maxLevel = SapCollectorConfiguration.rootmaxcapacity.Value; __instance.m_regenPerSec = SapCollectorConfiguration.rootregenpersec.Value; } } } [HarmonyPatch(typeof(SapCollector), "Awake")] public class SapCollector_Awake_Patch { public static void Postfix(SapCollector __instance) { if (SapCollectorConfiguration.enabled.Value || Configuration.modisenabled.Value) { __instance.m_secPerUnit = SapCollectorConfiguration.collectorsecperunit.Value; __instance.m_maxLevel = SapCollectorConfiguration.collectormaxcapacity.Value; } } } public static class SmelterDefinitions { public static readonly string KilnName = "$piece_charcoalkiln"; public static readonly string SmelterName = "$piece_smelter"; public static readonly string FurnaceName = "$piece_blastfurnace"; public static readonly string WindmillName = "$piece_windmill"; public static readonly string SpinningWheelName = "$piece_spinningwheel"; public static readonly string EitrRefineryName = "$piece_eitrrefinery"; } [HarmonyPatch(typeof(Smelter), "Awake")] public static class Smelter_Awake_Patch { public enum SmelterType { Unknown, Kiln, Smelter, Furnace, Windmill, SpinningWheel, EitrRefinery } private static Dictionary<int, SmelterType> smelterTypeCache = new Dictionary<int, SmelterType>(); private static void Prefix(ref Smelter __instance) { SmelterType smelterType = DetermineSmelterType(__instance); int instanceID = ((Object)__instance).GetInstanceID(); smelterTypeCache[instanceID] = smelterType; switch (smelterType) { case SmelterType.Kiln: if (SmelterConfiguration.kilnIsEnabled.Value) { __instance.m_maxOre = SmelterConfiguration.kilnMaxWood.Value; __instance.m_secPerProduct = SmelterConfiguration.kilnSpeed.Value; } break; case SmelterType.Smelter: if (SmelterConfiguration.smelterIsEnabled.Value) { __instance.m_maxOre = SmelterConfiguration.smelterMaxOre.Value; __instance.m_maxFuel = SmelterConfiguration.smelterMaxCoal.Value; __instance.m_secPerProduct = SmelterConfiguration.smelterSpeed.Value; __instance.m_fuelPerProduct = SmelterConfiguration.smelterCoalUsedPerProduct.Value; } break; case SmelterType.Furnace: if (SmelterConfiguration.furnaceIsEnabled.Value) { __instance.m_maxOre = SmelterConfiguration.furnaceMaxOre.Value; __instance.m_maxFuel = SmelterConfiguration.furnaceMaxCoal.Value; __instance.m_secPerProduct = SmelterConfiguration.furnaceSpeed.Value; __instance.m_fuelPerProduct = SmelterConfiguration.furnaceCoalUsedPerProduct.Value; } break; case SmelterType.Windmill: if (SmelterConfiguration.windmillIsEnabled.Value) { __instance.m_maxOre = SmelterConfiguration.windmillMaxBarley.Value; __instance.m_secPerProduct = SmelterConfiguration.windmillProductionSpeed.Value; } break; case SmelterType.SpinningWheel: if (SmelterConfiguration.spinningWheelIsEnabled.Value) { __instance.m_maxOre = SmelterConfiguration.spinningWheelMaxFlax.Value; __instance.m_secPerProduct = SmelterConfiguration.spinningWheelProductionSpeed.Value; } break; case SmelterType.EitrRefinery: if (SmelterConfiguration.eitrRefineryIsEnabled.Value) { __instance.m_maxOre = SmelterConfiguration.eitrRefineryMaxOre.Value; __instance.m_maxFuel = SmelterConfiguration.eitrRefineryMaxCoal.Value; __instance.m_secPerProduct = SmelterConfiguration.eitrRefinerySpeed.Value; __instance.m_fuelPerProduct = SmelterConfiguration.eitrRefineryCoalUsedPerProduct.Value; } break; } } private static SmelterType DetermineSmelterType(Smelter smelter) { string name = smelter.m_name; if (name == SmelterDefinitions.KilnName) { return SmelterType.Kiln; } if (name == SmelterDefinitions.SmelterName) { return SmelterType.Smelter; } if (name == SmelterDefinitions.FurnaceName) { return SmelterType.Furnace; } if (name == SmelterDefinitions.WindmillName) { return SmelterType.Windmill; } if (name == SmelterDefinitions.SpinningWheelName) { return SmelterType.SpinningWheel; } if (name == SmelterDefinitions.EitrRefineryName) { return SmelterType.EitrRefinery; } return SmelterType.Unknown; } public static SmelterType GetCachedSmelterType(Smelter smelter) { int instanceID = ((Object)smelter).GetInstanceID(); if (smelterTypeCache.TryGetValue(instanceID, out var value)) { return value; } return SmelterType.Unknown; } } [HarmonyPatch(typeof(Smelter), "FindCookableItem")] public static class Smelter_FindCookableItem_Transpiler { private static MethodInfo method_PreventUsingSpecificWood = AccessTools.Method(typeof(Smelter_FindCookableItem_Transpiler), "PreventUsingSpecificWood", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase original) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown if (!SmelterConfiguration.kilnIsEnabled.Value) { return instructions; } LocalVariableInfo localVariableInfo = (original?.GetMethodBody())?.LocalVariables?.FirstOrDefault((LocalVariableInfo local) => local.LocalType == typeof(ItemConversion)); if (localVariableInfo == null) { ZLog.LogWarning((object)"Smelter_FindCookableItem_Transpiler: could not find ItemConversion local; skipping patch"); return instructions; } int num = -1; List<CodeInstruction> list = instructions.ToList(); for (int num2 = 0; num2 < list.Count; num2++) { if (IsStloc(list[num2], localVariableInfo.LocalIndex)) { list.Insert(++num2, new CodeInstruction(OpCodes.Ldarg_0, (object)null)); list.Insert(++num2, LoadLocal(localVariableInfo.LocalIndex)); list.Insert(++num2, new CodeInstruction(OpCodes.Call, (object)method_PreventUsingSpecificWood)); num = num2; } else if (num != -1 && list[num2].opcode == OpCodes.Brfalse) { list.Insert(++num, new CodeInstruction(OpCodes.Brtrue, list[num2].operand)); return list.AsEnumerable(); } } ZLog.LogError((object)"Failed to apply Smelter_FindCookableItem_Transpiler"); return instructions; } private static bool IsStloc(CodeInstruction instruction, int localIndex) { switch (localIndex) { case 0: return instruction.opcode == OpCodes.Stloc_0; case 1: return instruction.opcode == OpCodes.Stloc_1; case 2: return instruction.opcode == OpCodes.Stloc_2; case 3: return instruction.opcode == OpCodes.Stloc_3; default: if (instruction.opcode == OpCodes.Stloc_S && instruction.operand is LocalBuilder localBuilder) { return localBuilder.LocalIndex == localIndex; } if (instruction.opcode == OpCodes.Stloc_S && instruction.operand is byte b) { return b == localIndex; } return false; } } private static CodeInstruction LoadLocal(int localIndex) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown return (CodeInstruction)(localIndex switch { 0 => (object)new CodeInstruction(OpCodes.Ldloc_0, (object)null), 1 => (object)new CodeInstruction(OpCodes.Ldloc_1, (object)null), 2 => (object)new CodeInstruction(OpCodes.Ldloc_2, (object)null), 3 => (object)new CodeInstruction(OpCodes.Ldloc_3, (object)null), _ => (object)new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)localIndex), }); } private static bool PreventUsingSpecificWood(Smelter smelter, ItemConversion itemConversion) { if (smelter.m_name.Equals(SmelterDefinitions.KilnName) && ((SmelterConfiguration.dontProcessFineWood.Value && itemConversion.m_from.m_itemData.m_shared.m_name.Equals(TillValhalla.WoodDefinitions.FineWoodName)) || (SmelterConfiguration.dontProcessRoundLog.Value && itemConversion.m_from.m_itemData.m_shared.m_name.Equals(TillValhalla.WoodDefinitions.RoundLogName)))) { return true; } return false; } } [HarmonyPatch(typeof(Smelter), "Spawn")] public static class Smelter_Spawn_Patch { private static bool Prefix(string ore, int stack, ref Smelter __instance) { Smelter smelter = __instance; if (!smelter.m_nview.IsOwner()) { return true; } if (__instance.m_name.Equals(SmelterDefinitions.KilnName) && SmelterConfiguration.kilnIsEnabled.Value && SmelterConfiguration.kilnAutoDeposit.Value) { return spawn(helper.Clamp(SmelterConfiguration.kilnAutoRange.Value, 1f, 50f), ignorePrivateAreaCheck: false); } if (__instance.m_name.Equals(SmelterDefinitions.SmelterName) && SmelterConfiguration.smelterIsEnabled.Value && SmelterConfiguration.smelterAutoDeposit.Value) { return spawn(helper.Clamp(SmelterConfiguration.smelterAutoRange.Value, 1f, 50f), ignorePrivateAreaCheck: false); } if (__instance.m_name.Equals(SmelterDefinitions.FurnaceName) && SmelterConfiguration.furnaceIsEnabled.Value && SmelterConfiguration.furnaceAutoDeposit.Value) { return spawn(helper.Clamp(SmelterConfiguration.furnaceAutoRange.Value, 1f, 50f), ignorePrivateAreaCheck: false); } if (__instance.m_name.Equals(SmelterDefinitions.WindmillName) && SmelterConfiguration.windmillIsEnabled.Value && SmelterConfiguration.windmillAutoDeposit.Value) { return spawn(helper.Clamp(SmelterConfiguration.windmillAutoRange.Value, 1f, 50f), ignorePrivateAreaCheck: false); } if (__instance.m_name.Equals(SmelterDefinitions.SpinningWheelName) && SmelterConfiguration.spinningWheelIsEnabled.Value && SmelterConfiguration.spinningWheelAutoDeposit.Value) { return spawn(helper.Clamp(SmelterConfiguration.spinningWheelAutoRange.Value, 1f, 50f), ignorePrivateAreaCheck: false); } if (__instance.m_name.Equals(SmelterDefinitions.EitrRefineryName) && SmelterConfiguration.eitrRefineryIsEnabled.Value && SmelterConfiguration.eitrRefineryAutoDeposit.Value) { return spawn(helper.Clamp(SmelterConfiguration.eitrRefineryAutoRange.Value, 1f, 50f), ignorePrivateAreaCheck: false); } return true; bool spawn(float autoDepositRange, bool ignorePrivateAreaCheck) { List<Container> nearbyChests = InventoryAssistant.GetNearbyChests(((Component)smelter).gameObject, autoDepositRange, !ignorePrivateAreaCheck); ItemDrop comp; if (nearbyChests.Count != 0) { if (autoDepositRange > 50f) { autoDepositRange = 50f; } else if (autoDepositRange < 1f) { autoDepositRange = 1f; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(((Object)((Component)smelter.GetItemConversion(ore).m_to).gameObject).name); ZNetView.m_forceDisableInit = true; GameObject val = Object.Instantiate<GameObject>(itemPrefab); ZNetView.m_forceDisableInit = false; comp = val.GetComponent<ItemDrop>(); comp.m_itemData.m_stack = stack; bool result = spawnNearbyChest(mustHaveItem: true); Object.Destroy((Object)(object)val); return result; } return true; bool spawnNearbyChest(bool mustHaveItem) { //IL_006a: 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_0088: 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) foreach (Container item in nearbyChests) { Inventory inventory = item.GetInventory(); if ((!mustHaveItem || inventory.HaveItem(comp.m_itemData.m_shared.m_name, true)) && inventory.AddItem(comp.m_itemData)) { smelter.m_produceEffects.Create(((Component)smelter).transform.position, ((Component)smelter).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)); InventoryAssistant.ConveyContainerToNetwork(item); return false; } } if (mustHaveItem) { return spawnNearbyChest(mustHaveItem: false); } return true; } } } } [HarmonyPatch(typeof(Smelter), "UpdateSmelter")] public static class Smelter_UpdateSmelter_Patch { private static readonly MethodInfo method_RPC_AddFuel = AccessTools.GetDeclaredMethods(typeof(Smelter)).FirstOrDefault((MethodInfo m) => m.Name == "RPC_AddFuel"); private static readonly MethodInfo method_RPC_AddOre = AccessTools.GetDeclaredMethods(typeof(Smelter)).FirstOrDefault((MethodInfo m) => m.Name == "RPC_AddOre"); private static void Prefix(Smelter __instance) { if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || (Object)(object)__instance.m_nview == (Object)null || !__instance.m_nview.IsOwner()) { return; } Stopwatch stopwatch = GameObjectAssistant.GetStopwatch(((Component)__instance).gameObject); if (stopwatch.IsRunning && stopwatch.ElapsedMilliseconds < 1000) { return; } stopwatch.Restart(); Smelter_Awake_Patch.SmelterType cachedSmelterType = Smelter_Awake_Patch.GetCachedSmelterType(__instance); float num = 0f; bool flag = false; bool flag2 = false; switch (cachedSmelterType) { default: return; case Smelter_Awake_Patch.SmelterType.Kiln: if (!SmelterConfiguration.kilnIsEnabled.Value || !SmelterConfiguration.kilnAutoFuel.Value) { return; } flag2 = true; num = SmelterConfiguration.kilnAutoRange.Value; break; case Smelter_Awake_Patch.SmelterType.Smelter: if (!SmelterConfiguration.smelterIsEnabled.Value || !SmelterConfiguration.smelterAutoFuel.Value) { return; } num = SmelterConfiguration.smelterAutoRange.Value; break; case Smelter_Awake_Patch.SmelterType.Furnace: if (!SmelterConfiguration.furnaceIsEnabled.Value || !SmelterConfiguration.furnaceAutoFuel.Value) { return; } num = SmelterConfiguration.furnaceAutoRange.Value; break; case Smelter_Awake_Patch.SmelterType.Windmill: if (!SmelterConfiguration.windmillIsEnabled.Value || !SmelterConfiguration.windmillAutoFuel.Value) { return; } num = SmelterConfiguration.windmillAutoRange.Value; break; case Smelter_Awake_Patch.SmelterType.SpinningWheel: if (!SmelterConfiguration.spinningWheelIsEnabled.Value || !SmelterConfiguration.spinningWheelAutoFuel.Value) { return; } num = SmelterConfiguration.eitrRefineryAutoRange.Value; break; case Smelter_Awake_Patch.SmelterType.EitrRefinery: if (!SmelterConfiguration.eitrRefineryIsEnabled.Value || !SmelterConfiguration.eitrRefineryAutoFuel.Value) { return; } num = SmelterConfiguration.eitrRefineryAutoRange.Value; break; } float range = helper.Clamp(num, 1f, 50f); int num2 = __instance.m_maxOre - __instance.GetQueueSize(); int num3 = __instance.m_maxFuel - (int)Math.Ceiling(__instance.GetFuel()); if (Object.op_Implicit((Object)(object)__instance.m_fuelItem) && num3 > 0) { ItemData itemData = __instance.m_fuelItem.m_itemData; int num4 = InventoryAssistant.RemoveItemInAmountFromAllNearbyChests(((Component)__instance).gameObject, range, itemData, num3, !flag); for (int i = 0; i < num4; i++) { InvokeAddFuelRpc(__instance); } if (num4 > 0 && Configuration.enableDebugLogging != null && Configuration.enableDebugLogging.Value) { ZLog.Log((object)("Added " + num4 + " fuel(" + itemData.m_shared.m_name + ") in " + __instance.m_name)); } } if (num2 <= 0) { return; } List<Container> nearbyChests = InventoryAssistant.GetNearbyChests(((Component)__instance).gameObject, range); foreach (Container item in nearbyChests) { foreach (ItemConversion item2 in __instance.m_conversion) { if (flag2) { if ((SmelterConfiguration.dontProcessFineWood.Value && item2.m_from.m_itemData.m_shared.m_name.Equals(TillValhalla.WoodDefinitions.FineWoodName)) || (SmelterConfiguration.dontProcessRoundLog.Value && item2.m_from.m_itemData.m_shared.m_name.Equals(TillValhalla.WoodDefinitions.RoundLogName))) { continue; } int num5 = ((SmelterConfiguration.kilnStopAutoFuelThreshold.Value >= 0) ? SmelterConfiguration.kilnStopAutoFuelThreshold.Value : 0); if (num5 > 0 && InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(nearbyChests), item2.m_to.m_itemData) >= num5) { return; } } ItemData itemData2 = item2.m_from.m_itemData; int num6 = InventoryAssistant.RemoveItemFromChest(item, itemData2, num2); if (num6 > 0) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(((Object)((Component)item2.m_from).gameObject).name); for (int j = 0; j < num6; j++) { InvokeAddOreRpc(__instance, ((Object)itemPrefab).name); } num2 -= num6; if (num6 > 0 && Configuration.enableDebugLogging != null && Configuration.enableDebugLogging.Value) { ZLog.Log((object)("Added " + num6 + " ores(" + itemData2.m_shared.m_name + ") in " + __instance.m_name)); } if (num2 == 0) { return; } } } } } private static void InvokeAddFuelRpc(Smelter smelter) { smelter.m_nview.InvokeRPC("RPC_AddFuel", BuildRpcPayload(method_RPC_AddFuel, null)); } private static void InvokeAddOreRpc(Smelter smelter, string oreName) { smelter.m_nview.InvokeRPC("RPC_AddOre", BuildRpcPayload(method_RPC_AddOre, oreName)); } private static object[] BuildRpcPayload(MethodInfo rpcMethod, string oreName) { if (rpcMethod == null) { if (oreName != null) { return new object[1] { oreName }; } return new object[0]; } List<object> list = new List<object>(); bool flag = false; ParameterInfo[] parameters = rpcMethod.GetParameters(); foreach (ParameterInfo parameterInfo in parameters) { if (!(parameterInfo.ParameterType == typeof(long))) { if (!flag && oreName != null && parameterInfo.ParameterType == typeof(string)) { list.Add(oreName); flag = true; } else { list.Add(GetDefaultRpcValue(parameterInfo.ParameterType)); } } } return list.ToArray(); } private static object GetDefaultRpcValue(Type parameterType) { if (parameterType == typeof(bool)) { return false; } if (parameterType == typeof(int)) { return 1; } if (parameterType == typeof(float)) { return 1f; } if (parameterType == typeof(string)) { return string.Empty; } if (!parameterType.IsValueType) { return null; } return Activator.CreateInstance(parameterType); } } [HarmonyPatch(typeof(ZSFX), "Awake")] public static class ZSFX_Awake_Patch { public static void Postfix(ZSFX __instance) { if (!Configuration.modisenabled.Value && !ZSFXConfiguration.enabled.Value) { return; } string zSFXName = GetZSFXName(__instance); if (ZSFXConfiguration.debugMode.Value) { Logger.LogInfo((object)("Check SFX:" + zSFXName)); } Dictionary<string, Dictionary<string, AudioClip>> sFXList = TillValhalla.SFXList; if (sFXList != null && sFXList.TryGetValue(zSFXName, out var value)) { if (ZSFXConfiguration.debugMode.Value) { Logger.LogInfo((object)("replacing SFX list by name: " + zSFXName)); } __instance.m_audioClips = value.Values.ToArray(); } else { if (TillValhalla.SFX == null || __instance.m_audioClips == null) { return; } for (int i = 0; i < __instance.m_audioClips.Length; i++) { if ((Object)(object)__instance.m_audioClips[i] == (Object)null) { continue; } if (ZSFXConfiguration.debugMode.Value) { Logger.LogInfo((object)("checking SFX: " + zSFXName + ", clip: " + ((Object)__instance.m_audioClips[i]).name)); } if (TillValhalla.SFX.TryGetValue(((Object)__instance.m_audioClips[i]).name, out var value2)) { if (ZSFXConfiguration.debugMode.Value) { Logger.LogInfo((object)("replacing SFX: " + zSFXName + ", clip: " + ((Object)__instance.m_audioClips[i]).name)); } __instance.m_audioClips[i] = value2; } } } } public static string GetZSFXName(ZSFX zfx) { string name = ((Object)zfx).name; char[] anyOf = new char[2] { '(', ' ' }; int num = name.IndexOfAny(anyOf); if (num != -1) { return name.Remove(num); } return name; } } public static class Waterproof { [HarmonyPatch(typeof(EnvMan), "IsWet")] public class EnvMan_Patch { public static bool Postfix(bool __result) { if (!PlayerConfiguration.WetFromRain.Value) { __result = iswet; } return __result; } } [HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")] public static class Player_UpdateEnvStats_Patch { public static bool Prefix() { AddingStatFromEnv++; return true; } public static void Postfix(Player __instance) { AddingStatFromEnv--; } } [HarmonyPatch] public static class SEMan_RemoveWetFromRain_Patch { private static MethodBase TargetMethod() { return AccessTools.GetDeclaredMethods(typeof(SEMan)).FirstOrDefault((MethodInfo m) => m.Name == "AddStatusEffect" && m.GetParameters().Length != 0 && m.GetParameters()[0].ParameterType == typeof(int)); } public static bool Prefix(SEMan __instance, int __0) { if (!PlayerConfiguration.WetFromRain.Value && AddingStatFromEnv > 0 && __instance.m_character.IsPlayer() && __0 == -1273337594 && iswet) { retur