using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("PettableVikings")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PettableVikings")] [assembly: AssemblyTitle("PettableVikings")] [assembly: AssemblyVersion("1.0.0.0")] namespace PettableVikings; [BepInPlugin("com.valheim.pettablevikings", "Pettable Vikings", "1.0.0")] public class PettableVikingsPlugin : BaseUnityPlugin { private const string ModGUID = "com.valheim.pettablevikings"; private const string ModName = "Pettable Vikings"; private const string ModVersion = "1.0.0"; public static ConfigEntry ModEnabled; public static ConfigEntry HoverText; public static ConfigEntry InteractionMessage; public static ConfigEntry InteractionDistance; public static ConfigEntry CooldownTimer; public static ConfigEntry ShowHearts; public static ConfigEntry PlaySound; private void Awake() { //IL_0102: Unknown result type (might be due to invalid IL or missing references) ModEnabled = ((BaseUnityPlugin)this).Config.Bind("1 - General", "1_Enabled", true, "Enable the mod."); HoverText = ((BaseUnityPlugin)this).Config.Bind("1 - General", "2_HoverText", "Pet @viking", "Text shown on the crosshair. Use @viking to insert the player's name."); InteractionMessage = ((BaseUnityPlugin)this).Config.Bind("1 - General", "3_Message", "@viking loves you", "Text displayed after a successful pet. Use @viking to insert the player's name."); InteractionDistance = ((BaseUnityPlugin)this).Config.Bind("1 - General", "4_Distance", 2f, "Maximum distance in meters to allow petting."); CooldownTimer = ((BaseUnityPlugin)this).Config.Bind("1 - General", "5_Cooldown", 1f, "Seconds to wait before you can pet someone again."); ShowHearts = ((BaseUnityPlugin)this).Config.Bind("2 - Visuals & Audio", "1_ShowHearts", true, "Show the pink hearts effect when petting."); PlaySound = ((BaseUnityPlugin)this).Config.Bind("2 - Visuals & Audio", "2_PlaySound", true, "Play the default love sound when petting."); if (ModEnabled.Value) { new Harmony("com.valheim.pettablevikings").PatchAll(); } } } [HarmonyPatch(typeof(Player), "Awake")] public static class Player_Awake_Patch { public static void Postfix(Player __instance) { ((Component)__instance).gameObject.AddComponent(); } } [HarmonyPatch(typeof(Player), "GetHoverText")] public static class Player_GetHoverText_Patch { public static void Postfix(Player __instance, ref string __result) { //IL_002d: 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 (PettableVikingsPlugin.ModEnabled.Value && !((Object)(object)__instance == (Object)(object)Player.m_localPlayer) && !((Character)__instance).IsDead() && !(Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)__instance).transform.position) > PettableVikingsPlugin.InteractionDistance.Value)) { string text = PettableVikingsPlugin.HoverText.Value.Replace("@viking", __instance.GetPlayerName()); string text2 = Localization.instance.Localize("\n[$KEY_Use] " + text); __result += text2; } } } public class PettableComponent : MonoBehaviour, Interactable { private Player _thisPlayer; private ZNetView _nview; private float _lastPetTime; private void Awake() { _thisPlayer = ((Component)this).GetComponent(); _nview = ((Component)this).GetComponent(); if ((Object)(object)_nview != (Object)null && _nview.IsValid()) { _nview.Register("PetVFX", (Action)RPC_PetVFX); } } public bool Interact(Humanoid user, bool hold, bool alt) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if (!PettableVikingsPlugin.ModEnabled.Value) { return false; } if (hold || alt || (Object)(object)_thisPlayer == (Object)(object)Player.m_localPlayer) { return false; } if (Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)_thisPlayer).transform.position) > PettableVikingsPlugin.InteractionDistance.Value) { return false; } if (Time.time - _lastPetTime < PettableVikingsPlugin.CooldownTimer.Value) { return false; } _lastPetTime = Time.time; Animator component = ((Component)user).GetComponent(); if (component != null) { component.SetTrigger("interact"); } string text = PettableVikingsPlugin.InteractionMessage.Value.Replace("@viking", _thisPlayer.GetPlayerName()); MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false); if ((Object)(object)_nview != (Object)null && _nview.IsValid()) { _nview.InvokeRPC(ZNetView.Everybody, "PetVFX", Array.Empty()); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } private void RPC_PetVFX(long sender) { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) if (!PettableVikingsPlugin.ShowHearts.Value && !PettableVikingsPlugin.PlaySound.Value) { return; } GameObject prefab = ZNetScene.instance.GetPrefab("Boar"); if (!((Object)(object)prefab != (Object)null)) { return; } Tameable component = prefab.GetComponent(); if (!((Object)(object)component != (Object)null) || component.m_petEffect == null) { return; } EffectData[] effectPrefabs = component.m_petEffect.m_effectPrefabs; foreach (EffectData val in effectPrefabs) { if (!((Object)(object)val.m_prefab != (Object)null)) { continue; } GameObject val2 = Object.Instantiate(val.m_prefab, ((Character)_thisPlayer).GetTopPoint(), Quaternion.identity); if (!PettableVikingsPlugin.PlaySound.Value) { ZSFX[] componentsInChildren = val2.GetComponentsInChildren(); for (int j = 0; j < componentsInChildren.Length; j++) { Object.Destroy((Object)(object)componentsInChildren[j]); } AudioSource[] componentsInChildren2 = val2.GetComponentsInChildren(); for (int j = 0; j < componentsInChildren2.Length; j++) { Object.Destroy((Object)(object)componentsInChildren2[j]); } } if (!PettableVikingsPlugin.ShowHearts.Value) { ParticleSystem[] componentsInChildren3 = val2.GetComponentsInChildren(); for (int j = 0; j < componentsInChildren3.Length; j++) { Object.Destroy((Object)(object)componentsInChildren3[j]); } } } } }