Decompiled source of DomaRapida v1.0.0

plugins/DomaRapida.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DomaRapida;

[BepInPlugin("piero.DomaRapida", "DomaRapida", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "piero.DomaRapida";

	public const string VERSION = "1.0.0";

	internal static ConfigEntry<float> TiempoDoma;

	internal static ConfigEntry<int> NivelAlDomesticar;

	internal static ConfigEntry<bool> MostrarAviso;

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		TiempoDoma = ((BaseUnityPlugin)this).Config.Bind<float>("Doma", "TiempoDoma", 240f, new ConfigDescription("Segundos de doma con el animal alimentado (vanilla: 1800 a 3000). Taming time in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 3600f), new object[0]));
		NivelAlDomesticar = ((BaseUnityPlugin)this).Config.Bind<int>("Doma", "NivelAlDomesticar", 3, new ConfigDescription("Nivel minimo al quedar domesticado: 1 = sin estrellas, 2 = 1 estrella, 3 = 2 estrellas. 0 = no cambiar. Level given on taming (3 = two stars).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), new object[0]));
		MostrarAviso = ((BaseUnityPlugin)this).Config.Bind<bool>("Doma", "MostrarAviso", true, "Muestra 'Se puede domesticar' y lo que come al apuntar a un animal salvaje domesticable. Show a 'Tameable' hint on wild tameable creatures.");
		new Harmony("piero.DomaRapida").PatchAll(typeof(Plugin).Assembly);
	}

	internal static bool Espanol()
	{
		try
		{
			return Localization.instance != null && Localization.instance.GetSelectedLanguage() == "Spanish";
		}
		catch
		{
			return false;
		}
	}
}
[HarmonyPatch(typeof(Tameable), "Awake")]
internal static class Patch_Awake
{
	private static void Postfix(Tameable __instance)
	{
		if (__instance.m_tamingTime > Plugin.TiempoDoma.Value)
		{
			__instance.m_tamingTime = Plugin.TiempoDoma.Value;
		}
	}
}
[HarmonyPatch(typeof(Tameable), "DecreaseRemainingTime")]
internal static class Patch_Restante
{
	private static void Prefix(Tameable __instance, ZNetView ___m_nview)
	{
		if (!((Object)(object)___m_nview == (Object)null) && ___m_nview.IsValid() && ___m_nview.IsOwner())
		{
			ZDO zDO = ___m_nview.GetZDO();
			float tamingTime = __instance.m_tamingTime;
			float num = zDO.GetFloat(ZDOVars.s_tameTimeLeft, tamingTime);
			if (num > tamingTime)
			{
				zDO.Set(ZDOVars.s_tameTimeLeft, tamingTime);
			}
		}
	}
}
[HarmonyPatch(typeof(Tameable), "Tame")]
internal static class Patch_Tame
{
	private static void Postfix(Tameable __instance, ZNetView ___m_nview, Character ___m_character)
	{
		int value = Plugin.NivelAlDomesticar.Value;
		if (value > 1 && !((Object)(object)___m_character == (Object)null) && !((Object)(object)___m_nview == (Object)null) && ___m_nview.IsValid() && ___m_nview.IsOwner() && ___m_character.IsTamed() && ___m_character.GetLevel() < value)
		{
			___m_character.SetLevel(value);
			___m_character.SetHealth(___m_character.GetMaxHealth());
		}
	}
}
[HarmonyPatch(typeof(Tameable), "GetHoverText")]
internal static class Patch_Hover
{
	private static readonly Dictionary<string, string> comidas = new Dictionary<string, string>();

	private static void Postfix(Tameable __instance, ref string __result, Character ___m_character, MonsterAI ___m_monsterAI)
	{
		if (Plugin.MostrarAviso.Value && !((Object)(object)___m_character == (Object)null) && !___m_character.IsTamed() && !string.IsNullOrEmpty(__result))
		{
			bool flag = Plugin.Espanol();
			string text = "\n<color=#8FE36B><b>" + (flag ? "Se puede domesticar" : "Can be tamed") + "</b></color>";
			string text2 = Comida(___m_character, ___m_monsterAI);
			if (!string.IsNullOrEmpty(text2))
			{
				string text3 = text;
				text = text3 + "\n<size=85%><color=#C8C8C8>" + (flag ? "Come: " : "Eats: ") + text2 + "</color></size>";
			}
			__result += text;
		}
	}

	private static string Comida(Character c, MonsterAI ai)
	{
		string text = (c.m_name ?? "") + "|" + (Plugin.Espanol() ? "es" : "en");
		if (comidas.TryGetValue(text, out var value))
		{
			return value;
		}
		value = "";
		try
		{
			if ((Object)(object)ai != (Object)null && ai.m_consumeItems != null && ai.m_consumeItems.Count > 0)
			{
				List<string> list = (from i in ai.m_consumeItems
					where (Object)(object)i != (Object)null && i.m_itemData != null
					select Localization.instance.Localize(i.m_itemData.m_shared.m_name)).Distinct().Take(4).ToList();
				value = string.Join(", ", list.ToArray());
				if (ai.m_consumeItems.Count > 4)
				{
					value += "…";
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Comida de " + text + ": " + ex.Message));
		}
		comidas[text] = value;
		return value;
	}
}