Decompiled source of VikingHorn v1.0.1

HornMod.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HornMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HornMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fdeb9f69-72fa-4d43-ba70-b6b9770b6d15")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HornMod;

[BepInPlugin("com.hornmod.vikinghorn", "Viking Horn", "1.0.0")]
public class HornPlugin : BaseUnityPlugin
{
	private const string escenaTienda = "island 21 M (siren song)";

	private const string raizTienda = "island 21 M (siren song) scenery";

	private const int indiceFijo = 20390;

	private static readonly Vector3 posicionTienda = new Vector3(28.444f, 2.29f, 31.543f);

	private static readonly Vector3 giroTienda = new Vector3(0f, 0f, 0f);

	private GameObject prefabCuerno;

	private bool registrado;

	private ConfigEntry<float> colgPosX;

	private ConfigEntry<float> colgPosY;

	private ConfigEntry<float> colgPosZ;

	private ConfigEntry<float> colgRotX;

	private ConfigEntry<float> colgRotY;

	private ConfigEntry<float> colgRotZ;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Viking Horn cargado correctamente");
		colgPosX = ((BaseUnityPlugin)this).Config.Bind<float>("Colgar en gancho", "PosicionX", 0.07f, "Desplazamiento X respecto al gancho");
		colgPosY = ((BaseUnityPlugin)this).Config.Bind<float>("Colgar en gancho", "PosicionY", 0.18f, "Desplazamiento Y (arriba/abajo) respecto al gancho");
		colgPosZ = ((BaseUnityPlugin)this).Config.Bind<float>("Colgar en gancho", "PosicionZ", -0.09f, "Desplazamiento Z respecto al gancho");
		colgRotX = ((BaseUnityPlugin)this).Config.Bind<float>("Colgar en gancho", "GiroX", 0f, "Giro en grados, eje X");
		colgRotY = ((BaseUnityPlugin)this).Config.Bind<float>("Colgar en gancho", "GiroY", 0f, "Giro en grados, eje Y");
		colgRotZ = ((BaseUnityPlugin)this).Config.Bind<float>("Colgar en gancho", "GiroZ", -90f, "Giro en grados, eje Z");
		SceneManager.sceneLoaded += AlCargarEscena;
		((MonoBehaviour)this).StartCoroutine(Preparar());
	}

	private void AlCargarEscena(Scene escena, LoadSceneMode modo)
	{
		if (((Scene)(ref escena)).name == "island 21 M (siren song)")
		{
			((MonoBehaviour)this).StartCoroutine(PonerEnTienda());
		}
	}

	private IEnumerator Preparar()
	{
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "horn_bundle");
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("No encuentro horn_bundle en: " + text));
			yield break;
		}
		AssetBundleCreateRequest peticion = AssetBundle.LoadFromFileAsync(text);
		yield return peticion;
		AssetBundle assetBundle = peticion.assetBundle;
		if ((Object)(object)assetBundle == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"No he podido abrir horn_bundle");
			yield break;
		}
		prefabCuerno = assetBundle.LoadAsset<GameObject>("cuerno vikingo");
		if ((Object)(object)prefabCuerno == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"No encuentro el prefab 'cuerno vikingo' dentro del paquete");
			yield break;
		}
		while ((Object)(object)PrefabsDirectory.instance == (Object)null)
		{
			yield return (object)new WaitForSeconds(1f);
		}
		yield return (object)new WaitForSeconds(2f);
		HornItem hornItem = prefabCuerno.AddComponent<HornItem>();
		((PickupableItem)hornItem).holdDistance = 1.15f;
		((PickupableItem)hornItem).furniturePlaceHeight = 0.15f;
		((ShipItem)hornItem).mass = 1f;
		((ShipItem)hornItem).value = 100;
		((ShipItem)hornItem).name = "viking horn";
		((ShipItem)hornItem).category = (TransactionCategory)3;
		((ShipItem)hornItem).inventoryScale = 1f;
		((ShipItem)hornItem).floaterHeight = 1.6f;
		((GoPointerButton)hornItem).allowPlacingItems = true;
		((PickupableItem)hornItem).big = false;
		SaveablePrefab val = prefabCuerno.AddComponent<SaveablePrefab>();
		PrefabsDirectory instance = PrefabsDirectory.instance;
		int num = 20390;
		if (num < instance.directory.Length && (Object)(object)instance.directory[num] != (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("La posicion " + num + " ya esta ocupada por otro objeto: no registro el cuerno para no pisarlo"));
			yield break;
		}
		int num2 = Mathf.Max(Mathf.Max(instance.directory.Length, instance.shipItems.Length), num + 1);
		GameObject[] array = (GameObject[])(object)new GameObject[num2];
		instance.directory.CopyTo(array, 0);
		array[num] = prefabCuerno;
		instance.directory = array;
		ShipItem[] array2 = (ShipItem[])(object)new ShipItem[num2];
		instance.shipItems.CopyTo(array2, 0);
		array2[num] = (ShipItem)(object)hornItem;
		instance.shipItems = array2;
		val.prefabIndex = num;
		registrado = true;
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Cuerno registrado en la posicion " + num));
		RegistrarColgado();
		Scene sceneByName = SceneManager.GetSceneByName("island 21 M (siren song)");
		if (((Scene)(ref sceneByName)).isLoaded)
		{
			((MonoBehaviour)this).StartCoroutine(PonerEnTienda());
		}
		LogOcupados("al registrar");
		while (GameState.currentlyLoading || GameState.justStarted || !GameState.playing)
		{
			yield return (object)new WaitForSeconds(1f);
		}
		yield return (object)new WaitForSeconds(5f);
		LogOcupados("con la partida cargada");
		if (PrefabsDirectory.instance.directory.Length <= 20390 || (Object)(object)PrefabsDirectory.instance.directory[20390] != (Object)(object)prefabCuerno)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("AVISO: otro mod ha pisado la posicion " + 20390 + " del cuerno"));
		}
	}

	private void RegistrarColgado()
	{
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				type = assemblies[i].GetType("HooksHangMore.HHM_Plugin");
				if (type != null)
				{
					break;
				}
			}
			if (type == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"COLGAR: HooksHangMore no esta instalado, el cuerno no se podra colgar");
				return;
			}
			MethodInfo method = type.GetMethod("AddAttachedOffset", BindingFlags.Static | BindingFlags.Public);
			if (method == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"COLGAR: esta version de HooksHangMore no tiene AddAttachedOffset");
				return;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(colgPosX.Value, colgPosY.Value, colgPosZ.Value);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(colgRotX.Value, colgRotY.Value, colgRotZ.Value);
			object obj = method.Invoke(null, new object[3] { "viking horn", val, val2 });
			((BaseUnityPlugin)this).Logger.LogInfo((object)("COLGAR: AddAttachedOffset('viking horn') -> " + obj));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("COLGAR: no se pudo registrar el colgado: " + ex.Message));
		}
	}

	private void LogOcupados(string cuando)
	{
		GameObject[] directory = PrefabsDirectory.instance.directory;
		string text = "";
		int num = 0;
		for (int i = 390; i < directory.Length; i++)
		{
			if ((Object)(object)directory[i] != (Object)null && i != 20390)
			{
				num++;
				if (num <= 80)
				{
					text = text + i + " ";
				}
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("OCUPADOS (" + cuando + "): " + num + " objetos de otros mods desde la posicion 390: " + text));
	}

	private IEnumerator PonerEnTienda()
	{
		while (!registrado)
		{
			yield return (object)new WaitForSeconds(1f);
		}
		GameObject raiz = null;
		for (int i = 0; i < 30; i++)
		{
			raiz = GameObject.Find("island 21 M (siren song) scenery");
			if ((Object)(object)raiz != (Object)null)
			{
				break;
			}
			yield return (object)new WaitForSeconds(1f);
		}
		if ((Object)(object)raiz == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"TIENDA: no encuentro island 21 M (siren song) scenery");
		}
		else if (!((Object)(object)raiz.transform.Find("cuerno spawner") != (Object)null))
		{
			GameObject val = new GameObject("cuerno spawner");
			val.transform.parent = raiz.transform;
			val.transform.localPosition = posicionTienda;
			val.transform.localRotation = Quaternion.Euler(giroTienda);
			val.AddComponent<MeshFilter>().sharedMesh = prefabCuerno.GetComponent<MeshFilter>().sharedMesh;
			val.AddComponent<MeshRenderer>();
			val.AddComponent<ShopItemSpawner>().itemPrefab = prefabCuerno;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TIENDA: spawner del cuerno creado en island 21 M (siren song) scenery");
		}
	}
}
[DefaultExecutionOrder(1000)]
public class HornItem : ShipItem
{
	private const float distanciaBoca = 0.35f;

	private const float alturaBoca = -0.15f;

	private const float giroBoca = 0f;

	private const float giroLateral = 90f;

	private const float velocidad = 6f;

	private const float duracionFundido = 0.12f;

	private AudioSource sonido;

	private float volumenOriginal = 1f;

	private float distanciaInicial;

	private float giroActual;

	private bool usando;

	private bool estabaUsando;

	private bool yaSono;

	private bool pulsadoEsteFotograma;

	private bool botonLiberado = true;

	public override void OnLoad()
	{
		sonido = ((Component)this).GetComponent<AudioSource>();
		if ((Object)(object)sonido != (Object)null)
		{
			volumenOriginal = sonido.volume;
		}
		distanciaInicial = ((PickupableItem)this).holdDistance;
		Debug.Log((object)("HornItem cargado. AudioSource encontrado: " + ((Object)(object)sonido != (Object)null)));
	}

	public override void OnBuy()
	{
		botonLiberado = false;
	}

	public override void OnAltHeld()
	{
		pulsadoEsteFotograma = true;
		if (base.sold && botonLiberado && distanciaInicial != 0f)
		{
			usando = true;
			((PickupableItem)this).holdDistance = Mathf.Lerp(((PickupableItem)this).holdDistance, 0.35f, Time.deltaTime * 6f);
			((PickupableItem)this).holdHeight = Mathf.Lerp(((PickupableItem)this).holdHeight, -0.15f, Time.deltaTime * 6f);
			((PickupableItem)this).heldRotationOffset = Mathf.Lerp(((PickupableItem)this).heldRotationOffset, 0f, Time.deltaTime * 6f);
			giroActual = Mathf.Lerp(giroActual, 90f, Time.deltaTime * 6f);
			if ((Object)(object)sonido != (Object)null && sonido.isPlaying)
			{
				sonido.volume = volumenOriginal;
			}
			if (!yaSono && (Object)(object)sonido != (Object)null && !sonido.isPlaying)
			{
				sonido.Play();
				yaSono = true;
				Debug.Log((object)"HornItem: sonando");
			}
		}
	}

	public override void ExtraLateUpdate()
	{
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		if (!pulsadoEsteFotograma)
		{
			botonLiberado = true;
		}
		pulsadoEsteFotograma = false;
		if ((Object)(object)sonido != (Object)null && sonido.isPlaying && (!usando || (Object)(object)((PickupableItem)this).held == (Object)null))
		{
			sonido.volume = Mathf.MoveTowards(sonido.volume, 0f, Time.deltaTime * volumenOriginal / 0.12f);
			if (sonido.volume <= 0.001f)
			{
				sonido.Stop();
				sonido.volume = volumenOriginal;
			}
		}
		if (distanciaInicial == 0f)
		{
			return;
		}
		if ((Object)(object)((PickupableItem)this).held == (Object)null)
		{
			((PickupableItem)this).holdDistance = distanciaInicial;
			((PickupableItem)this).holdHeight = 0f;
			giroActual = 0f;
			estabaUsando = false;
			yaSono = false;
			usando = false;
			return;
		}
		if (usando)
		{
			estabaUsando = true;
		}
		else
		{
			yaSono = false;
			if (estabaUsando)
			{
				((PickupableItem)this).holdDistance = Mathf.Lerp(((PickupableItem)this).holdDistance, distanciaInicial, Time.deltaTime * 6f);
				((PickupableItem)this).holdHeight = Mathf.Lerp(((PickupableItem)this).holdHeight, 0f, Time.deltaTime * 6f);
				((PickupableItem)this).heldRotationOffset = Mathf.Lerp(((PickupableItem)this).heldRotationOffset, 0f, Time.deltaTime * 6f);
				giroActual = Mathf.Lerp(giroActual, 0f, Time.deltaTime * 6f);
				if (Mathf.Abs(((PickupableItem)this).holdDistance - distanciaInicial) < 0.01f)
				{
					((PickupableItem)this).holdDistance = distanciaInicial;
					((PickupableItem)this).holdHeight = 0f;
					((PickupableItem)this).heldRotationOffset = 0f;
					giroActual = 0f;
					estabaUsando = false;
				}
			}
		}
		if (Mathf.Abs(giroActual) > 0.01f)
		{
			((Component)this).transform.Rotate(Vector3.up, giroActual, (Space)1);
		}
		usando = false;
	}
}