using Harmony; using System; using System.Reflection; using UnityEngine; [ModTitle("SharkSpy")] // The mod name. [ModDescription("Wearing the shark's head will keep the shark from attacking you while you're in the water.")] // Short description for the mod. [ModAuthor("TeigRolle")] // The author name of the mod. [ModIconUrl("https://www.raftmodding.com/TeKGameRMods/sharkspy_icon.jpg")] // An icon for your mod. Its recommended to be 128x128px and in .jpg format. [ModWallpaperUrl("https://www.raftmodding.com/TeKGameRMods/mods_without_banners/sharkspy.jpg")] // A banner for your mod. Its recommended to be 330x100px and in .jpg format. [ModVersionCheckUrl("https://www.raftmodding.com/api/v1/mods/sharkspy/version.txt")] // This is for update checking. Needs to be a .txt file with the latest mod version. [ModVersion("3.0")] // This is the mod version. [RaftVersion("Update Name")] // This is the recommended raft version. [ModIsPermanent(false)] // If your mod add new blocks, new items or just content you should set that to true. It loads the mod on start and prevents unloading. public class SharkSpy : Mod { private HarmonyInstance instance; public void Start() { RConsole.Log("SharkSpy has been loaded!"); instance = HarmonyInstance.Create("TeigRolle.SharkSpy"); this.instance.PatchAll(Assembly.GetExecutingAssembly()); } public void OnModUnload() { this.instance.UnpatchAll("TeigRolle.SharkSpy"); RConsole.Log("SharkSpy has been unloaded!"); Destroy(gameObject); } } [HarmonyPatch(typeof(Helper), "ClosestPlayerInWaterToPoint", MethodType.Normal)] [HarmonyPatch(new Type[] { typeof(Vector3), typeof(float), typeof(bool)})] class Patch_Shark_ClosestPlayerInWaterToPoint { public static bool Prefix(Shark __instance, ref Network_Player __result, Vector3 point, float maxDistanceFromPoint, bool includeDeadPlayers = true) { Type type = typeof(Helper); FieldInfo info = type.GetField("network", BindingFlags.NonPublic | BindingFlags.Static); Semih_Network net = (Semih_Network)info.GetValue(null); if (net == null || net.remoteUsers == null) { __result = null; } Network_Player result = null; float num = float.MaxValue; foreach (Network_Player network_Player in net.remoteUsers.Values) { bool eqFlag = false; foreach (Equipment equipment in (Equipment[])Traverse.Create(network_Player.PlayerEquipment).Field("equipment").GetValue()) { if (equipment.Equipped && equipment.equipableItem == ItemManager.GetItemByName("Head_Shark")) { eqFlag = true; } } if (!(network_Player == null) && (includeDeadPlayers || !network_Player.PlayerScript.IsDead) && Helper.IsValidWaterTarget(network_Player) && !eqFlag) { float num2 = Vector3.Distance(point, network_Player.transform.position); if (num2 <= num && num2 <= maxDistanceFromPoint) { result = network_Player; num = num2; } } } __result = result; return false; } }