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 NaNNaVH v0.13.1
NaNNaVH/NaNNaVH.dll
Decompiled 2 days agousing 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; using System.Security.Permissions; using System.Threading.Tasks; using System.Timers; using BepInEx; using HarmonyLib; using NaNNaVH.slib; using Splatform; using Steamworks; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("NaNNaVH")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("NaNNaVH")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("61d604dd-aa6b-408a-94bb-3ed50aa0844f")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] public static class ZNetExtensions { public enum ZNetInstanceType { Local, Client, Server } public static bool IsLocalInstance(this ZNet znet) { return znet.IsServer() && !znet.IsDedicated(); } public static bool IsClientInstance(this ZNet znet) { return !znet.IsServer() && !znet.IsDedicated(); } public static bool IsServerInstance(this ZNet znet) { return znet.IsServer() && znet.IsDedicated(); } public static ZNetInstanceType GetInstanceType(this ZNet znet) { if (znet.IsLocalInstance()) { return ZNetInstanceType.Local; } if (znet.IsClientInstance()) { return ZNetInstanceType.Client; } return ZNetInstanceType.Server; } } namespace NaNNaVH { [BepInPlugin("nb.wackjob.NaNNaVH", "NaNNaVH", "0.13.1")] public class NaNNaVH : BaseUnityPlugin { public static Timer mapSyncSaveTimer = new Timer(TimeSpan.FromMinutes(5.0).TotalMilliseconds); public static readonly string nVHDataDirectoryPath; public static Harmony harmony; private void Awake() { harmony.PatchAll(); if (!Directory.Exists(nVHDataDirectoryPath)) { Directory.CreateDirectory(nVHDataDirectoryPath); } if (ZNet.m_isServer) { mapSyncSaveTimer.AutoReset = true; mapSyncSaveTimer.Elapsed += delegate { MapSync.SaveMapDataToDisk(); }; } } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } static NaNNaVH() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown string bepInExRootPath = Paths.BepInExRootPath; char directorySeparatorChar = Path.DirectorySeparatorChar; nVHDataDirectoryPath = bepInExRootPath + directorySeparatorChar + "nvh-data"; harmony = new Harmony("nb.wackjob.NaNNaVH"); } } } namespace NaNNaVH.slib { public class MapSync { public class MapRange { public int StartingX; public int EndingX; public int Y; } public static bool[] ServerMapData; public static bool ShouldSyncOnSpawn = true; public static void RPC_nVHMapSync(long sender, ZPackage mapPkg) { if (ZNet.m_isServer) { if (sender == ZRoutedRpc.instance.GetServerPeerID() || mapPkg == null) { return; } int num = mapPkg.ReadInt(); if (num > 0) { for (int i = 0; i < num; i++) { MapRange mapRange = mapPkg.ReadnVHMapRange(); for (int j = mapRange.StartingX; j < mapRange.EndingX; j++) { ServerMapData[mapRange.Y * Minimap.instance.m_textureSize + j] = true; } } ZLog.Log((object)$"Received {num} map ranges from peer #{sender}."); nVHAck.SendAck(sender); } if (!mapPkg.ReadBool()) { return; } List<MapRange> list = ExplorationDataToMapRanges(ServerMapData); List<ZPackage> list2 = ChunkMapData(list); foreach (ZPackage item in list2) { RpcData rpcData = new RpcData(); rpcData.Name = "nVHMapSync"; rpcData.Payload = new object[1] { item }; rpcData.Target = 0L; RpcQueue.Enqueue(rpcData); } ZLog.Log((object)$"-------------------------- Packages: {list2.Count}"); ZLog.Log((object)$"Sent map updates to all clients ({list.Count} map ranges, {list2.Count} chunks)"); } else { if (sender != ZRoutedRpc.instance.GetServerPeerID()) { return; } if (mapPkg == null) { ZLog.LogWarning((object)"Warning: Got empty map sync package from server."); return; } int num2 = mapPkg.ReadInt(); if (num2 > 0) { for (int k = 0; k < num2; k++) { MapRange mapRange2 = mapPkg.ReadnVHMapRange(); for (int l = mapRange2.StartingX; l < mapRange2.EndingX; l++) { Minimap.instance.Explore(l, mapRange2.Y); } } Minimap.instance.m_fogTexture.Apply(); ZLog.Log((object)$"I got {num2} map ranges from the server!"); nVHAck.SendAck(sender); } else { ZLog.Log((object)"Server has no explored areas to sync, continuing."); } } } public static void SendMapToServer() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown ZLog.Log((object)"-------------------- SENDING NVHMAPSYNC DATA"); bool[] array = new bool[Minimap.instance.m_explored.Count]; Minimap.instance.m_explored.CopyTo(array, 0); List<MapRange> list = ExplorationDataToMapRanges(array); if (list.Count == 0) { ZPackage val = new ZPackage(); val.Write(0); val.Write(true); ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "nVHMapSync", new object[1] { val }); return; } List<ZPackage> list2 = ChunkMapData(list); foreach (ZPackage item in list2) { RpcData rpcData = new RpcData(); rpcData.Name = "nVHMapSync"; rpcData.Payload = new object[1] { item }; rpcData.Target = ZRoutedRpc.instance.GetServerPeerID(); RpcQueue.Enqueue(rpcData); } ZLog.Log((object)$"Sent my map data to the server ({list.Count} map ranges, {list2.Count} chunks)"); } public static void LoadMapDataFromDisk() { if (ServerMapData == null) { return; } string nVHDataDirectoryPath = NaNNaVH.nVHDataDirectoryPath; char directorySeparatorChar = Path.DirectorySeparatorChar; if (!File.Exists(nVHDataDirectoryPath + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat")) { return; } try { string nVHDataDirectoryPath2 = NaNNaVH.nVHDataDirectoryPath; directorySeparatorChar = Path.DirectorySeparatorChar; string text = File.ReadAllText(nVHDataDirectoryPath2 + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat"); string[] array = text.Split(new char[1] { ',' }); string[] array2 = array; foreach (string s in array2) { if (int.TryParse(s, out var result)) { ServerMapData[result] = true; } } ZLog.Log((object)$"Loaded {array.Length} map points from disk."); } catch (Exception ex) { ZLog.LogError((object)"Failed to load synchronized map data."); ZLog.LogError((object)ex); } } public static void SaveMapDataToDisk() { if (ServerMapData == null) { return; } List<int> list = new List<int>(); for (int i = 0; i < Minimap.instance.m_textureSize; i++) { for (int j = 0; j < Minimap.instance.m_textureSize; j++) { if (ServerMapData[i * Minimap.instance.m_textureSize + j]) { list.Add(i * Minimap.instance.m_textureSize + j); } } } if (list.Count > 0) { string nVHDataDirectoryPath = NaNNaVH.nVHDataDirectoryPath; char directorySeparatorChar = Path.DirectorySeparatorChar; File.Delete(nVHDataDirectoryPath + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat"); string nVHDataDirectoryPath2 = NaNNaVH.nVHDataDirectoryPath; directorySeparatorChar = Path.DirectorySeparatorChar; File.WriteAllText(nVHDataDirectoryPath2 + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat", string.Join(",", list)); ZLog.Log((object)$"Saved {list.Count} map points to disk."); } } private static List<MapRange> ExplorationDataToMapRanges(bool[] explorationData) { List<MapRange> list = new List<MapRange>(); for (int i = 0; i < Minimap.instance.m_textureSize; i++) { int num = -1; int num2 = -1; for (int j = 0; j < Minimap.instance.m_textureSize; j++) { if (explorationData[i * Minimap.instance.m_textureSize + j] && num == -1 && num2 == -1) { num = j; } else if (!explorationData[i * Minimap.instance.m_textureSize + j] && num > -1 && num2 == -1) { num2 = j - 1; } else if (num > -1 && num2 > -1) { list.Add(new MapRange { StartingX = num, EndingX = num2, Y = i }); num = -1; num2 = -1; } } if (num > -1 && num2 == -1) { list.Add(new MapRange { StartingX = num, EndingX = Minimap.instance.m_textureSize, Y = i }); } } return list; } private static List<ZPackage> ChunkMapData(List<MapRange> mapData, int chunkSize = 10000) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown if (mapData == null || mapData.Count == 0) { return null; } List<List<MapRange>> list = mapData.ChunkBy(chunkSize); List<ZPackage> list2 = new List<ZPackage>(); foreach (List<MapRange> item in list) { ZPackage val = new ZPackage(); val.Write(item.Count); foreach (MapRange item2 in item) { val.WritenVHMapRange(item2); } if (item == list.Last()) { val.Write(true); } else { val.Write(false); } list2.Add(val); } return list2; } } public static class ListExtensions { public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize) { return (from x in source.Select((T x, int i) => new { Index = i, Value = x }) group x by x.Index / chunkSize into x select x.Select(v => v.Value).ToList()).ToList(); } } public class nVHAck { public static void RPC_nVHAck(long sender) { RpcQueue.GotAck(); } public static void SendAck(long target) { ZRoutedRpc.instance.InvokeRoutedRPC(target, "nVHAck", Array.Empty<object>()); } } public class RpcData { public string Name; public long Target = 0L; public object[] Payload; } public static class RpcQueue { private static Queue<RpcData> _rpcQueue = new Queue<RpcData>(); private static bool _ack = true; public static void Enqueue(RpcData rpc) { _rpcQueue.Enqueue(rpc); } public static bool SendNextRpc() { if (_rpcQueue.Count == 0 || !_ack) { return false; } RpcData rpcData = _rpcQueue.Dequeue(); if (Utility.IsNullOrWhiteSpace(rpcData.Name) || rpcData.Payload == null) { return false; } ZRoutedRpc.instance.InvokeRoutedRPC(rpcData.Target, rpcData.Name, rpcData.Payload); _ack = false; return true; } public static void GotAck() { _ack = true; } } internal static class sFunc { 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 IEnumerable<CodeInstruction> StripForcedCase(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Callvirt) { MethodBase methodBase = list[i].operand as MethodBase; if (methodBase != null && (methodBase.Name == "ToLowerInvariant" || methodBase.Name == "ToUpper")) { list.RemoveRange(i - 1, 3); i -= 2; } } } return list; } 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 versionCheck { [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class PatchZNetOnNewConnection { private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { ZLog.Log((object)("========== Server Client connected by the name of: " + peer.m_playerName)); } } } public static void ReceiveClientVersion(long sender, string clientVersion) { string modVersion = GetModVersion(); ZNetPeer val = FindPeerBySenderID(sender); if (val != null && clientVersion != modVersion) { ZLog.Log((object)("========== Version mismatch. Kicking peer: " + ((object)val).ToString())); ZNet.instance.InternalKick(val); } } public static ZNetPeer FindPeerBySenderID(long senderID) { foreach (ZNetPeer peer in ZNet.instance.m_peers) { if (peer.m_uid == senderID) { return peer; } } return null; } public static string GetModVersion() { BepInPlugin customAttribute = ((MemberInfo)typeof(NaNNaVH)).GetCustomAttribute<BepInPlugin>(); return (customAttribute != null) ? customAttribute.Version.ToString() : "Unknown"; } } public static class ZDODataBuffer { [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private class StartBufferingOnNewConnection { private static void Postfix(ZNet __instance, ZNetPeer peer) { if (!__instance.IsServer()) { peer.m_rpc.Register<ZPackage>("ZDOData", (Action<ZRpc, ZPackage>)delegate(ZRpc _, ZPackage package) { packageBuffer.Add(package); }); } } } [HarmonyPatch(typeof(ZNet), "Shutdown")] private class ClearPackageBufferOnShutdown { private static void Postfix() { packageBuffer.Clear(); } } [HarmonyPatch(typeof(ZDOMan), "AddPeer")] private class EvaluateBufferedPackages { private static void Postfix(ZDOMan __instance, ZNetPeer netPeer) { foreach (ZPackage item in packageBuffer) { __instance.RPC_ZDOData(netPeer.m_rpc, item); } packageBuffer.Clear(); } } private static readonly List<ZPackage> packageBuffer = new List<ZPackage>(); } public static class ZPackageExtensions { public static MapSync.MapRange ReadnVHMapRange(this ZPackage pkg) { return new MapSync.MapRange { StartingX = pkg.m_reader.ReadInt32(), EndingX = pkg.m_reader.ReadInt32(), Y = pkg.m_reader.ReadInt32() }; } public static void WritenVHMapRange(this ZPackage pkg, MapSync.MapRange mapRange) { pkg.m_writer.Write(mapRange.StartingX); pkg.m_writer.Write(mapRange.EndingX); pkg.m_writer.Write(mapRange.Y); } } } namespace NaNNaVH.mods { [HarmonyPatch] internal static class AreaRepair { [HarmonyPatch(typeof(Player), "UpdatePlacement")] public static class Player_UpdatePlacement_Transpiler { private static readonly MethodInfo method_Player_Repair = AccessTools.Method(typeof(Player), "Repair", (Type[])null, (Type[])null); private static readonly FieldRef<Player, Piece> field_Player_m_hoveringPiece = AccessTools.FieldRefAccess<Player, Piece>("m_hoveringPiece"); private static readonly MethodInfo method_RepairNearby = AccessTools.Method(typeof(Player_UpdatePlacement_Transpiler), "RepairNearby", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], method_Player_Repair)) { list[i].operand = method_RepairNearby; } } return list.AsEnumerable(); } public static void RepairNearby(Player instance, ItemData toolItem, Piece _1) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) Piece hoveringPiece = instance.GetHoveringPiece(); Vector3 val = (((Object)(object)hoveringPiece != (Object)null) ? ((Component)hoveringPiece).transform.position : ((Component)instance).transform.position); List<Piece> list = new List<Piece>(); Piece.GetAllPiecesInRadius(val, m_repair_radius, list); m_repair_count = 0; Piece val2 = field_Player_m_hoveringPiece.Invoke(instance); MethodInfo methodInfo = AccessTools.Method(typeof(Player), "Repair", (Type[])null, (Type[])null); foreach (Piece item in list) { if (!((Character)instance).HaveStamina(toolItem.m_shared.m_attack.m_attackStamina) || (toolItem.m_shared.m_useDurability && toolItem.m_durability <= 0f)) { break; } field_Player_m_hoveringPiece.Invoke(instance) = item; methodInfo.Invoke(instance, new object[2] { toolItem, _1 }); field_Player_m_hoveringPiece.Invoke(instance) = val2; } if (m_repair_count > 0) { ((Character)instance).Message((MessageType)1, $"{m_repair_count} pieces repaired", 0, (Sprite)null, false); } } } [HarmonyPatch(typeof(Player), "Repair")] public static class Player_Repair_Transpiler { private static readonly MethodInfo method_Character_Message = AccessTools.Method(typeof(Character), "Message", (Type[])null, (Type[])null); private static readonly MethodInfo method_MessageNoop = AccessTools.Method(typeof(Player_Repair_Transpiler), "MessageNoop", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(instructions); bool flag = true; for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], method_Character_Message)) { list[i].operand = method_MessageNoop; list.Insert(i++, new CodeInstruction(flag ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0, (object)null)); flag = false; } } return list.AsEnumerable(); } public static void MessageNoop(Character _0, MessageType _1, string _2, int _3, Sprite _4, int repaired) { m_repair_count += repaired; } } private static int m_repair_count; private static readonly float m_repair_radius = 10f; } internal class AutoFuel { [HarmonyPatch(typeof(Container), "Awake")] private static class ContainerAwakePatch { private static void Postfix(Container __instance, ZNetView ___m_nview) { AddContainer(__instance, ___m_nview); } } [HarmonyPatch(typeof(Container), "OnDestroyed")] private static class ContainerOnDestroyedPatch { private static void Prefix(Container __instance) { ContainerList.Remove(__instance); } } [HarmonyPatch(typeof(Smelter), "Awake")] public class BlastFurnacePatch { private static void Prefix(ref Smelter __instance) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Expected O, but got Unknown if (__instance.m_name != "$piece_blastfurnace") { return; } ObjectDB instance = ObjectDB.instance; List<ItemDrop> allItems = instance.GetAllItems((ItemType)1, ""); foreach (ItemDrop item in allItems) { if (Enumerable.Contains(metals.Keys, item.m_itemData.m_shared.m_name)) { metals[item.m_itemData.m_shared.m_name] = item; } } List<ItemConversion> list = new List<ItemConversion> { new ItemConversion { m_from = metals["$item_copperore"], m_to = metals["$item_copper"] }, new ItemConversion { m_from = metals["$item_tinore"], m_to = metals["$item_tin"] }, new ItemConversion { m_from = metals["$item_ironscrap"], m_to = metals["$item_iron"] }, new ItemConversion { m_from = metals["$item_silverore"], m_to = metals["$item_silver"] }, new ItemConversion { m_from = metals["$item_copperscrap"], m_to = metals["$item_copper"] } }; foreach (ItemConversion item2 in list) { __instance.m_conversion.Add(item2); } } } [HarmonyPatch(typeof(Smelter), "UpdateSmelter")] private static class Smelter_FixedUpdate_Patch { private static void Postfix(Smelter __instance, ZNetView ___m_nview) { if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && !((Object)(object)___m_nview == (Object)null) && ___m_nview.IsOwner()) { if ((double)(Time.time - lastFuel) < 0.1) { fuelCount++; RefuelSmelter(__instance, ___m_nview, fuelCount * 33); } else { fuelCount = 0; lastFuel = Time.time; RefuelSmelter(__instance, ___m_nview, 0); } } } } public static float lastFuel; public static int fuelCount; internal static string fuelDisallowTypes = "RoundLog,FineWood"; internal static string oreDisallowTypes = "RoundLog,FineWood"; internal static bool distributedFilling = true; internal static readonly List<Container> ContainerList = new List<Container>(); private static Dictionary<string, ItemDrop> metals = new Dictionary<string, ItemDrop> { { "$item_copperore", null }, { "$item_copper", null }, { "$item_ironscrap", null }, { "$item_iron", null }, { "$item_tinore", null }, { "$item_tin", null }, { "$item_silverore", null }, { "$item_silver", null }, { "$item_copperscrap", null } }; private void OnDestroy() { } public static string GetPrefabName(string name) { char[] anyOf = new char[2] { '(', ' ' }; int num = name.IndexOfAny(anyOf); return (num >= 0) ? name.Substring(0, num) : name; } public static void AddContainer(Container container, ZNetView nview) { try { if (container.GetInventory() != null && ((nview != null) ? nview.GetZDO() : null) != null && (((Object)container).name.StartsWith("piece_", StringComparison.Ordinal) || ((Object)container).name.StartsWith("Container", StringComparison.Ordinal) || nview.GetZDO().GetLong(StringExtensionMethods.GetStableHashCode("creator"), 0L) != 0)) { ContainerList.Add(container); } } catch { } } public static List<Container> GetNearbyContainers(Vector3 center, float range) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) List<Container> list = new List<Container>(); foreach (Container item in ContainerList.Where((Container container) => (Object)(object)container != (Object)null && (Object)(object)((Component)container).GetComponentInParent<Piece>() != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)((container != null) ? ((Component)container).transform : null) != (Object)null && container.GetInventory() != null && (range <= 0f || Vector3.Distance(center, ((Component)container).transform.position) < range) && container.CheckAccess(Player.m_localPlayer.GetPlayerID()) && !container.IsInUse())) { Vector3 position = ((Component)item).transform.position; if (PrivateArea.CheckAccess(position, 0f, false, false)) { if (!PrivateArea.InsideFactionArea(((Component)item).transform.position, (Faction)0)) { item.Load(); list.Add(item); } else { item.Load(); list.Add(item); } } } return list; } public static async void RefuelSmelter(Smelter __instance, ZNetView ___m_nview, int delay) { await Task.Delay(delay); if (!Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)___m_nview) || !___m_nview.IsValid()) { return; } int maxOre = __instance.m_maxOre - Traverse.Create((object)__instance).Method("GetQueueSize", Array.Empty<object>()).GetValue<int>(); int maxFuel = __instance.m_maxFuel - Mathf.CeilToInt(___m_nview.GetZDO().GetFloat("fuel", 0f)); List<Container> nearbyOreContainers = GetNearbyContainers(((Component)__instance).transform.position, 10f); List<Container> nearbyFuelContainers = GetNearbyContainers(((Component)__instance).transform.position, 10f); if (((Object)__instance).name.Contains("charcoal_kiln")) { string outputName = __instance.m_conversion[0].m_to.m_itemData.m_shared.m_name; int maxOutput = 50 - Traverse.Create((object)__instance).Method("GetQueueSize", Array.Empty<object>()).GetValue<int>(); foreach (Container c in nearbyOreContainers) { List<ItemData> itemList = new List<ItemData>(); c.GetInventory().GetAllItems(outputName, itemList); foreach (ItemData outputItem in itemList) { if (outputItem != null) { maxOutput -= outputItem.m_stack; } } } if (maxOutput < 0) { maxOutput = 0; } if (maxOre > maxOutput) { maxOre = maxOutput; } } bool fueled = false; bool ored = false; Vector3 position = ((Component)__instance).transform.position + Vector3.up; Collider[] array = Physics.OverlapSphere(position, 10f); foreach (Collider collider in array) { if (!Object.op_Implicit((Object)(object)((collider != null) ? collider.attachedRigidbody : null))) { continue; } ItemDrop item = ((Component)collider.attachedRigidbody).GetComponent<ItemDrop>(); int num; if (item == null) { num = 1; } else { ZNetView component = ((Component)item).GetComponent<ZNetView>(); num = ((((component != null) ? new bool?(component.IsValid()) : ((bool?)null)) != true) ? 1 : 0); } if (num != 0) { continue; } string name = GetPrefabName(((Object)((Component)item).gameObject).name); foreach (ItemConversion itemConversion in __instance.m_conversion) { if (ored) { break; } if (!(item.m_itemData.m_shared.m_name == itemConversion.m_from.m_itemData.m_shared.m_name) || maxOre <= 0 || oreDisallowTypes.Split(new char[1] { ',' }).Contains(name)) { continue; } int amount = Mathf.Min(item.m_itemData.m_stack, maxOre); maxOre -= amount; for (int j = 0; j < amount; j++) { if (item.m_itemData.m_stack <= 1) { if (___m_nview.GetZDO() == null) { Object.Destroy((Object)(object)((Component)item).gameObject); } else { ZNetScene.instance.Destroy(((Component)item).gameObject); } ___m_nview.InvokeRPC("RPC_AddOre", new object[1] { name }); if (distributedFilling) { ored = true; } break; } ItemData itemData = item.m_itemData; itemData.m_stack--; ___m_nview.InvokeRPC("RPC_AddOre", new object[1] { name }); Traverse.Create((object)item).Method("Save", Array.Empty<object>()).GetValue(); if (distributedFilling) { ored = true; } } } if (!Object.op_Implicit((Object)(object)__instance.m_fuelItem) || !(item.m_itemData.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name) || maxFuel <= 0 || fueled || fuelDisallowTypes.Split(new char[1] { ',' }).Contains(name)) { continue; } int amount2 = Mathf.Min(item.m_itemData.m_stack, maxFuel); maxFuel -= amount2; for (int k = 0; k < amount2; k++) { if (item.m_itemData.m_stack <= 1) { if (___m_nview.GetZDO() == null) { Object.Destroy((Object)(object)((Component)item).gameObject); } else { ZNetScene.instance.Destroy(((Component)item).gameObject); } ___m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); if (distributedFilling) { fueled = true; } break; } ItemData itemData2 = item.m_itemData; itemData2.m_stack--; ___m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); Traverse.Create((object)item).Method("Save", Array.Empty<object>()).GetValue(); if (distributedFilling) { fueled = true; break; } } } foreach (Container c2 in nearbyOreContainers) { foreach (ItemConversion itemConversion2 in __instance.m_conversion) { if (ored) { break; } List<ItemData> itemList2 = new List<ItemData>(); c2.GetInventory().GetAllItems(itemConversion2.m_from.m_itemData.m_shared.m_name, itemList2); foreach (ItemData oreItem in itemList2) { if (oreItem != null && maxOre > 0 && !oreDisallowTypes.Split(new char[1] { ',' }).Contains(((Object)oreItem.m_dropPrefab).name)) { maxOre--; object[] array2 = new object[1]; GameObject dropPrefab = oreItem.m_dropPrefab; array2[0] = ((dropPrefab != null) ? ((Object)dropPrefab).name : null); ___m_nview.InvokeRPC("RPC_AddOre", array2); c2.GetInventory().RemoveItem(itemConversion2.m_from.m_itemData.m_shared.m_name, 1, -1, true); typeof(Container).GetMethod("Save", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(c2, new object[0]); typeof(Inventory).GetMethod("Changed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(c2.GetInventory(), new object[0]); if (distributedFilling) { ored = true; break; } } } } } foreach (Container c3 in nearbyFuelContainers) { if (!Object.op_Implicit((Object)(object)__instance.m_fuelItem) || maxFuel <= 0 || fueled) { break; } List<ItemData> itemList3 = new List<ItemData>(); c3.GetInventory().GetAllItems(__instance.m_fuelItem.m_itemData.m_shared.m_name, itemList3); foreach (ItemData fuelItem in itemList3) { if (fuelItem == null) { continue; } maxFuel--; if (!fuelDisallowTypes.Split(new char[1] { ',' }).Contains(((Object)fuelItem.m_dropPrefab).name)) { ___m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); c3.GetInventory().RemoveItem(__instance.m_fuelItem.m_itemData.m_shared.m_name, 1, -1, true); typeof(Container).GetMethod("Save", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(c3, new object[0]); typeof(Inventory).GetMethod("Changed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(c3.GetInventory(), new object[0]); if (distributedFilling) { fueled = true; break; } } } } } } [HarmonyPatch(typeof(Player), "Update")] public static class PlayerUpdatePatch { private static void Postfix(Player __instance) { if ((Object)(object)Player.m_localPlayer != (Object)null) { ApplyModerBuff(__instance); } } private static void ApplyModerBuff(Player player) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown SEMan sEMan = ((Character)player).GetSEMan(); int stableHashCode = StringExtensionMethods.GetStableHashCode("GP_Moder"); if (sEMan != null && !sEMan.HaveStatusEffect(stableHashCode)) { StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(stableHashCode); statusEffect.m_ttl = 0f; statusEffect.m_startMessage = ""; statusEffect.m_startEffects = new EffectList(); sEMan.AddStatusEffect(statusEffect, false, 0, 0f, (short)(-1)); } } } [HarmonyPatch(typeof(ItemStand), "IsGuardianPowerActive")] public static class ItemStandIsGuardianPowerActivePatch { private static void Postfix(ItemStand __instance, ref bool __result, Humanoid user) { if (((Object)__instance.m_guardianPower).name == "GP_Moder") { __result = true; } } } public static class PlayerExtensions { public static SEMan GetSEMan(this Player player) { return ((Component)player).GetComponent<SEMan>(); } public static bool HaveStatusEffect(this SEMan seman, int effectHash) { foreach (StatusEffect statusEffect in seman.m_statusEffects) { if (statusEffect.m_nameHash == effectHash) { return true; } } return false; } public static void AddStatusEffect(this SEMan seman, StatusEffect effect) { seman.AddStatusEffect(effect, false, 0, 0f, (short)(-1)); } } [HarmonyPatch(typeof(Terminal))] public static class Chat_MixedCase_Terminal_Patch { [HarmonyPatch("AddString", new Type[] { typeof(string), typeof(string), typeof(Type), typeof(bool) })] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> AddString_Transpiler(IEnumerable<CodeInstruction> instructions) { return sFunc.StripForcedCase(instructions); } } [HarmonyPatch(typeof(Chat))] public static class Chat_MixedCase_Chat_Patch { [HarmonyPatch("AddInworldText")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> AddInworldText_Transpiler(IEnumerable<CodeInstruction> instructions) { return sFunc.StripForcedCase(instructions); } } [HarmonyPatch(typeof(Chat))] public static class Chat_Shout_Patch { [HarmonyPatch("InputText")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> InputText_Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldstr && instruction.operand.Equals("say ")) { instruction.operand = "s "; } yield return instruction; } } } [HarmonyPatch(typeof(Minimap))] public static class Minimap_Patches { [HarmonyPatch("UpdateDynamicPins")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count - 1; i++) { if (list[i + 1].opcode == OpCodes.Call) { MethodBase methodBase = (MethodBase)list[i + 1].operand; if (methodBase.Name == "UpdateShoutPins") { list.RemoveRange(i, 2); break; } } } return list; } } [HarmonyPatch(typeof(Player), "Update")] public static class Player_Update_Patch { private static GameObject timeObj = null; private static double savedEnvMinutes = -1.0; private const float ColorRatio = 0.5882353f; private const float AlphaRatio = 44f / 51f; private const int FontSize = 24; private static void Postfix(ref Player __instance) { if (((Character)__instance).m_nview.IsValid() && ((Character)__instance).m_nview.IsOwner()) { Hud instance = Hud.instance; if ((Object)(object)timeObj == (Object)null) { InitializeTimeObject(instance); } UpdateTimeText(instance, EnvMan.instance); } } private static void InitializeTimeObject(Hud hud) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) MessageHud instance = MessageHud.instance; timeObj = new GameObject("TimeText"); timeObj.transform.SetParent(((Component)hud.m_statusEffectListRoot).transform.parent); timeObj.AddComponent<RectTransform>(); TMP_Text val = (TMP_Text)(object)timeObj.AddComponent<TextMeshProUGUI>(); ((Graphic)val).color = new Color(0.5882353f, 0.5882353f, 0.5882353f, 44f / 51f); val.font = instance.m_messageCenterText.font; val.fontSize = 24f; val.alignment = (TextAlignmentOptions)514; val.overflowMode = (TextOverflowModes)0; ((Behaviour)val).enabled = true; } private static void UpdateTimeText(Hud hud, EnvMan env) { double num = env.m_totalSeconds / 60.0; if (savedEnvMinutes != num) { TMP_Text component = timeObj.GetComponent<TMP_Text>(); int currentDay = env.GetCurrentDay(); float num2 = Mathf.Lerp(0f, 24f, env.GetDayFraction()); int num3 = Mathf.FloorToInt(num2); int num4 = Mathf.FloorToInt((num2 - (float)num3) * 60f); string text = ((num3 < 12) ? " AM" : " PM"); if (num3 > 12) { num3 -= 12; } component.text = $"Day {currentDay}, {num3:00}:{num4:00}{text}"; PositionTimeText(hud); savedEnvMinutes = num; } } private static void PositionTimeText(Hud hud) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)hud.m_staminaBar2Root).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); Transform transform2 = ((Component)hud.m_statusEffectListRoot).transform; RectTransform val2 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null); RectTransform component = timeObj.GetComponent<RectTransform>(); ((Transform)component).position = Vector2.op_Implicit(new Vector2(((Transform)val).position.x, ((Transform)val2).position.y)); timeObj.SetActive(true); } } internal class Demister { [HarmonyPatch(typeof(Mister), "OnEnable")] internal static class MisterOnEnablePatch { private static bool Prefix() { return false; } } [HarmonyPatch(typeof(ParticleMist), "Awake")] internal static class ParticleMistAwakePatch { private static void Postfix(ParticleMist __instance) { try { if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.m_ps != (Object)null) { MistEmitter component = ((Component)__instance).GetComponent<MistEmitter>(); if ((Object)(object)component != (Object)null) { component.SetEmit(false); } } } catch (Exception ex) { ZLog.LogWarning((object)ex); } } } } [HarmonyPatch(typeof(Player), "StartGuardianPower")] public static class Player_StartGuardianPower_Patch { private static bool Prefix(ref Player __instance, ref bool __result) { if ((Object)(object)__instance.m_guardianSE == (Object)null) { __result = false; return false; } if (__instance.m_guardianPowerCooldown > 0f) { ((Character)__instance).Message((MessageType)2, "$hud_powernotready", 0, (Sprite)null, false); __result = false; return false; } __instance.ActivateGuardianPower(); __result = true; return false; } } [HarmonyPatch(typeof(EnvMan), "SetEnv")] public static class AshlandsEnvOverride { private static readonly string targetEnvironment = "Mistlands_clear"; [HarmonyPrefix] public static void Prefix(EnvMan __instance, ref EnvSetup env) { if (env.m_name.StartsWith("Ashlands")) { EnvSetup val = __instance.m_environments.Find((EnvSetup e) => e.m_name == targetEnvironment); if (val != null) { env = val; } } } } [HarmonyPatch(typeof(InventoryGui), "RepairOneItem")] public static class InventoryGui_RepairOneItem_Transpiler { private static readonly MethodInfo method_EffectList_Create = AccessTools.Method(typeof(EffectList), "Create", (Type[])null, (Type[])null); private static readonly MethodInfo method_CreateNoop = AccessTools.Method(typeof(InventoryGui_RepairOneItem_Transpiler), "CreateNoop", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], method_EffectList_Create)) { list[i] = new CodeInstruction(OpCodes.Call, (object)method_CreateNoop); } } return list.AsEnumerable(); } private static GameObject[] CreateNoop(Vector3 _0, Quaternion _1, Transform _2, float _3, int _4) { return null; } } [HarmonyPatch(typeof(InventoryGui), "UpdateRepair")] public static class InventoryGui_UpdateRepair_Patch { [HarmonyPrefix] public static void Prefix(InventoryGui __instance) { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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) Player localPlayer = Player.m_localPlayer; CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation(); if ((Object)(object)currentCraftingStation == (Object)null) { return; } int num = 0; foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems()) { if (ItemRepair.CanRepair(allItem) && allItem.m_durability < allItem.GetMaxDurability()) { allItem.m_durability = allItem.GetMaxDurability(); num++; } } if (num > 0) { currentCraftingStation.m_repairItemDoneEffects.Create(((Component)currentCraftingStation).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); } } } public static class ItemRepair { public static bool CanRepair(ItemData item) { Recipe recipe = ObjectDB.instance.GetRecipe(item); CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation(); if ((Object)(object)recipe == (Object)null || (Object)(object)currentCraftingStation == (Object)null) { return false; } return (((Object)(object)recipe.m_repairStation != (Object)null && recipe.m_repairStation.m_name == currentCraftingStation.m_name) || ((Object)(object)recipe.m_craftingStation != (Object)null && recipe.m_craftingStation.m_name == currentCraftingStation.m_name)) && currentCraftingStation.GetLevel(true) >= recipe.m_minStationLevel; } } [HarmonyPatch(typeof(Game), "Start")] public static class Game_Start_Patch { private static void Prefix() { ZRoutedRpc.instance.Register<ZPackage>("nVHMapSync", (Action<long, ZPackage>)MapSync.RPC_nVHMapSync); ZRoutedRpc.instance.Register("nVHAck", (Action<long>)nVHAck.RPC_nVHAck); } } [HarmonyPatch(typeof(Minimap))] public class HookExplore { [HarmonyReversePatch(/*Could not decode attribute arguments.*/)] [HarmonyPatch(typeof(Minimap), "Explore", new Type[] { typeof(Vector3), typeof(float) })] public static void call_Explore(object instance, Vector3 p, float radius) { throw new NotImplementedException(); } } [HarmonyPatch(typeof(Minimap), "UpdateExplore")] public static class ChangeMapBehavior { private static void Prefix(ref float dt, ref Player player, ref Minimap __instance, ref float ___m_exploreTimer, ref float ___m_exploreInterval) { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) float num = ___m_exploreTimer; num += Time.deltaTime; float radius = 200f; if (num > ___m_exploreInterval && ZNet.instance.m_players.Any()) { foreach (PlayerInfo player2 in ZNet.instance.m_players) { HookExplore.call_Explore(__instance, player2.m_position, radius); } } HookExplore.call_Explore(__instance, ((Component)player).transform.position, radius); } } [HarmonyPatch(typeof(Minimap), "Awake")] public static class MinimapAwake { private static void Postfix() { if (ZNet.m_isServer) { MapSync.ServerMapData = new bool[Minimap.instance.m_textureSize * Minimap.instance.m_textureSize]; MapSync.LoadMapDataFromDisk(); NaNNaVH.mapSyncSaveTimer.Start(); } } } [HarmonyPatch(typeof(ZNet))] public class HookZNet { [HarmonyReversePatch(/*Could not decode attribute arguments.*/)] [HarmonyPatch(typeof(ZNet), "GetOtherPublicPlayers", new Type[] { typeof(List<PlayerInfo>) })] public static void GetOtherPublicPlayers(object instance, List<PlayerInfo> playerList) { throw new NotImplementedException(); } } [HarmonyPatch(typeof(ZNet), "SendPeriodicData")] public static class PeriodicDataHandler { private static void Postfix() { RpcQueue.SendNextRpc(); } } [HarmonyPatch(typeof(ZNet), "Shutdown")] public static class OnErrorLoadOwnIni { private static void Prefix(ref ZNet __instance) { if (!__instance.IsServer()) { NaNNaVH.harmony.UnpatchSelf(); NaNNaVH.harmony.PatchAll(); MapSync.ShouldSyncOnSpawn = true; } else { MapSync.SaveMapDataToDisk(); } } } [HarmonyPatch(typeof(ZNet), "SetPublicReferencePosition")] public static class PreventPublicPositionToggle { private static void Postfix(ref bool pub, ref bool ___m_publicReferencePosition) { ___m_publicReferencePosition = true; } } [HarmonyPatch(typeof(ZNet), "RPC_ServerSyncedPlayerData")] public static class PlayerPositionWatcher { private static void Postfix(ref ZNet __instance, ZRpc rpc) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) if (!__instance.IsServer()) { return; } ZNetPeer peer = __instance.GetPeer(rpc); if (peer == null) { return; } Vector3 refPos = peer.m_refPos; int num = default(int); int num2 = default(int); Minimap.instance.WorldToPixel(refPos, ref num, ref num2); int num3 = (int)Mathf.Ceil(200f / Minimap.instance.m_pixelSize); for (int i = num2 - num3; i <= num2 + num3; i++) { for (int j = num - num3; j <= num + num3; j++) { if (j >= 0 && i >= 0 && j < Minimap.instance.m_textureSize && i < Minimap.instance.m_textureSize) { Vector2 val = new Vector2((float)(j - num), (float)(i - num2)); if ((double)((Vector2)(ref val)).magnitude <= (double)num3) { MapSync.ServerMapData[i * Minimap.instance.m_textureSize + j] = true; } } } } } } [HarmonyPatch(typeof(Player), "OnSpawned")] public static class Player_OnSpawned_Patch { private static void Prefix(ref Player __instance) { MapSync.SendMapToServer(); MapSync.ShouldSyncOnSpawn = false; } } public class DisplayCartsAndBoatsOnMap { [HarmonyPatch(typeof(Minimap), "OnDestroy")] public static class Minimap_OnDestroy_Patch { private static void Postfix() { customPins.Clear(); icons.Clear(); } } [HarmonyPatch(typeof(Minimap), "UpdateMap")] public static class Minimap_UpdateMap_Patch { private static float timeCounter = updateInterval; private static void FindIcons() { GameObject val = ObjectDB.instance.m_itemByHash[hammerHashCode]; if (!Object.op_Implicit((Object)(object)val)) { return; } ItemDrop component = val.GetComponent<ItemDrop>(); if (!Object.op_Implicit((Object)(object)component)) { return; } PieceTable buildPieces = component.m_itemData.m_shared.m_buildPieces; foreach (GameObject piece in buildPieces.m_pieces) { Piece component2 = piece.GetComponent<Piece>(); icons.Add(StringExtensionMethods.GetStableHashCode(((Object)component2).name), component2.m_icon); } } private static bool CheckPin(Minimap __instance, Player player, ZDO zdo, int hashCode, string pinName) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) if (zdo.m_prefab != hashCode) { return false; } PinData value; bool flag = customPins.TryGetValue(zdo, out value); Ship controlledShip = player.GetControlledShip(); if (Object.op_Implicit((Object)(object)controlledShip) && Vector3.Distance(((Component)controlledShip).transform.position, zdo.m_position) < 0.01f) { if (flag) { __instance.RemovePin(value); customPins.Remove(zdo); } return true; } if (!flag) { value = __instance.AddPin(zdo.m_position, (PinType)4, pinName, false, false, 0L, default(PlatformUserID)); if (icons.TryGetValue(hashCode, out var value2)) { value.m_icon = value2; } value.m_doubleSize = true; customPins.Add(zdo, value); } else { value.m_pos = zdo.m_position; } return true; } public static void Postfix(ref Minimap __instance, Player player, float dt, bool takeInput) { timeCounter += dt; if (timeCounter < updateInterval) { return; } timeCounter -= updateInterval; if (icons.Count == 0) { FindIcons(); } List<ZDO>[] objectsBySector = ZDOMan.instance.m_objectsBySector; foreach (List<ZDO> list in objectsBySector) { if (list == null) { continue; } foreach (ZDO item in list) { for (int j = 0; j < HashCodes.Length && !CheckPin(__instance, player, item, HashCodes[j], PinNames[j]); j++) { } } } List<ZDO> list2 = new List<ZDO>(); foreach (KeyValuePair<ZDO, PinData> customPin in customPins) { if (!customPin.Key.IsValid()) { __instance.RemovePin(customPin.Value); list2.Add(customPin.Key); } } foreach (ZDO item2 in list2) { customPins.Remove(item2); } } } private static Dictionary<ZDO, PinData> customPins = new Dictionary<ZDO, PinData>(); private static Dictionary<int, Sprite> icons = new Dictionary<int, Sprite>(); private static int[] HashCodes = new int[4] { StringExtensionMethods.GetStableHashCode("Cart"), StringExtensionMethods.GetStableHashCode("Raft"), StringExtensionMethods.GetStableHashCode("Karve"), StringExtensionMethods.GetStableHashCode("VikingShip") }; private static string[] PinNames = new string[4] { "Cart", "Raft", "Karve", "Longship" }; private static int hammerHashCode = StringExtensionMethods.GetStableHashCode("Hammer"); private static float updateInterval = 5f; } public class Network { [HarmonyPatch(typeof(ZSteamSocket), "RegisterGlobalCallbacks")] private static class IncreaseSendingLimit { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldc_I4 && CodeInstructionExtensions.OperandIs(instruction, (object)153600)) { instruction.operand = 50000000; } yield return instruction; } } private static void Postfix() { if (!(CSteamAPIContext.GetSteamClient() != IntPtr.Zero)) { return; } GCHandle gCHandle = default(GCHandle); try { gCHandle = GCHandle.Alloc(100000000, GCHandleType.Pinned); SteamNetworkingUtils.SetConfigValue((ESteamNetworkingConfigValue)9, (ESteamNetworkingConfigScope)1, IntPtr.Zero, (ESteamNetworkingConfigDataType)1, gCHandle.AddrOfPinnedObject()); } finally { if (gCHandle.IsAllocated) { gCHandle.Free(); } } } } private const int NewLimit = 50000000; private const int BufferSize = 100000000; } [HarmonyPatch(typeof(EnvMan), "SetEnv")] public static class EnvMan_SetEnv_Patch { private const float NightBrightnessMultiplier = 1.5f; private static void Prefix(ref EnvMan __instance, ref EnvSetup env) { env.m_fogDensityNight = 0f; env.m_fogDensityMorning = 0f; env.m_fogDensityEvening = 0f; ApplyEnvModifier(env); } private static void ApplyEnvModifier(EnvSetup env) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) env.m_ambColorNight = ApplyBrightnessModifier(env.m_ambColorNight, 1.5f); env.m_fogColorNight = ApplyBrightnessModifier(env.m_fogColorNight, 1.5f); env.m_fogColorSunNight = ApplyBrightnessModifier(env.m_fogColorSunNight, 1.5f); env.m_sunColorNight = ApplyBrightnessModifier(env.m_sunColorNight, 1.5f); } private static Color ApplyBrightnessModifier(Color color, float multiplier) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) float num = default(float); float num2 = default(float); float num3 = default(float); Color.RGBToHSV(color, ref num, ref num2, ref num3); float num4 = ((multiplier >= 0f) ? (Mathf.Sqrt(multiplier) * 0.00010699527f + 1f) : (1f - Mathf.Sqrt(Mathf.Abs(multiplier)) * 0.00010699527f)); num3 = Mathf.Clamp01(num3 * num4); return Color.HSVToRGB(num, num2, num3); } } [HarmonyPatch(typeof(EnvMan), "SetParticleArrayEnabled")] public static class EnvMan_SetParticleArrayEnabled_Patch { private static void Postfix(GameObject[] psystems, bool enabled) { foreach (GameObject val in psystems) { MistEmitter componentInChildren = val.GetComponentInChildren<MistEmitter>(); if (Object.op_Implicit((Object)(object)componentInChildren)) { ((Behaviour)componentInChildren).enabled = false; } } } } [HarmonyPatch(typeof(Piece), "DropResources")] public static class PieceDropResourcesTranspiler { private static MethodInfo _methodPieceIsPlacedByPlayer = AccessTools.Method(typeof(Piece), "IsPlacedByPlayer", (Type[])null, (Type[])null); private static FieldInfo _fieldRequirementMRecover = AccessTools.Field(typeof(Requirement), "m_recover"); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); bool flag = false; bool flag2 = false; for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], _methodPieceIsPlacedByPlayer) && !flag) { list[i] = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null); list.RemoveAt(i - 1); flag = true; } if (CodeInstructionExtensions.LoadsField(list[i], _fieldRequirementMRecover, false) && !flag2) { list.RemoveRange(i - 1, 3); flag2 = true; } } return list.AsEnumerable(); } } [HarmonyPatch(typeof(ItemData), "GetMaxDurability", new Type[] { typeof(int) })] public static class ItemDrop_GetMaxDurability_Patch { private static readonly HashSet<string> ItemsToChangeDurability = new HashSet<string> { "hammer", "cultivator", "hoe", "torch" }; private static bool Prefix(ItemData __instance, int quality, ref float __result) { string text = __instance.m_shared.m_name.ToLower(); foreach (string item in ItemsToChangeDurability) { if (text.Contains(item)) { float targetValue = __instance.m_shared.m_maxDurability + (float)Mathf.Max(0, quality - 1) * __instance.m_shared.m_durabilityPerLevel; __result = sFunc.applyModifierValue(targetValue, 200f); return false; } } return true; } } [HarmonyPatch(typeof(Player), "EatFood")] public static class Player_EatFood_Transpiler { private static readonly FieldInfo field_ItemDrop_ItemData_SharedData_m_foodBurnTime = AccessTools.Field(typeof(SharedData), "m_foodBurnTime"); private static readonly MethodInfo method_ComputeModifiedFoodBurnTime = AccessTools.Method(typeof(Player_EatFood_Transpiler), "ComputeModifiedFoodBurnTime", (Type[])null, (Type[])null); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.LoadsField(list[i], field_ItemDrop_ItemData_SharedData_m_foodBurnTime, false)) { list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)method_ComputeModifiedFoodBurnTime)); i++; } } return list.AsEnumerable(); } private static float ComputeModifiedFoodBurnTime(float foodBurnTime) { return sFunc.applyModifierValue(foodBurnTime, 300f); } } [HarmonyPatch(typeof(Player), "GetTotalFoodValue")] public static class Player_GetTotalFoodValue_Transpiler { private static readonly FieldInfo field_Food_m_health = AccessTools.Field(typeof(Food), "m_health"); private static readonly FieldInfo field_Food_m_stamina = AccessTools.Field(typeof(Food), "m_stamina"); private static readonly FieldInfo field_Food_m_item = AccessTools.Field(typeof(Food), "m_item"); private static readonly FieldInfo field_ItemData_m_shared = AccessTools.Field(typeof(ItemData), "m_shared"); private static readonly FieldInfo field_SharedData_m_food = AccessTools.Field(typeof(SharedData), "m_food"); private static readonly FieldInfo field_SharedData_m_foodStamina = AccessTools.Field(typeof(SharedData), "m_foodStamina"); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.LoadsField(list[i], field_Food_m_health, false) || CodeInstructionExtensions.LoadsField(list[i], field_Food_m_stamina, false)) { bool flag = CodeInstructionExtensions.LoadsField(list[i], field_Food_m_health, false); list[i].operand = field_Food_m_item; list.Insert(++i, new CodeInstruction(OpCodes.Ldfld, (object)field_ItemData_m_shared)); list.Insert(++i, new CodeInstruction(OpCodes.Ldfld, (object)(flag ? field_SharedData_m_food : field_SharedData_m_foodStamina))); } } return list.AsEnumerable(); } } public class Fuel { [HarmonyPatch(typeof(Fireplace), "UpdateFireplace")] private class Fireplace_UpdateFireplace_Patch { [HarmonyPrefix] private static void Prefix(Fireplace __instance, ref ZNetView ___m_nview) { ___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel); } } [HarmonyPatch(typeof(CookingStation), "SetFuel")] private class CookingStation_SetFuel_Patch { [HarmonyPrefix] private static void Prefix(CookingStation __instance, ref float fuel) { fuel = __instance.m_maxFuel; } } [HarmonyPatch(typeof(CookingStation), "Awake")] private class CookingStation_Awake_Patch { [HarmonyPostfix] private static void Postfix(CookingStation __instance, ref ZNetView ___m_nview) { if (!((Object)(object)Player.m_localPlayer == (Object)null) && !((Character)Player.m_localPlayer).IsTeleporting()) { RefuelAsync(___m_nview); } } } private static async void RefuelAsync(ZNetView nview) { if (!((Object)(object)nview == (Object)null) && ((Behaviour)nview).isActiveAndEnabled) { await Task.Delay(33); nview.InvokeRPC("AddFuel", Array.Empty<object>()); } } } [HarmonyPatch(typeof(DropTable), "GetDropList", new Type[] { typeof(int) })] public static class DropTable_GetDropList_Patch { private static void Postfix(ref DropTable __instance, ref List<GameObject> __result, int amount) { __instance.m_dropChance = 1f; List<string> list = new List<string> { "Wood", "RoundLog", "Stone", "FineWood" }; Dictionary<string, Tuple<int, GameObject>> dictionary = new Dictionary<string, Tuple<int, GameObject>>(); List<GameObject> list2 = new List<GameObject>(); foreach (GameObject item2 in __result) { if (list.Contains(((Object)item2).name)) { if (!dictionary.ContainsKey(((Object)item2).name)) { dictionary.Add(((Object)item2).name, new Tuple<int, GameObject>(1, item2)); continue; } int item = dictionary[((Object)item2).name].Item1; dictionary[((Object)item2).name] = new Tuple<int, GameObject>(item + 1, item2); } else { list2.Add(item2); } } __result.Clear(); __result.AddRange(list2); foreach (KeyValuePair<string, Tuple<int, GameObject>> item3 in dictionary) { float num = sFunc.applyModifierValue(item3.Value.Item1, 200f); int num2 = Mathf.RoundToInt(num); for (int i = 0; i < num2; i++) { __result.Add(item3.Value.Item2); } } } } [HarmonyPatch] internal class Recipes { [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] public static class ObjectDB_CopyOtherDB_Patch { private static void Postfix() { ModifyCosts("ObjectDB.CopyOtherDB"); } } protected static bool PatchingHasAlreadySucceeded; internal static void ModifyCosts(string debugInfo) { if ((Object)(object)ObjectDB.instance == (Object)null || PatchingHasAlreadySucceeded) { return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Hammer"); ItemDrop val = default(ItemDrop); if ((Object)(object)itemPrefab == (Object)null || !itemPrefab.TryGetComponent<ItemDrop>(ref val)) { return; } PieceTable val2 = val.m_itemData?.m_shared?.m_buildPieces; if ((Object)(object)val2 == (Object)null) { return; } GameObject val3 = val2.m_pieces.Find((GameObject piece) => ((Object)piece).name == "piece_stonecutter"); Piece val4 = default(Piece); if ((Object)(object)val3 == (Object)null || !val3.TryGetComponent<Piece>(ref val4) || val4.m_resources == null || val4.m_resources.Length == 0) { return; } Requirement[] resources = val4.m_resources; ItemDrop resItem = default(ItemDrop); foreach (Requirement val5 in resources) { if (((Object)val5.m_resItem).name == "Iron") { GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab("Bronze"); if (!((Object)(object)itemPrefab2 == (Object)null) && itemPrefab2.TryGetComponent<ItemDrop>(ref resItem)) { val5.m_resItem = resItem; PatchingHasAlreadySucceeded = true; } break; } } } } [HarmonyPatch(typeof(SE_Rested), "UpdateTTL")] public static class SE_Rested_UpdateTTL_Patch { [HarmonyPrefix] public static void Prefix(ref float ___m_baseTTL, ref float ___m_TTLPerComfortLevel) { ___m_baseTTL = 960f; ___m_TTLPerComfortLevel = 120f; } } [HarmonyPatch(typeof(Player), "UseStamina")] public static class Player_UseStamina_Patch { private static void Prefix(ref Player __instance, ref float v) { string name = new StackTrace().GetFrame(2).GetMethod().Name; if (name.Contains("UpdatePlacement") || name.Contains("Repair") || name.Contains("RemovePiece")) { string item = ((Humanoid)__instance).GetRightItem()?.m_shared.m_name; HashSet<string> hashSet = new HashSet<string> { "$item_hammer", "$item_hoe", "$item_cultivator" }; if (hashSet.Contains(item)) { v = sFunc.applyModifierValue(v, -100f); } } } } [HarmonyPatch(typeof(Attack), "GetAttackStamina")] public static class Attack_GetAttackStamina_Patch { private static void Postfix(ref Attack __instance, ref float __result) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Invalid comparison between Unknown and I4 if (((Character)__instance.m_character).IsPlayer()) { ItemData currentWeapon = __instance.m_character.GetCurrentWeapon(); SkillType val = (SkillType)((currentWeapon == null) ? 11 : ((int)currentWeapon.m_shared.m_skillType)); if ((int)val == 12) { __result = sFunc.applyModifierValue(__result, -100f); } } } } [HarmonyPatch(typeof(WearNTear), "HaveRoof")] public static class RemoveWearNTear { private static void Postfix(ref bool __result) { __result = true; } } [HarmonyPatch(typeof(WearNTear), "IsUnderWater")] public static class RemoveWearNTearFromUnderWater { private static void Postfix(ref bool __result) { __result = false; } } [HarmonyPatch(typeof(CraftingStation), "CheckUsable")] public static class WorkbenchRemoveRestrictions { private static bool Prefix(ref CraftingStation __instance, ref Player player, ref bool showMessage, ref bool __result) { __instance.m_craftRequireRoof = false; return true; } } }