using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TesoroMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TesoroMod")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("500ccf7a-3448-4b0c-ad93-f4560c792349")]
[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 TesoroMod;
[BepInPlugin("vikingdmike.treasurehunt", "Message in a Bottle", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(PrefabsDirectory), "Start")]
private static class ParcheDirectorio
{
private static void Prefix(PrefabsDirectory __instance)
{
Insertar(__instance);
}
}
public const string ID = "vikingdmike.treasurehunt";
public const int IndiceBotella = 24701;
public const int IndicePergamino = 115;
public const int IndiceCofre = 24702;
public const int IndiceCofreGrande = 24712;
public const int IndiceRellenoCofre = 33;
public const int IndiceBotellaVacia = 59;
public static Plugin Instancia;
public static GameObject PrefabBotella;
public static GameObject PrefabCofre;
public static GameObject PrefabCofreGrande;
private const int PrecioBotella = 50;
private ConfigEntry<int> columnasCofre;
private ConfigEntry<int> filasCofre;
private static bool registrado;
private GameObject puesto;
private ConfigEntry<string> tiendaEscena;
private ConfigEntry<string> tiendaRaiz;
private ConfigEntry<float> tiendaX;
private ConfigEntry<float> tiendaY;
private ConfigEntry<float> tiendaZ;
private ConfigEntry<float> tiendaGiro;
private ConfigEntry<float> tiendaInclinacion;
private ConfigEntry<KeyCode> teclaLocalizar;
private float proximoBrillo;
private readonly HashSet<BotellaItem> conBrillo = new HashSet<BotellaItem>();
private static readonly Predicate<BotellaItem> SinBotella = (BotellaItem x) => (Object)(object)x == (Object)null;
private AudioClip sonidoRotura;
public int PrecioCofreGrande => 18350;
public int PrecioCofre => 1000;
public int ColumnasCofre
{
get
{
if (columnasCofre == null)
{
return 4;
}
return columnasCofre.Value;
}
}
public int FilasCofre
{
get
{
if (filasCofre == null)
{
return 2;
}
return filasCofre.Value;
}
}
private void Awake()
{
Instancia = this;
columnasCofre = ((BaseUnityPlugin)this).Config.Bind<int>("Treasure", "ChestColumns", 4, "Storage slots of the treasure chest: columns (1-6)");
filasCofre = ((BaseUnityPlugin)this).Config.Bind<int>("Treasure", "ChestRows", 2, "Storage slots of the treasure chest: rows (1-5)");
CargarPaquete();
((Component)this).gameObject.AddComponent<Naufragio>().Configurar(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
sonidoRotura = CargarWav(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "botella_rota.wav"));
Harmony.CreateAndPatchAll(typeof(ParcheDirectorio), "vikingdmike.treasurehunt");
Harmony.CreateAndPatchAll(typeof(ParcheHuecosCofre), "vikingdmike.treasurehunt.huecos");
Harmony.CreateAndPatchAll(typeof(ParcheLupaHueco), "vikingdmike.treasurehunt.lupa");
Harmony.CreateAndPatchAll(typeof(ParcheLupaGuardar), "vikingdmike.treasurehunt.lupa2");
if ((Object)(object)PrefabsDirectory.instance != (Object)null && (Object)(object)PrefabBotella != (Object)null)
{
Insertar(PrefabsDirectory.instance);
AccessTools.Method(typeof(PrefabsDirectory), "PopulateShipItems", (Type[])null, (Type[])null).Invoke(PrefabsDirectory.instance, null);
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"VDM Treasure Hunt cargado");
}
private void CargarPaquete()
{
//IL_00de: 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)
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "tesoro_bundle");
if (!File.Exists(text))
{
((BaseUnityPlugin)this).Logger.LogError((object)("No encuentro tesoro_bundle en " + text));
return;
}
AssetBundle val = AssetBundle.LoadFromFile(text);
if ((Object)(object)val == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"No he podido abrir tesoro_bundle");
return;
}
PrefabBotella = val.LoadAsset<GameObject>("botella");
if ((Object)(object)PrefabBotella == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Falta el prefab 'botella' en tesoro_bundle");
return;
}
AjustarColores(PrefabBotella);
BotellaItem botellaItem = PrefabBotella.AddComponent<BotellaItem>();
((PickupableItem)botellaItem).holdDistance = 0.5f;
((PickupableItem)botellaItem).holdHeight = -0.2f;
((PickupableItem)botellaItem).furniturePlaceHeight = 0.02f;
((ShipItem)botellaItem).mass = 0.6f;
((ShipItem)botellaItem).value = 50;
((ShipItem)botellaItem).name = "message in a bottle";
((ShipItem)botellaItem).category = (TransactionCategory)3;
((ShipItem)botellaItem).inventoryScale = 1f;
((ShipItem)botellaItem).floaterHeight = 0.3f;
PrefabBotella.AddComponent<SaveablePrefab>().prefabIndex = 24701;
PrefabCofre = val.LoadAsset<GameObject>("cofre");
if ((Object)(object)PrefabCofre == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Falta el prefab 'cofre' en tesoro_bundle");
return;
}
AjustarColores(PrefabCofre);
CofreItem cofreItem = PrefabCofre.AddComponent<CofreItem>();
((PickupableItem)cofreItem).holdDistance = 1f;
((PickupableItem)cofreItem).holdHeight = -0.35f;
((PickupableItem)cofreItem).furniturePlaceHeight = 0f;
((ShipItem)cofreItem).mass = 15f;
((ShipItem)cofreItem).amount = 0f;
((ShipItem)cofreItem).value = 1000;
((ShipItem)cofreItem).name = "treasure chest";
((ShipItem)cofreItem).category = (TransactionCategory)3;
((ShipItem)cofreItem).inventoryScale = 0.4f;
((PickupableItem)cofreItem).big = true;
PrefabCofre.AddComponent<SaveablePrefab>().prefabIndex = 24702;
Tesoros.Cargar(val, ((BaseUnityPlugin)this).Logger);
Mapas.CargarTexturas(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "mapas"), ((BaseUnityPlugin)this).Logger);
try
{
PrepararCofreGrande(val);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("COFRE GRANDE: no se ha podido preparar: " + ex));
PrefabCofreGrande = null;
}
}
private void PrepararCofreGrande(AssetBundle paquete)
{
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
PrefabCofreGrande = paquete.LoadAsset<GameObject>("cofre_grande");
if ((Object)(object)PrefabCofreGrande == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Falta el prefab 'cofre_grande' en tesoro_bundle");
return;
}
AjustarColores(PrefabCofreGrande);
MeshFilter val2;
MeshRenderer val3;
int num;
if ((Object)(object)PrefabCofreGrande.GetComponent<Renderer>() == (Object)null)
{
Transform val = PrefabCofreGrande.transform.Find("cuerpo");
val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshFilter>() : null);
val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshRenderer>() : null);
if ((Object)(object)val != (Object)null)
{
Vector3 val4 = val.localPosition;
if (((Vector3)(ref val4)).sqrMagnitude < 1E-06f && Quaternion.Angle(val.localRotation, Quaternion.identity) < 0.01f)
{
val4 = val.localScale - Vector3.one;
num = ((((Vector3)(ref val4)).sqrMagnitude < 1E-06f) ? 1 : 0);
goto IL_00e1;
}
}
num = 0;
goto IL_00e1;
}
goto IL_0147;
IL_0147:
CofreGrandeItem cofreGrandeItem = PrefabCofreGrande.AddComponent<CofreGrandeItem>();
((PickupableItem)cofreGrandeItem).holdDistance = 1.4f;
((PickupableItem)cofreGrandeItem).holdHeight = -0.45f;
((PickupableItem)cofreGrandeItem).furniturePlaceHeight = 0f;
((ShipItem)cofreGrandeItem).mass = 40f;
((ShipItem)cofreGrandeItem).value = 36700;
((ShipItem)cofreGrandeItem).name = "great treasure chest";
((ShipItem)cofreGrandeItem).category = (TransactionCategory)3;
((ShipItem)cofreGrandeItem).inventoryScale = 0.25f;
((PickupableItem)cofreGrandeItem).big = true;
PrefabCofreGrande.AddComponent<SaveablePrefab>().prefabIndex = 24712;
((BaseUnityPlugin)this).Logger.LogInfo((object)"COFRE GRANDE: preparado");
return;
IL_00e1:
bool flag = (byte)num != 0;
if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null && flag)
{
PrefabCofreGrande.AddComponent<MeshFilter>().sharedMesh = val2.sharedMesh;
((Renderer)PrefabCofreGrande.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val3).sharedMaterials;
((Renderer)val3).enabled = false;
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"COFRE GRANDE: el cuerpo no esta en (0,0,0); uso un renderer vacio");
PrefabCofreGrande.AddComponent<MeshRenderer>();
}
goto IL_0147;
}
public static void AjustarColoresPublico(GameObject go)
{
AjustarColores(go);
}
private static void AjustarColores(GameObject go)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: 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)
HashSet<Material> hashSet = new HashSet<Material>();
Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
Material[] sharedMaterials = componentsInChildren[i].sharedMaterials;
foreach (Material val in sharedMaterials)
{
if (!((Object)(object)val == (Object)null) && hashSet.Add(val))
{
if (val.HasProperty("_Color"))
{
Color color = val.color;
val.color = new Color(Mathf.LinearToGammaSpace(color.r), Mathf.LinearToGammaSpace(color.g), Mathf.LinearToGammaSpace(color.b), color.a);
}
if (val.HasProperty("_Metallic"))
{
val.SetFloat("_Metallic", 0f);
}
}
}
}
}
private static void Insertar(PrefabsDirectory dir)
{
if ((Object)(object)PrefabBotella == (Object)null || registrado)
{
return;
}
if (24701 < dir.directory.Length && (Object)(object)dir.directory[24701] != (Object)null && (Object)(object)dir.directory[24701] != (Object)(object)PrefabBotella)
{
Debug.LogError((object)("VDM Treasure Hunt: la posicion " + 24701 + " ya esta ocupada por otro objeto"));
return;
}
int num = Mathf.Max(24701, Mathf.Max(24702, 24712)) + 1;
if (dir.directory.Length < num)
{
GameObject[] array = (GameObject[])(object)new GameObject[num];
dir.directory.CopyTo(array, 0);
dir.directory = array;
}
dir.directory[24701] = PrefabBotella;
registrado = true;
CopiarFlotacion(dir);
if ((Object)(object)PrefabCofre != (Object)null)
{
if (24702 >= dir.directory.Length)
{
GameObject[] array2 = (GameObject[])(object)new GameObject[24703];
dir.directory.CopyTo(array2, 0);
dir.directory = array2;
}
if ((Object)(object)dir.directory[24702] != (Object)null && (Object)(object)dir.directory[24702] != (Object)(object)PrefabCofre)
{
Debug.LogError((object)("VDM Treasure Hunt: la posicion " + 24702 + " ya esta ocupada por otro objeto"));
}
else
{
dir.directory[24702] = PrefabCofre;
AccessTools.Field(typeof(ShipItemCrate), "containedPrefab").SetValue(PrefabCofre.GetComponent<CofreItem>(), dir.directory[33]);
}
}
if ((Object)(object)PrefabCofreGrande != (Object)null)
{
if ((Object)(object)dir.directory[24712] != (Object)null && (Object)(object)dir.directory[24712] != (Object)(object)PrefabCofreGrande)
{
Debug.LogError((object)("VDM Treasure Hunt: la posicion " + 24712 + " ya esta ocupada por otro objeto"));
}
else
{
dir.directory[24712] = PrefabCofreGrande;
}
}
Tesoros.Registrar(dir);
Mapas.Registrar(dir, ((Object)(object)Instancia != (Object)null) ? ((BaseUnityPlugin)Instancia).Logger : null);
}
private static void CopiarFlotacion(PrefabsDirectory dir)
{
if (dir.directory.Length <= 59 || (Object)(object)dir.directory[59] == (Object)null)
{
return;
}
ShipItem component = dir.directory[59].GetComponent<ShipItem>();
ShipItem component2 = PrefabBotella.GetComponent<ShipItem>();
if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
{
return;
}
Type type = typeof(ShipItem);
while (type != null && type != typeof(MonoBehaviour))
{
FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
string text = fieldInfo.Name.ToLower();
if ((text.Contains("float") || text.Contains("buoy") || text.Contains("drag") || text.Contains("water") || text == "mass") && (!(fieldInfo.FieldType != typeof(float)) || !(fieldInfo.FieldType != typeof(bool)) || !(fieldInfo.FieldType != typeof(int))))
{
object value = fieldInfo.GetValue(component2);
object value2 = fieldInfo.GetValue(component);
fieldInfo.SetValue(component2, value2);
Debug.Log((object)("VDM Treasure Hunt: flotacion " + type.Name + "." + fieldInfo.Name + " = " + value2?.ToString() + " (antes " + value?.ToString() + ")"));
}
}
type = type.BaseType;
}
}
private IEnumerator PonerEnTienda()
{
while (!registrado)
{
yield return (object)new WaitForSeconds(1f);
}
GameObject raiz = null;
for (int i = 0; i < 30; i++)
{
if (!((Object)(object)raiz == (Object)null))
{
break;
}
Scene sceneByName = SceneManager.GetSceneByName(tiendaEscena.Value);
if (((Scene)(ref sceneByName)).isLoaded)
{
GameObject[] rootGameObjects = ((Scene)(ref sceneByName)).GetRootGameObjects();
foreach (GameObject val in rootGameObjects)
{
if (((Object)val).name == tiendaRaiz.Value)
{
raiz = val;
break;
}
}
}
if ((Object)(object)raiz == (Object)null)
{
yield return (object)new WaitForSeconds(1f);
}
}
if ((Object)(object)raiz == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("TIENDA: no encuentro " + tiendaRaiz.Value));
}
else if (!((Object)(object)raiz.transform.Find("botella spawner") != (Object)null))
{
puesto = new GameObject("botella spawner");
puesto.transform.parent = raiz.transform;
puesto.transform.localPosition = new Vector3(tiendaX.Value, tiendaY.Value, tiendaZ.Value);
puesto.transform.localRotation = Quaternion.Euler(tiendaInclinacion.Value, tiendaGiro.Value, 0f);
puesto.AddComponent<MeshFilter>().sharedMesh = PrefabBotella.GetComponentInChildren<MeshFilter>().sharedMesh;
puesto.AddComponent<MeshRenderer>();
puesto.AddComponent<ShopItemSpawner>().itemPrefab = PrefabBotella;
}
}
private void Update()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (Time.time >= proximoBrillo)
{
proximoBrillo = Time.time + 1f;
PonerBrillos();
}
if (teclaLocalizar != null && (int)teclaLocalizar.Value != 0 && Input.GetKeyDown(teclaLocalizar.Value))
{
Localizar();
}
if ((Object)(object)puesto != (Object)null)
{
puesto.transform.localPosition = new Vector3(tiendaX.Value, tiendaY.Value, tiendaZ.Value);
puesto.transform.localRotation = Quaternion.Euler(tiendaInclinacion.Value, tiendaGiro.Value, 0f);
}
}
private void PonerBrillos()
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
BotellaItem.Todas.RemoveWhere(SinBotella);
foreach (BotellaItem toda in BotellaItem.Todas)
{
if (!conBrillo.Contains(toda))
{
conBrillo.Add(toda);
Destello destello = new GameObject("brillo botella").AddComponent<Destello>();
destello.botella = (ShipItem)(object)toda;
Object.DontDestroyOnLoad((Object)(object)((Component)destello).gameObject);
((BaseUnityPlugin)this).Logger.LogInfo((object)"TESORO: brillo puesto a una botella");
}
}
conBrillo.RemoveWhere(SinBotella);
}
private void Localizar()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0394: Unknown result type (might be due to invalid IL or missing references)
//IL_0399: 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_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
if ((Object)(object)main == (Object)null)
{
return;
}
RaycastHit val = default(RaycastHit);
bool flag = false;
float num = float.MaxValue;
RaycastHit[] array = Physics.RaycastAll(((Component)main).transform.position, ((Component)main).transform.forward, 20f, -1, (QueryTriggerInteraction)1);
for (int i = 0; i < array.Length; i++)
{
RaycastHit val2 = array[i];
bool flag2 = false;
Transform val3 = ((RaycastHit)(ref val2)).transform;
while ((Object)(object)val3 != (Object)null)
{
if (((Object)val3).name.StartsWith("OVRPlayerController") || (Object)(object)val3 == (Object)(object)((Component)main).transform)
{
flag2 = true;
break;
}
val3 = val3.parent;
}
if (!flag2 && !(((RaycastHit)(ref val2)).distance >= num))
{
num = ((RaycastHit)(ref val2)).distance;
val = val2;
flag = true;
}
}
if (!flag)
{
return;
}
Transform val4 = null;
string text = "";
Transform val5 = ((RaycastHit)(ref val)).transform;
while ((Object)(object)val5 != (Object)null)
{
text = ((Object)val5).name + ((text == "") ? "" : (" > " + text));
if ((Object)(object)val4 == (Object)null && ((Object)val5).name.StartsWith("island "))
{
val4 = val5;
}
val5 = val5.parent;
}
Vector3 val7;
if ((Object)(object)val4 == (Object)null)
{
float num2 = float.MaxValue;
Transform[] componentsInChildren = ((Component)((RaycastHit)(ref val)).transform.root).GetComponentsInChildren<Transform>();
foreach (Transform val6 in componentsInChildren)
{
if (((Object)val6).name.StartsWith("island "))
{
val7 = val6.position - ((RaycastHit)(ref val)).point;
float sqrMagnitude = ((Vector3)(ref val7)).sqrMagnitude;
if (sqrMagnitude < num2)
{
num2 = sqrMagnitude;
val4 = val6;
}
}
}
}
if ((Object)(object)val4 == (Object)null)
{
val4 = ((RaycastHit)(ref val)).transform.root;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("LOCALIZAR: cadena de padres: " + text));
Vector3 val8 = val4.InverseTransformPoint(((RaycastHit)(ref val)).point);
ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
string[] obj = new string[13]
{
"LOCALIZAR: escena '", null, null, null, null, null, null, null, null, null,
null, null, null
};
Scene scene = ((Component)val4).gameObject.scene;
obj[1] = ((Scene)(ref scene)).name;
obj[2] = "', raiz '";
obj[3] = ((Object)val4).name;
obj[4] = "', objeto '";
obj[5] = ((Object)((RaycastHit)(ref val)).transform).name;
obj[6] = "', punto respecto a la raiz (";
obj[7] = val8.x.ToString("F3");
obj[8] = ", ";
obj[9] = val8.y.ToString("F3");
obj[10] = ", ";
obj[11] = val8.z.ToString("F3");
obj[12] = ")";
logger.LogInfo((object)string.Concat(obj));
try
{
string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "escondites_marcados.txt");
string[] obj2 = new string[13]
{
DateTime.Now.ToString("dd/MM HH:mm"),
" | ",
((Object)val4).name,
" | punto ",
val8.x.ToString("F3", CultureInfo.InvariantCulture),
"; ",
val8.y.ToString("F3", CultureInfo.InvariantCulture),
"; ",
val8.z.ToString("F3", CultureInfo.InvariantCulture),
" | toca '",
((Object)((RaycastHit)(ref val)).transform).name,
"' | mundo ",
null
};
val7 = ((RaycastHit)(ref val)).point;
obj2[12] = ((Vector3)(ref val7)).ToString("F1");
string text2 = string.Concat(obj2);
File.AppendAllText(path, text2 + Environment.NewLine);
NotificationUi instance = NotificationUi.instance;
if (instance != null)
{
instance.ShowNotification("escondite marcado");
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("No he podido apuntar el escondite: " + ex.Message));
}
}
public void AbrirBotella(BotellaItem botella)
{
((MonoBehaviour)this).StartCoroutine(Abrir(botella));
}
private IEnumerator Abrir(BotellaItem botella)
{
int num = Mapas.ElegirSitio();
int num2 = ((num >= 0) ? (24720 + num) : 115);
GameObject modelo = (((Object)(object)PrefabsDirectory.instance != (Object)null && num2 < PrefabsDirectory.instance.directory.Length) ? PrefabsDirectory.instance.directory[num2] : null);
((BaseUnityPlugin)this).Logger.LogInfo((object)("TESORO: la botella trae el mapa de " + ((num >= 0) ? Escondites.Lista[num].Clave : "(ninguno libre)")));
if ((Object)(object)modelo == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"TESORO: no encuentro el pergamino del juego");
yield break;
}
Vector3 donde = ((Component)botella).transform.position;
Quaternion giro = ((Component)botella).transform.rotation;
GoPointer puntero = Object.FindObjectOfType<GoPointer>();
bool soltada = LlamarSoltar(puntero);
yield return (object)new WaitForFixedUpdate();
if (!soltada)
{
Traverse.Create((object)botella).Field("held").SetValue((object)null);
}
MethodInfo methodInfo = AccessTools.Method(typeof(ShipItem), "DestroyItem", (Type[])null, (Type[])null);
if (methodInfo != null && methodInfo.GetParameters().Length == 0)
{
try
{
methodInfo.Invoke(botella, null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"TESORO: botella destruida con DestroyItem");
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("TESORO: DestroyItem fallo: " + (ex.InnerException ?? ex).Message));
}
}
else
{
SaveablePrefab component = ((Component)botella).GetComponent<SaveablePrefab>();
MethodInfo methodInfo2 = AccessTools.Method(typeof(SaveablePrefab), "Unregister", (Type[])null, (Type[])null);
if ((Object)(object)component != (Object)null && methodInfo2 != null)
{
methodInfo2.Invoke(component, null);
}
if ((Object)(object)((ShipItem)botella).itemRigidbodyC != (Object)null)
{
Object.Destroy((Object)(object)((Component)((ShipItem)botella).itemRigidbodyC).gameObject);
}
Object.Destroy((Object)(object)((Component)botella).gameObject);
}
GameObject val = Object.Instantiate<GameObject>(modelo, donde, giro);
ShipItem si = val.GetComponent<ShipItem>();
if ((Object)(object)si == (Object)null)
{
Object.Destroy((Object)(object)val);
yield break;
}
si.sold = true;
SaveablePrefab component2 = val.GetComponent<SaveablePrefab>();
MethodInfo methodInfo3 = (((Object)(object)component2 != (Object)null) ? AccessTools.Method(typeof(SaveablePrefab), "RegisterToSave", (Type[])null, (Type[])null) : null);
if (methodInfo3 != null && methodInfo3.GetParameters().Length == 0)
{
methodInfo3.Invoke(component2, null);
}
for (int i = 0; i < 30; i++)
{
if (!((Object)(object)si.itemRigidbodyC == (Object)null))
{
break;
}
yield return (object)new WaitForFixedUpdate();
}
yield return (object)new WaitForFixedUpdate();
MethodInfo methodInfo4 = AccessTools.Method(((object)si).GetType(), "OnLoad", (Type[])null, (Type[])null);
if (methodInfo4 != null && methodInfo4.GetParameters().Length == 0)
{
try
{
methodInfo4.Invoke(si, null);
}
catch (Exception ex2)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("TESORO: OnLoad del pergamino fallo: " + (ex2.InnerException ?? ex2).Message));
}
}
if ((Object)(object)puntero != (Object)null)
{
MethodInfo[] methods = typeof(GoPointer).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo5 in methods)
{
if (methodInfo5.Name != "PickUpItem")
{
continue;
}
ParameterInfo[] parameters = methodInfo5.GetParameters();
if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(((object)si).GetType()))
{
try
{
methodInfo5.Invoke(puntero, new object[1] { si });
}
catch (Exception ex3)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("TESORO: no he podido darte el pergamino: " + (ex3.InnerException ?? ex3).Message));
}
break;
}
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"TESORO: botella abierta, pergamino en la mano");
NotificationUi instance = NotificationUi.instance;
if (instance != null)
{
instance.ShowNotification("You break the bottle\nand take out the message");
}
if ((Object)(object)sonidoRotura != (Object)null && (Object)(object)Camera.main != (Object)null)
{
AudioSource.PlayClipAtPoint(sonidoRotura, ((Component)Camera.main).transform.position + ((Component)Camera.main).transform.forward * 0.5f, 0.7f);
}
}
private AudioClip CargarWav(string ruta)
{
try
{
if (!File.Exists(ruta))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("No encuentro el sonido " + ruta));
return null;
}
byte[] array = File.ReadAllBytes(ruta);
int num = 1;
int num2 = 44100;
int num3 = 16;
int i = 12;
int num4 = -1;
int num5 = 0;
int num6;
for (; i + 8 <= array.Length; i += 8 + num6 + (num6 & 1))
{
string text = Encoding.ASCII.GetString(array, i, 4);
num6 = BitConverter.ToInt32(array, i + 4);
if (text == "fmt ")
{
num = BitConverter.ToInt16(array, i + 10);
num2 = BitConverter.ToInt32(array, i + 12);
num3 = BitConverter.ToInt16(array, i + 22);
}
else if (text == "data")
{
num4 = i + 8;
num5 = Mathf.Min(num6, array.Length - num4);
break;
}
}
if (num4 < 0 || num3 != 16)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("El sonido " + ruta + " no es un wav de 16 bits"));
return null;
}
int num7 = num5 / 2;
float[] array2 = new float[num7];
for (int j = 0; j < num7; j++)
{
array2[j] = (float)BitConverter.ToInt16(array, num4 + j * 2) / 32768f;
}
AudioClip obj = AudioClip.Create("botella rota", num7 / num, num, num2, false);
obj.SetData(array2, 0);
return obj;
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("No he podido cargar el sonido: " + ex.Message));
return null;
}
}
private bool LlamarSoltar(GoPointer puntero)
{
if ((Object)(object)puntero == (Object)null)
{
return false;
}
string[] array = new string[3] { "DropItem", "DropHeldItem", "ReleaseItem" };
foreach (string text in array)
{
MethodInfo methodInfo = AccessTools.Method(typeof(GoPointer), text, (Type[])null, (Type[])null);
if (methodInfo != null && methodInfo.GetParameters().Length == 0)
{
try
{
methodInfo.Invoke(puntero, null);
((BaseUnityPlugin)this).Logger.LogInfo((object)("TESORO: botella soltada con " + text));
return true;
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("TESORO: " + text + " fallo: " + (ex.InnerException ?? ex).Message));
}
}
}
((BaseUnityPlugin)this).Logger.LogWarning((object)"TESORO: no encuentro como soltar lo que llevas en la mano");
return false;
}
}
[DefaultExecutionOrder(1000)]
public class BotellaItem : ShipItem
{
public static readonly HashSet<BotellaItem> Todas = new HashSet<BotellaItem>();
private const string TextoSuelta = "message in a bottle";
private const string TextoEnMano = "message in a bottle\npress R to open it";
private bool apuntada;
private bool pulsadoEsteFotograma;
private bool pulsadoAntes;
private bool botonLiberado = true;
private bool abierta;
public override void OnBuy()
{
botonLiberado = false;
}
public override void OnAltHeld()
{
pulsadoEsteFotograma = true;
}
public override void ExtraLateUpdate()
{
bool flag = pulsadoEsteFotograma;
pulsadoEsteFotograma = false;
bool flag2 = flag && !pulsadoAntes;
pulsadoAntes = flag;
if (!flag)
{
botonLiberado = true;
}
if (!apuntada)
{
apuntada = true;
Todas.Add(this);
}
if (base.sold)
{
string text = (((Object)(object)((PickupableItem)this).held != (Object)null) ? "message in a bottle\npress R to open it" : "message in a bottle");
if ((object)((GoPointerButton)this).lookText != text)
{
((GoPointerButton)this).lookText = text;
}
}
if (!((Object)(object)((PickupableItem)this).held == (Object)null) && !abierta && flag2 && base.sold && botonLiberado && (Object)(object)Plugin.Instancia != (Object)null)
{
abierta = true;
Plugin.Instancia.AbrirBotella(this);
}
}
}
public class Destello : MonoBehaviour
{
private static Material material;
private static Mesh malla;
public ShipItem botella;
private GameObject brillo;
private Renderer dibujo;
private float proximo;
private float inicio = -10f;
private const float NivelMar = 0f;
private const float DuracionDestello = 0.5f;
private void Start()
{
if ((Object)(object)material == (Object)null)
{
CrearRecursos();
}
brillo = ((Component)this).gameObject;
brillo.AddComponent<MeshFilter>().sharedMesh = malla;
MeshRenderer val = brillo.AddComponent<MeshRenderer>();
((Renderer)val).sharedMaterial = material;
((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val).receiveShadows = false;
dibujo = (Renderer)(object)val;
dibujo.enabled = false;
proximo = Time.time + Random.Range(1f, 4f);
}
private void LateUpdate()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: 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_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)botella == (Object)null)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
return;
}
Camera main = Camera.main;
if ((Object)(object)dibujo == (Object)null || (Object)(object)main == (Object)null)
{
return;
}
float y = ((Component)botella).transform.position.y;
bool flag = (Object)(object)botella.itemRigidbodyC != (Object)null && (Object)(object)botella.itemRigidbodyC.GetCurrentInventorySlot() != (Object)null;
if (!((Object)(object)((PickupableItem)botella).held == (Object)null) || flag || !((Object)(object)botella.currentActualBoat == (Object)null) || !(y > -3f) || !(y < 1.2f))
{
dibujo.enabled = false;
return;
}
Vector3 val = ((Component)botella).transform.position + Vector3.up * 0.6f;
float num = Vector3.Distance(((Component)main).transform.position, val);
brillo.transform.position = val;
brillo.transform.rotation = Quaternion.LookRotation(val - ((Component)main).transform.position, ((Component)main).transform.up);
float num3;
Color color = default(Color);
if ((Object)(object)RenderSettings.sun != (Object)null && ((Component)RenderSettings.sun).transform.forward.y > 0.05f)
{
float num2 = 0.5f + 0.5f * Mathf.Sin(Time.time * 1.6f);
num3 = Mathf.Clamp(0.8f + num * 0.03f, 0.8f, 6f);
float num4 = 0.25f + 0.35f * num2;
((Color)(ref color))..ctor(0.45f, 1f, 0.7f, num4);
}
else
{
if (Time.time >= proximo)
{
inicio = Time.time;
proximo = Time.time + Random.Range(2f, 4f);
}
float num5 = (Time.time - inicio) / 0.5f;
if (num5 < 0f || num5 > 1f)
{
dibujo.enabled = false;
return;
}
float num6 = Mathf.Sin(num5 * (float)Math.PI);
num3 = Mathf.Clamp(1.2f + num * 0.07f, 1.2f, 14f) * (0.5f + 0.5f * num6);
float num4 = num6;
((Color)(ref color))..ctor(1f, 0.95f, 0.75f, num4);
}
dibujo.enabled = true;
brillo.transform.localScale = Vector3.one * num3;
material.color = color;
}
private static void CrearRecursos()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Expected O, but got Unknown
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Expected O, but got Unknown
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
int num = 64;
Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
((Texture)val).wrapMode = (TextureWrapMode)1;
for (int i = 0; i < num; i++)
{
for (int j = 0; j < num; j++)
{
float num2 = ((float)i - (float)num / 2f + 0.5f) / ((float)num / 2f);
float num3 = ((float)j - (float)num / 2f + 0.5f) / ((float)num / 2f);
float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
float num5 = Mathf.Clamp01(1f - num4 * 2.2f);
float num6 = Mathf.Clamp01(1f - Mathf.Abs(num2) * 14f) * Mathf.Clamp01(1f - Mathf.Abs(num3)) + Mathf.Clamp01(1f - Mathf.Abs(num3) * 14f) * Mathf.Clamp01(1f - Mathf.Abs(num2));
float num7 = Mathf.Clamp01(num5 * num5 + num6 * 0.8f + Mathf.Clamp01(1f - num4) * 0.15f);
val.SetPixel(i, j, new Color(1f, 1f, 1f, num7));
}
}
val.Apply();
material = new Material(Shader.Find("Sprites/Default"));
material.mainTexture = (Texture)(object)val;
material.renderQueue = 3100;
malla = new Mesh();
malla.vertices = (Vector3[])(object)new Vector3[4]
{
new Vector3(-0.5f, -0.5f, 0f),
new Vector3(0.5f, -0.5f, 0f),
new Vector3(0.5f, 0.5f, 0f),
new Vector3(-0.5f, 0.5f, 0f)
};
malla.uv = (Vector2[])(object)new Vector2[4]
{
new Vector2(0f, 0f),
new Vector2(1f, 0f),
new Vector2(1f, 1f),
new Vector2(0f, 1f)
};
malla.triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
malla.RecalculateBounds();
}
}
public class Naufragio : MonoBehaviour
{
public static Naufragio Instancia;
private ManualLogSource log;
private const float ProbOro = 0.015f;
private const float ProbPlata = 0.05f;
private const float ProbGrande = 0.005f;
private ConfigEntry<float> probabilidad;
private ConfigEntry<float> cadaSegundos;
private ConfigEntry<float> distMin;
private ConfigEntry<float> distMax;
private ConfigEntry<float> angulo;
private ConfigEntry<float> distBorrar;
private ConfigEntry<float> radioSinIslas;
private ConfigEntry<float> velocidadMin;
private readonly List<ShipItem> flotando = new List<ShipItem>();
private readonly Dictionary<ShipItem, float> lejosDesde = new Dictionary<ShipItem, float>();
private Vector3 posAnterior;
private Vector3 rumbo = Vector3.forward;
private float tAnterior;
private float velocidad;
private float proximaTirada;
private static readonly int[] Pescado = new int[8] { 31, 32, 33, 34, 35, 36, 37, 38 };
private static readonly int[] Carne = new int[4] { 39, 41, 54, 154 };
private static readonly int[] Verdura = new int[4] { 150, 151, 152, 153 };
private static readonly int[] Fruta = new int[5] { 44, 147, 149, 42, 49 };
private static readonly int[] Barriles = new int[3] { 10, 13, 11 };
private const int CajaVacia = 1;
private const int CajaOro = 22;
private const int CajaPlata = 226;
private int forzarExtra = -1;
private float proximaBusqueda;
private ConfigEntry<float> distTesoro;
private int pruebaN;
private static readonly string[] TiposTesoro = new string[8] { "cofre pirata", "taberna", "tabaco", "lana y cuero", "contrabandista", "noble", "especiero", "gourmet" };
private static readonly float[] PesosTesoro = new float[8] { 10f, 22f, 20f, 17f, 12f, 9f, 6f, 4f };
private static readonly int[][] Alijos = new int[8][]
{
null,
new int[4] { 11, 11, 12, 232 },
new int[3] { 207, 210, 232 },
new int[2] { 222, 219 },
new int[4] { 11, 11, 28, 211 },
new int[3] { 28, 230, 30 },
new int[3] { 234, 24, 5 },
new int[2] { 202, 13 }
};
private int pruebaTesoro;
private List<int> maderas;
private int cajaPequena = -1;
public void Configurar(ConfigFile cfg, ManualLogSource logger)
{
Instancia = this;
log = logger;
probabilidad = cfg.Bind<float>("Shipwreck", "Chance", 0.01f, "Chance (0-1) of finding wreckage at each check while sailing in open sea");
cadaSegundos = cfg.Bind<float>("Shipwreck", "CheckEverySeconds", 60f, "Seconds between checks");
distMin = cfg.Bind<float>("Shipwreck", "MinDistance", 150f, "Minimum distance ahead of you (m)");
distMax = cfg.Bind<float>("Shipwreck", "MaxDistance", 300f, "Maximum distance ahead of you (m)");
angulo = cfg.Bind<float>("Shipwreck", "Angle", 45f, "Degrees left/right of your heading");
distBorrar = cfg.Bind<float>("Shipwreck", "RemoveDistance", 500f, "Wreckage you leave behind disappears at this distance (m)");
radioSinIslas = cfg.Bind<float>("Shipwreck", "NoLandRadius", 400f, "No land may be closer than this to the wreckage (m)");
velocidadMin = cfg.Bind<float>("Shipwreck", "MinSpeed", 1.5f, "Only while moving at least this fast (m/s)");
distTesoro = cfg.Bind<float>("Treasure", "FindDistance", 60f, "The treasure appears when you get this close (m) to its hiding place with its map");
proximaTirada = Time.time + cadaSegundos.Value;
}
private void Update()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
if (log == null)
{
return;
}
Camera main = Camera.main;
if ((Object)(object)main == (Object)null || !GameState.playing || GameState.currentlyLoading)
{
return;
}
if (Time.time - tAnterior > 2f)
{
Vector3 val = ((Component)main).transform.position - posAnterior;
val.y = 0f;
float num = ((Vector3)(ref val)).magnitude / Mathf.Max(0.01f, Time.time - tAnterior);
if (num < 60f)
{
velocidad = num;
if (((Vector3)(ref val)).sqrMagnitude > 0.04f)
{
rumbo = ((Vector3)(ref val)).normalized;
}
}
posAnterior = ((Component)main).transform.position;
tAnterior = Time.time;
}
Vigilar(main);
if (Time.time >= proximaBusqueda)
{
proximaBusqueda = Time.time + 2f;
BuscarTesoros(main);
}
if (Time.time >= proximaTirada)
{
proximaTirada = Time.time + Mathf.Max(5f, cadaSegundos.Value);
Intentar(main, forzar: false);
}
}
private void BuscarTesoros(Camera cam)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: 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)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: 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_012f: 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_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
if (distTesoro == null)
{
return;
}
foreach (MapaTesoro item in Mapas.Activos())
{
if (item.Sitio < 0 || item.Sitio >= Escondites.Lista.Count)
{
continue;
}
Escondites.Sitio sitio = Escondites.Lista[item.Sitio];
Transform val = Escondites.Isla(sitio.Isla);
if (!((Object)(object)val == (Object)null) && !(Mathf.Abs(val.position.y) > 3f))
{
Vector3 val2 = val.TransformPoint(sitio.Local);
Vector3 val3 = val2 - ((Component)cam).transform.position;
val3.y = 0f;
if (!(((Vector3)(ref val3)).magnitude > distTesoro.Value))
{
item.Item.health = 7777f;
Vector3 val4 = val2;
log.LogInfo((object)("TESORO: llegas al escondite " + sitio.Clave + " (a " + ((Vector3)(ref val3)).magnitude.ToString("F0") + " m): aparece el tesoro"));
((MonoBehaviour)this).StartCoroutine(CrearTesoro(val4 + Vector3.up * 0.3f));
}
}
}
}
public void Forzar()
{
Camera main = Camera.main;
if ((Object)(object)main != (Object)null)
{
Intentar(main, forzar: true);
}
}
public void ProbarCofre()
{
//IL_004c: 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)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
pruebaN++;
forzarExtra = ((pruebaN % 3 == 1) ? 22 : ((pruebaN % 3 == 2) ? 226 : (-1)));
Camera main = Camera.main;
if (!((Object)(object)main == (Object)null))
{
Vector3 position = ((Component)main).transform.position;
Vector3 val = Vector3.ProjectOnPlane(((Component)main).transform.forward, Vector3.up);
Vector3 p = position + ((Vector3)(ref val)).normalized * 1.5f;
((MonoBehaviour)this).StartCoroutine(CrearCofre(p, Tesoros.BotinAlAzar().ToArray()));
}
}
public IEnumerator CrearTesoro(Vector3 p, int tipo = -1)
{
//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)
if (tipo < 0)
{
float num = 0f;
float[] pesosTesoro = PesosTesoro;
foreach (float num2 in pesosTesoro)
{
num += num2;
}
float num3 = Random.value * num;
for (tipo = 0; tipo < PesosTesoro.Length - 1; tipo++)
{
num3 -= PesosTesoro[tipo];
if (num3 <= 0f)
{
break;
}
}
}
log.LogInfo((object)("TESORO: " + TiposTesoro[tipo]));
if (Alijos[tipo] == null)
{
yield return CrearCofre(p, Tesoros.BotinAlAzar().ToArray());
yield break;
}
int[] cajas = Alijos[tipo];
for (int j = 0; j < cajas.Length; j++)
{
float num4 = (float)j * (float)Math.PI * 2f / (float)cajas.Length;
Vector3 pos = p + new Vector3(Mathf.Cos(num4), 0f, Mathf.Sin(num4)) * 0.9f + Vector3.up * 0.4f;
yield return CrearObjeto(cajas[j], pos, delegate
{
});
}
}
public void ProbarTesoro()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
if ((Object)(object)main == (Object)null)
{
return;
}
Vector3 position = ((Component)main).transform.position;
Vector3 val = Vector3.ProjectOnPlane(((Component)main).transform.forward, Vector3.up);
Vector3 p = position + ((Vector3)(ref val)).normalized * 2.5f;
int num = pruebaTesoro % TiposTesoro.Length;
pruebaTesoro++;
if (num == 0)
{
List<int> list = Tesoros.BotinAlAzar();
if (Tesoros.Caliz != null && !list.Contains(Tesoros.Caliz.Indice))
{
list.Insert(0, Tesoros.Caliz.Indice);
}
if (Tesoros.Cruz != null && !list.Contains(Tesoros.Cruz.Indice))
{
list.Insert(0, Tesoros.Cruz.Indice);
}
((MonoBehaviour)this).StartCoroutine(CrearCofre(p, list.ToArray()));
}
else
{
((MonoBehaviour)this).StartCoroutine(CrearTesoro(p, num));
}
}
public void ProbarCofreGrande()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_0047: 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)
Camera main = Camera.main;
if (!((Object)(object)main == (Object)null))
{
Vector3 position = ((Component)main).transform.position;
Vector3 val = Vector3.ProjectOnPlane(((Component)main).transform.forward, Vector3.up);
Vector3 p = position + ((Vector3)(ref val)).normalized * 2f;
((MonoBehaviour)this).StartCoroutine(CrearCofreGrande(p));
}
}
private IEnumerator CrearCofreGrande(Vector3 p)
{
//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)
ShipItem cg = null;
yield return CrearObjeto(24712, p, delegate(ShipItem x)
{
cg = x;
});
if (!((Object)(object)cg == (Object)null))
{
LlamarOnLoad(cg);
log.LogInfo((object)"COFRE GRANDE: creado");
}
}
public IEnumerator CrearCofre(Vector3 p, int[] contenido)
{
//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)
ShipItem cofre = null;
yield return CrearObjeto(24702, p, delegate(ShipItem x)
{
cofre = x;
});
if ((Object)(object)cofre == (Object)null)
{
yield break;
}
CrateInventory inv = PrepararCaja(cofre);
if ((Object)(object)inv == (Object)null)
{
log.LogWarning((object)"COFRE: sin inventario");
yield break;
}
contenido = Tesoros.Recortar(contenido, Plugin.Instancia.ColumnasCofre * Plugin.Instancia.FilasCofre);
int[] array = contenido;
foreach (int indice in array)
{
ShipItem obj = null;
yield return CrearObjeto(indice, p + Vector3.up * 3f, delegate(ShipItem x)
{
obj = x;
});
if (!((Object)(object)obj == (Object)null))
{
yield return (object)new WaitForEndOfFrame();
obj.sold = true;
try
{
inv.InsertItem(obj);
}
catch (Exception ex)
{
log.LogWarning((object)("COFRE: no he podido meter " + obj.name + ": " + ex.Message));
}
}
}
float value = Random.value;
int num2 = ((value < 0.015f) ? 22 : ((value < 0.065f) ? 226 : (-1)));
if (forzarExtra >= 0)
{
num2 = forzarExtra;
forzarExtra = -1;
}
if (num2 >= 0)
{
Vector3 pos = p + ((Component)cofre).transform.right * 0.8f + Vector3.up * 0.3f;
ShipItem caja = null;
yield return CrearObjeto(num2, pos, delegate(ShipItem x)
{
caja = x;
});
log.LogInfo((object)("COFRE: con premio gordo al lado: " + (((Object)(object)caja != (Object)null) ? caja.name : "?")));
}
if (Random.value < 0.005f)
{
yield return CrearCofreGrande(p - ((Component)cofre).transform.right * 1.3f + Vector3.up * 0.3f);
}
string text = "";
int[] array2 = contenido;
for (int num3 = 0; num3 < array2.Length; num3++)
{
int num4 = array2[num3];
GameObject val = PrefabsDirectory.instance.directory[num4];
text = text + (((Object)(object)val != (Object)null) ? val.GetComponent<ShipItem>().name : num4.ToString()) + ", ";
}
log.LogInfo((object)("COFRE: creado con " + contenido.Length + " objetos: " + text));
}
private void Intentar(Camera cam, bool forzar)
{
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
if (!forzar)
{
if (velocidad < velocidadMin.Value)
{
return;
}
foreach (ShipItem item in flotando)
{
if (item is BotellaItem)
{
return;
}
}
if (Mapas.Activos().Count >= 2 || Random.value > probabilidad.Value)
{
return;
}
}
Vector3 val = Quaternion.Euler(0f, Random.Range(0f - angulo.Value, angulo.Value), 0f) * rumbo;
if (forzar)
{
Vector3 val2 = Vector3.ProjectOnPlane(((Component)cam).transform.forward, Vector3.up);
val = ((Vector3)(ref val2)).normalized;
}
float num = (forzar ? 25f : Random.Range(distMin.Value, distMax.Value));
Vector3 p = ((Component)cam).transform.position + val * num;
p.y = 0f;
if (!forzar && !MarAbierto(p))
{
log.LogInfo((object)"NAUFRAGIO: tocaba, pero hay tierra cerca");
return;
}
log.LogInfo((object)("NAUFRAGIO: restos a " + num.ToString("F0") + " m" + (forzar ? " (forzado)" : "")));
((MonoBehaviour)this).StartCoroutine(Crear(p));
}
private bool MarAbierto(Vector3 p)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: 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_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
RaycastHit val2 = default(RaycastHit);
for (int i = 0; i <= 8; i++)
{
Vector3 val = p;
if (i > 0)
{
val += Quaternion.Euler(0f, (float)i * 45f, 0f) * Vector3.forward * radioSinIslas.Value;
}
if (Physics.Raycast(new Vector3(val.x, 400f, val.z), Vector3.down, ref val2, 600f, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val2)).point.y > -4f)
{
return false;
}
}
return true;
}
private void Vigilar(Camera cam)
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
for (int num = flotando.Count - 1; num >= 0; num--)
{
ShipItem val = flotando[num];
if ((Object)(object)val == (Object)null)
{
flotando.RemoveAt(num);
}
else if ((Object)(object)((PickupableItem)val).held != (Object)null)
{
flotando.RemoveAt(num);
}
else
{
float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)cam).transform.position);
if (num2 > distBorrar.Value)
{
if (!lejosDesde.ContainsKey(val))
{
lejosDesde[val] = Time.time;
}
if (Time.time - lejosDesde[val] > 5f)
{
log.LogInfo((object)("NAUFRAGIO: borro " + val.name + " (a " + num2.ToString("F0") + " m)"));
lejosDesde.Remove(val);
Borrar(val);
flotando.RemoveAt(num);
}
}
else
{
lejosDesde.Remove(val);
}
}
}
}
private void Borrar(ShipItem s)
{
CrateInventory component = ((Component)s).GetComponent<CrateInventory>();
if ((Object)(object)component != (Object)null && Traverse.Create((object)component).Field("containedItems").GetValue() is IList c)
{
foreach (object item in new ArrayList(c))
{
ShipItem val = (ShipItem)((item is ShipItem) ? item : null);
if (val != null && (Object)(object)val != (Object)null)
{
Destruir(val);
}
}
}
Destruir(s);
}
private void Destruir(ShipItem s)
{
try
{
AccessTools.Method(typeof(ShipItem), "DestroyItem", (Type[])null, (Type[])null).Invoke(s, null);
}
catch (Exception ex)
{
log.LogWarning((object)("NAUFRAGIO: DestroyItem fallo (" + ex.Message + "), lo quito a mano"));
SaveablePrefab component = ((Component)s).GetComponent<SaveablePrefab>();
if ((Object)(object)component != (Object)null)
{
AccessTools.Method(typeof(SaveablePrefab), "Unregister", (Type[])null, (Type[])null)?.Invoke(component, null);
}
if ((Object)(object)s.itemRigidbodyC != (Object)null)
{
Object.Destroy((Object)(object)((Component)s.itemRigidbodyC).gameObject);
}
Object.Destroy((Object)(object)((Component)s).gameObject);
}
}
private IEnumerator Crear(Vector3 p)
{
//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)
ShipItem botella = null;
yield return CrearObjeto(24701, p + Vector3.up * 0.5f, delegate(ShipItem x)
{
botella = x;
});
if ((Object)(object)botella != (Object)null)
{
flotando.Add(botella);
}
Vector3 val = p + Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) * Vector3.forward * Random.Range(5f, 9f);
ShipItem barril = null;
yield return CrearObjeto(Barriles[Random.Range(0, Barriles.Length)], val + Vector3.up, delegate(ShipItem x)
{
barril = x;
});
if ((Object)(object)barril != (Object)null)
{
float valor = Mathf.Round(Random.Range(8f, 60f));
PonerNumero(barril, "health", valor);
flotando.Add(barril);
log.LogInfo((object)("NAUFRAGIO: barril de " + barril.name + " con " + valor + " litros"));
}
if (IndiceMadera() >= 0)
{
int trozos = Random.Range(2, 4);
for (int i = 0; i < trozos; i++)
{
int indice = IndiceMadera();
Vector3 val2 = p + Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) * Vector3.forward * Random.Range(4f, 12f);
ShipItem m = null;
yield return CrearObjeto(indice, val2 + Vector3.up, delegate(ShipItem x)
{
m = x;
});
if ((Object)(object)m != (Object)null)
{
flotando.Add(m);
}
}
}
Vector3 pc = p + Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) * Vector3.forward * Random.Range(5f, 9f);
ShipItem caja = null;
yield return CrearObjeto(CajaPequena(), pc + Vector3.up, delegate(ShipItem x)
{
caja = x;
});
if ((Object)(object)caja == (Object)null)
{
yield break;
}
CrateInventory inv = PrepararCaja(caja);
flotando.Add(caja);
if ((Object)(object)inv == (Object)null)
{
yield break;
}
int cuantos = Random.Range(3, 8);
string resumen = "";
for (int trozos = 0; trozos < cuantos; trozos++)
{
int[] array = trozos switch
{
1 => Fruta,
0 => Pescado,
_ => (new int[4][] { Pescado, Carne, Verdura, Fruta })[Random.Range(0, 4)],
};
ShipItem obj = null;
yield return CrearObjeto(array[Random.Range(0, array.Length)], pc + Vector3.up * 3f, delegate(ShipItem x)
{
obj = x;
});
if (!((Object)(object)obj == (Object)null))
{
yield return (object)new WaitForEndOfFrame();
obj.sold = true;
try
{
inv.InsertItem(obj);
resumen = resumen + obj.name + ", ";
}
catch (Exception ex)
{
log.LogWarning((object)("NAUFRAGIO: no he podido meter " + obj.name + ": " + ex.Message));
}
}
}
log.LogInfo((object)("NAUFRAGIO: caja con " + resumen));
}
private int IndiceMadera()
{
if (maderas == null)
{
maderas = new List<int>();
GameObject[] array = (((Object)(object)PrefabsDirectory.instance != (Object)null) ? PrefabsDirectory.instance.directory : null);
string text = "";
if (array != null)
{
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name.ToLower().Contains("driftwood") && (Object)(object)array[i].GetComponent<ShipItem>() != (Object)null)
{
maderas.Add(i);
text = text + ((Object)array[i]).name + ", ";
}
}
}
log.LogInfo((object)("NAUFRAGIO: maderas a la deriva: " + ((maderas.Count > 0) ? text : "no encontradas")));
}
if (maderas.Count <= 0)
{
return -1;
}
return maderas[Random.Range(0, maderas.Count)];
}
private int CajaPequena()
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
if (cajaPequena >= 0)
{
return cajaPequena;
}
int num = 1;
float num2 = float.MaxValue;
try
{
GameObject[] directory = PrefabsDirectory.instance.directory;
Mesh[] array = (((Object)(object)CrateInventoryUI.instance != (Object)null) ? CrateInventoryUI.instance.containerMeshes : null);
for (int i = 0; i < directory.Length; i++)
{
GameObject val = directory[i];
if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ShipItemCrate>() == (Object)null)
{
continue;
}
MeshFilter component = val.GetComponent<MeshFilter>();
if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null || (array != null && Array.IndexOf(array, component.sharedMesh) < 0))
{
continue;
}
Bounds bounds = component.sharedMesh.bounds;
Vector3 val2 = Vector3.Scale(((Bounds)(ref bounds)).size, val.transform.localScale);
float num3 = val2.x * val2.y * val2.z;
bool flag = false;
Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val3 in componentsInChildren)
{
if ((Object)(object)((Component)val3).gameObject != (Object)(object)val && ((Object)val3).name.StartsWith("small box"))
{
flag = true;
break;
}
}
if (!flag && num3 < num2)
{
num2 = num3;
num = i;
}
}
log.LogInfo((object)("NAUFRAGIO: caja pequena elegida: " + num + " (" + (((Object)(object)directory[num] != (Object)null) ? ((Object)directory[num]).name : "?") + "), volumen " + num2.ToString("0.000")));
}
catch (Exception ex)
{
log.LogWarning((object)("NAUFRAGIO: no he podido buscar la caja pequena: " + ex.Message));
}
cajaPequena = num;
return num;
}
private CrateInventory PrepararCaja(ShipItem caja)
{
LlamarOnLoad(caja);
CrateInventory val = ((Component)caja).GetComponent<CrateInventory>();
if ((Object)(object)val == (Object)null)
{
val = ((Component)caja).gameObject.AddComponent<CrateInventory>();
Traverse.Create((object)caja).Field("crateInventory").SetValue((object)val);
}
caja.amount = 0f;
try
{
caja.UpdateLookText();
}
catch
{
}
return val;
}
private void LlamarOnLoad(ShipItem s)
{
MethodInfo methodInfo = AccessTools.Method(((object)s).GetType(), "OnLoad", (Type[])null, (Type[])null);
if (methodInfo == null || methodInfo.GetParameters().Length != 0)
{
return;
}
try
{
methodInfo.Invoke(s, null);
}
catch (Exception ex)
{
log.LogWarning((object)("NAUFRAGIO: OnLoad de " + s.name + " fallo: " + (ex.InnerException ?? ex).Message));
}
}
private void SinMision(GameObject g)
{
Component[] components = g.GetComponents<Component>();
foreach (Component val in components)
{
if ((Object)(object)val == (Object)null || ((object)val).GetType().Name != "Good")
{
continue;
}
FieldInfo[] fields = ((object)val).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.FieldType == typeof(int) && fieldInfo.Name.ToLower().Contains("mission"))
{
fieldInfo.SetValue(val, -1);
}
}
}
}
private static void PonerNumero(object o, string nombre, float valor)
{
FieldInfo fieldInfo = AccessTools.Field(o.GetType(), nombre);
if (fieldInfo != null)
{
fieldInfo.SetValue(o, Convert.ChangeType(valor, fieldInfo.FieldType));
return;
}
PropertyInfo propertyInfo = AccessTools.Property(o.GetType(), nombre);
if (propertyInfo != null && propertyInfo.CanWrite)
{
propertyInfo.SetValue(o, Convert.ChangeType(valor, propertyInfo.PropertyType), null);
}
}
private IEnumerator CrearObjeto(int indice, Vector3 pos, Action<ShipItem> listo)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
GameObject[] array = (((Object)(object)PrefabsDirectory.instance != (Object)null) ? PrefabsDirectory.instance.directory : null);
if (array == null || indice >= array.Length || (Object)(object)array[indice] == (Object)null)
{
log.LogWarning((object)("NAUFRAGIO: no existe el objeto " + indice));
listo(null);
yield break;
}
GameObject val = Object.Instantiate<GameObject>(array[indice], pos, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
ShipItem si = val.GetComponent<ShipItem>();
if ((Object)(object)si == (Object)null)
{
Object.Destroy((Object)(object)val);
listo(null);
yield break;
}
si.sold = true;
SinMision(val);
SaveablePrefab component = val.GetComponent<SaveablePrefab>();
if ((Object)(object)component != (Object)null)
{
component.RegisterToSave();
}
for (int i = 0; i < 30; i++)
{
if (!((Object)(object)si.itemRigidbodyC == (Object)null))
{
break;
}
yield return (object)new WaitForFixedUpdate();
}
yield return (object)new WaitForFixedUpdate();
listo(si);
}
}
public class CofreItem : ShipItemCrate
{
public virtual string Nombre => "treasure chest";
public virtual int Precio
{
get
{
if (!((Object)(object)Plugin.Instancia != (Object)null))
{
return 1000;
}
return Plugin.Instancia.PrecioCofre;
}
}
public virtual int Columnas
{
get
{
if (!((Object)(object)Plugin.Instancia != (Object)null))
{
return 4;
}
return Plugin.Instancia.ColumnasCofre;
}
}
public virtual int Filas
{
get
{
if (!((Object)(object)Plugin.Instancia != (Object)null))
{
return 2;
}
return Plugin.Instancia.FilasCofre;
}
}
public override void OnLoad()
{
((ShipItemCrate)this).OnLoad();
((ShipItem)this).value = Precio;
((ShipItem)this).UpdateLookText();
}
public override void UpdateLookText()
{
try
{
((ShipItemCrate)this).UpdateLookText();
}
catch
{
}
if (((ShipItem)this).sold)
{
((GoPointerButton)this).lookText = Nombre;
}
}
}
public class CofreGrandeItem : ShipItem
{
private const float Abierta = -100f;
private const float Velocidad = 150f;
private Transform tapa;
private float angulo;
private bool abierto;
public override void OnLoad()
{
((ShipItem)this).OnLoad();
if ((Object)(object)Plugin.Instancia != (Object)null)
{
base.value = Plugin.Instancia.PrecioCofreGrande;
}
((ShipItem)this).UpdateLookText();
}
public override void UpdateLookText()
{
((ShipItem)this).UpdateLookText();
if (base.sold)
{
((GoPointerButton)this).lookText = "";
((GoPointerButton)this).description = "";
}
}
public override void OnAltActivate()
{
((ShipItem)this).OnAltActivate();
if (base.sold && (Object)(object)((PickupableItem)this).held == (Object)null)
{
abierto = !abierto;
}
}
public override void ExtraLateUpdate()
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
((GoPointerButton)this).ExtraLateUpdate();
if ((Object)(object)tapa == (Object)null)
{
tapa = ((Component)this).transform.Find("tapa");
if ((Object)(object)tapa == (Object)null)
{
return;
}
}
float num = (abierto ? (-100f) : 0f);
if (!Mathf.Approximately(angulo, num))
{
angulo = Mathf.MoveTowards(angulo, num, 150f * Time.deltaTime);
tapa.localRotation = Quaternion.Euler(angulo, 0f, 0f);
}
}
}
[HarmonyPatch(typeof(CrateInventoryUI), "GetCrateDimensions")]
public static class ParcheHuecosCofre
{
public static void Postfix(CrateInventoryUI __instance, ref Vector2 __result)
{
//IL_0042: 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)
if (!((Object)(object)__instance.currentCrate == (Object)null))
{
CofreItem component = ((Component)__instance.currentCrate).GetComponent<CofreItem>();
if (!((Object)(object)component == (Object)null))
{
__result = new Vector2((float)Mathf.Clamp(component.Columnas, 1, 6), (float)Mathf.Clamp(component.Filas, 1, 5));
}
}
}
}
public class TesoroItem : ShipItem
{
public float LupaHueco = 1f;
public int UltimoHueco = -10;
public override void ExtraLateUpdate()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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)
((GoPointerButton)this).ExtraLateUpdate();
if (Time.frameCount - UltimoHueco > 2 && ((Component)this).transform.localScale != Vector3.one)
{
((Component)this).transform.localScale = Vector3.one;
}
}
}
[HarmonyPatch(typeof(CrateInventoryButton), "UpdateItemPos")]
public static class ParcheLupaHueco
{
public static void Postfix(ShipItem ___currentItem)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
TesoroItem tesoroItem = ___currentItem as TesoroItem;
if (!((Object)(object)tesoroItem == (Object)null))
{
tesoroItem.UltimoHueco = Time.frameCount;
((Component)tesoroItem).transform.localScale = Vector3.one * tesoroItem.LupaHueco;
}
}
}
[HarmonyPatch(typeof(CrateInventoryButton), "PutItemBack")]
public static class ParcheLupaGuardar
{
public static void Prefix(ShipItem ___currentItem)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
TesoroItem tesoroItem = ___currentItem as TesoroItem;
if (!((Object)(object)tesoroItem == (Object)null))
{
tesoroItem.UltimoHueco = -10;
((Component)tesoroItem).transform.localScale = Vector3.one;
}
}
}
public static class Tesoros
{
public class Tipo
{
public int Indice;
public string Nombre;
public int Valor;
public float Peso;
public GameObject Prefab;
}
public static readonly List<Tipo> Lista = new List<Tipo>();
public static Tipo Doblon;
public static Tipo Lingote;
public static Tipo Diamante;
public static Tipo Cruz;
public static Tipo Caliz;
public static readonly List<Tipo> Gemas = new List<Tipo>();
private static GameObject almacen;
public static void Cargar(AssetBundle paquete, ManualLogSource log)
{
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
Doblon = Crear(paquete, "moneda", 24703, "gold doubloon", 400, 0.03f, log, 2f);
Lingote = Crear(paquete, "lingote", 24704, "gold ingot", 16000, 12f, log, 1f);
Diamante = Crear(paquete, "diamante", 24705, "diamond", 16000, 0.1f, log, 2f);
GirarEnHueco(Doblon, 90f);
GirarEnHueco(Diamante, -25f);
Lupa(Doblon, 1.6f);
Lupa(Lingote, 0.6f);
Lupa(Diamante, 1f);
Cruz = Crear(paquete, "cruz", 24713, "ceremonial cross", 18000, 1.2f, log, 1f);
Caliz = Crear(paquete, "caliz", 24714, "silver chalice", 9000, 0.6f, log, 1f);
Lupa(Cruz, 0.45f);
Lupa(Caliz, 0.6f);
GameObject val = paquete.LoadAsset<GameObject>("gema");
if ((Object)(object)val == (Object)null)
{
log.LogError((object)"Falta el prefab 'gema' en tesoro_bundle");
return;
}
Agrandar(val, 2f);
almacen = new GameObject("VDM Treasure Hunt plantillas");
almacen.SetActive(false);
Object.DontDestroyOnLoad((Object)(object)almacen);
CrearGema(val, 24706, "ruby", 3000, Color32.op_Implicit(new Color32((byte)200, (byte)16, (byte)46, byte.MaxValue)), log);
CrearGema(val, 24707, "citrine", 1170, Color32.op_Implicit(new Color32((byte)232, (byte)130, (byte)30, byte.MaxValue)), log);
CrearGema(val, 24708, "topaz", 1500, Color32.op_Implicit(new Color32((byte)242, (byte)196, (byte)15, byte.MaxValue)), log);
CrearGema(val, 24709, "emerald", 3340, Color32.op_Implicit(new Color32((byte)30, (byte)155, (byte)79, byte.MaxValue)), log);
CrearGema(val, 24710, "sapphire", 3000, Color32.op_Implicit(new Color32((byte)31, (byte)79, (byte)200, byte.MaxValue)), log);
CrearGema(val, 24711, "amethyst", 1840, Color32.op_Implicit(new Color32((byte)142, (byte)63, (byte)201, byte.MaxValue)), log);
}
private static Tipo Crear(AssetBundle paquete, string asset, int indice, string nombre, int valor, float peso, ManualLogSource log, float tamano)
{
GameObject val = paquete.LoadAsset<GameObject>(asset);
if ((Object)(object)val == (Object)null)
{
log.LogError((object)("Falta el prefab '" + asset + "' en tesoro_bundle"));
return null;
}
Agrandar(val, tamano);
Plugin.AjustarColoresPublico(val);
return Preparar(val, indice, nombre, valor, peso);
}
private static void CrearGema(GameObject modelo, int indice, string nombre, int valor, Color color, ManualLogSource log)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Object.Instantiate<GameObject>(modelo, almacen.transform);
((Object)val).name = nombre;
Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val2 in componentsInChildren)
{
Material[] sharedMaterials = val2.sharedMaterials;
for (int j = 0; j < sharedMaterials.Length; j++)
{
if (!((Object)(object)sharedMaterials[j] == (Object)null))
{
Material val3 = new Material(sharedMaterials[j]);
float num = (val3.HasProperty("_Color") ? val3.color.a : 1f);
val3.color = new Color(color.r, color.g, color.b, num);
if (val3.HasProperty("_Metallic"))
{
val3.SetFloat("_Metallic", 0f);
}
sharedMaterials[j] = val3;
}
}
val2.sharedMaterials = sharedMaterials;
}
Tipo tipo = Preparar(val, indice, nombre, valor, 0.05f);
GirarEnHueco(tipo, -25f);
Lupa(tipo, 1f);
Gemas.Add(tipo);
}
private static Tipo Preparar(GameObject p, int indice, string nombre, int valor, float peso)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
TesoroItem tesoroItem = p.AddComponent<TesoroItem>();
((PickupableItem)tesoroItem).holdDistance = 0.45f;
((PickupableItem)tesoroItem).holdHeight = -0.15f;
((PickupableItem)tesoroItem).furniturePlaceHeight = 0f;
((ShipItem)tesoroItem).mass = peso;
((ShipItem)tesoroItem).value = valor;
((ShipItem)tesoroItem).name = nombre;
((ShipItem)tesoroItem).category = (TransactionCategory)3;
((ShipItem)tesoroItem).inventoryScale = 1f;
p.AddComponent<SaveablePrefab>().prefabIndex = indice;
Tipo tipo = new Tipo
{
Indice = indice,
Nombre = nombre,
Valor = valor,
Peso = peso,
Prefab = p
};
Lista.Add(tipo);
return tipo;
}
private static void Agrandar(GameObject p, float f)
{
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
if (Mathf.Approximately(f, 1f))
{
return;
}
MeshFilter[] componentsInChildren = p.GetComponentsInChildren<MeshFilter>(true);
foreach (MeshFilter val in componentsInChildren)
{
if (!((Object)(object)val.sharedMesh == (Object)null))
{
if (!val.sharedMesh.isReadable)
{
Debug.LogWarning((object)("VDM Treasure Hunt: el modelo '" + ((Object)p).name + "' no tiene Read/Write en Unity: no se puede agrandar"));
return;
}
Mesh val2 = Object.Instantiate<Mesh>(val.sharedMesh);
Vector3[] vertices = val2.vertices;
for (int j = 0; j < vertices.Length; j++)
{
ref Vector3 reference = ref vertices[j];
reference *= f;
}
val2.vertices = vertices;
val2.RecalculateBounds();
val.sharedMesh = val2;
}
}
BoxCollider[] componentsInChildren2 = p.GetComponentsInChildren<BoxCollider>(true);
foreach (BoxCollider obj in componentsInChildren2)
{
obj.size *= f;
obj.center *= f;
}
SphereCollider[] componentsInChildren3 = p.GetComponentsInChildren<SphereCollider>(true);
foreach (SphereCollider obj2 in componentsInChildren3)
{
obj2.radius *= f;
obj2.center *= f;
}
MeshCollider[] componentsInChildren4 = p.GetComponentsInChildren<MeshCollider>(true);
foreach (MeshCollider val3 in componentsInChildren4)
{
MeshFilter component = ((Component)val3).GetComponent<MeshFilter>();
if ((Object)(object)component != (Object)null)
{
val3.sharedMesh = component.sharedMesh;
}
}
}
private static void Lupa(Tipo t, float veces)
{
if (t != null)
{
TesoroItem component = t.Prefab.GetComponent<TesoroItem>();
if ((Object)(object)component != (Object)null)
{
component.LupaHueco = veces;
}
}
}
private static void GirarEnHueco(Tipo t, float grados)
{
if (t != null)
{
ShipItem component = t.Prefab.GetComponent<ShipItem>();
if ((Object)(object)component != (Object)null)
{
component.inventoryRotationX = grados;
}
}
}
public static void Registrar(PrefabsDirectory dir)
{
int num = 0;
foreach (Tipo listum in Lista)
{
num = Mathf.Max(num, listum.Indice);
}
if (dir.directory.Length <= num)
{
GameObject[] array = (GameObject[])(object)new GameObject[num + 1];
dir.directory.CopyTo(array, 0);
dir.directory = array;
}
foreach (Tipo listum2 in Lista)
{
if ((Object)(object)dir.directory[listum2.Indice] != (Object)null && (Object)(object)dir.directory[listum2.Indice] != (Object)(object)listum2.Prefab)
{
Debug.LogError((object)("VDM Treasure Hunt: la posicion " + listum2.Indice + " ya esta ocupada por otro objeto"));
}
else
{
dir.directory[listum2.Indice] = listum2.Prefab;
}
}
}
public static List<int> BotinAlAzar()
{
List<int> list = new List<int>();
int num = Random.Range(2, 4);
for (int i = 0; i < num; i++)
{
if (Doblon == null)
{
break;
}
list.Add(Doblon.Indice);
}
if (Lingote != null)
{
list.Add(Lingote.Indice);
}
if (Cruz != null && Random.value < 0.05f)
{
list.Add(Cruz.Indice);
}
if (Caliz != null && Random.value < 0.05f)
{
list.Add(Caliz.Indice);
}
if (Diamante != null && Random.value < 0.5f)
{
list.Add(Diamante.Indice);
}
int num2 = Random.Range(2, 4);
for (int j = 0; j < num2; j++)
{
if (Gemas.Count <= 0)
{
break;
}
list.Add(GemaAlAzar().Indice);
}
return list;
}
private static Tipo GemaAlAzar()
{
float num = 0f;
foreach (Tipo gema in Gemas)
{
num += PesoGema(gema);
}
float num2 = Random.value * num;
foreach (Tipo gema2 in Gemas)
{
num2 -= PesoGema(gema2);
if (num2 <= 0f)
{
return gema2;
}
}
return Gemas[Gemas.Count - 1];
}
private static float PesoGema(Tipo g)
{
return g.Nombre switch
{
"citrine" => 3f,
"topaz" => 3f,
"amethyst" => 2.5f,
"ruby" => 1.5f,
"sapphire" => 1.5f,
"emerald" => 1f,
_ => 1f,
};
}
public static int[] Recortar(int[] contenido, int huecos)
{
if (contenido.Length <= huecos)
{
return contenido;
}
int[] array = new int[huecos];
Array.Copy(contenido, array, huecos);
return array;
}
}
public static class Escondites
{
public class Sitio
{
public string Clave;
public string Isla;
public Vector3 Local;
public Sitio(string c, string i, float x, float y, float z)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
Clave = c;
Isla = i;
Local = new Vector3(x, y, z);
}
}
public static readonly List<Sitio> Lista = new List<Sitio>
{
new Sitio("aestra_abbey", "island 34 M monastery", 287.361f, 3.396f, 154.388f),
new Sitio("eastwind", "island 19 M (Eastwind)", 160.285f, 8.283f, 162.461f),
new Sitio("firefly_grotto", "island 33 M cave church", -589.949f, 9.225f, -1131.157f),
new Sitio("happy_bay", "island 18 M (HappyBay)", -52.229f, 1.146f, 84.178f),
new Sitio("dead_cove", "island 37 E (swamp)", -24.856f, 30.527f, -120.512f),
new Sitio("sage_hills", "island 13 E (Sage Hills)", 302.851f, 21.292f, 282.703f),
new Sitio("sanctuary", "island 10 E (sanctuary)", -100.626f, 3.916f, -53.563f),
new Sitio("serpent_isle", "island 22 E (Serpent Isle)", 543.033f, -852.326f, 3.464f),
new Sitio("turtle_island", "island 38 E (jungle)", 1.328f, 3.44f, -60.628f),
new Sitio("fire_fish", "island 26 Lagoon Temple", -63.277f, 2.741f, 187.954f),
new Sitio("kicia_bay", "island 26 lagoon parent terrain (-1)", 879.605f, 6.881f, -356.215f),
new Sitio("onna_isla_vacia", "island 26 lagoon parent terrain (-1)", 608.394f, 29.985f, -1835.041f),
new Sitio("perfil_faro", "island 20 A (Oasis)", 550.304f, 7.621f, -587.144f),
new Sitio("alnilem", "island 2 A (AlNilem)", 240.762f, 4.24f, -266.006f),
new Sitio("albacore_town", "island 4 A (fish island)", -101.875f, 10.357f, 148.909f),
new Sitio("alchemists_island", "island 7 A (alchemist's island)", 203.421f, 8.919f, -100.505f),
new Sitio("perfil_obelisco", "island 5 A (clear mind)", 33.847f, 2.185f, -206.654f)
};
private static readonly Dictionary<string, Transform> cache = new Dictionary<string, Transform>();
private static readonly Dictionary<string, float> proximaBusqueda = new Dictionary<string, float>();
public static Transform Isla(string nombre)
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
if (cache.TryGetValue(nombre, out var value) && (Object)(object)value != (Object)null)
{
return value;
}
if (proximaBusqueda.TryGetValue(nombre, out var value2) && Time.time < value2)
{
return null;
}
proximaBusqueda[nombre] = Time.time + 15f;
value = null;
Transform[] array = Resources.FindObjectsOfTypeAll<Transform>();
foreach (Transform val in array)
{
if (((Object)val).name == nombre)
{
Scene scene = ((Component)val).gameObject.scene;
if (((Scene)(ref scene)).IsValid())
{
value = val;
break;
}
}
}
cache[nombre] = value;
return value;
}
public static Vector3? Posicion(Sitio s)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
Transform val = Isla(s.Isla);
if ((Object)(object)val == (Object)null)
{
return null;
}
return val.TransformPoint(s.Local);
}
public unsafe static void Siluetas(string carpeta, ManualLogSource log)
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: 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_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
Directory.CreateDirectory(carpeta);
if ((Object)(object)Camera.main == (Object)null)
{
return;
}
int num = 480;
int num2 = 0;
RaycastHit val3 = default(RaycastHit);
foreach (Sitio listum in Lista)
{
Vector3? val = Posicion(listum);
if (!val.HasValue)
{
continue;
}
Vector3 value = val.Value;
Transform val2 = Isla(listum.Isla);
if (Mathf.Abs(val2.position.y) > 3f)
{
continue;
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("P2\n").Append(num).Append(' ')
.Append(num)
.Append("\n255\n");
int num3 = 0;
for (int i = 0; i < num; i++)
{
float num4 = value.z + 1200f - (float)i * 5f;
for (int j = 0; j < num; j++)
{
float num5 = value.x - 1200f + (float)j * 5f;
int value2 = 0;
if (Physics.Raycast(new Vector3(num5, 400f, num4), Vector3.down, ref val3, 800f, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val3)).point.y > 0.3f)
{
value2 = Mathf.Clamp(60 + (int)(((RaycastHit)(ref val3)).point.y * 2f), 60, 255);
num3++;
}
stringBuilder.Append(value2).Append(' ');
}
stringBuilder.Append('\n');
}
File.WriteAllText(Path.Combine(carpeta, listum.Clave + "_cerca.pgm"), stringBuilder.ToString());
num2++;
string[] obj = new string[10]
{
"SILUETA: ",
listum.Clave,
" tierra=",
num3.ToString(),
" centro=",
null,
null,
null,
null,
null
};
Vector3 val4 = value;
obj[5] = ((object)(*(Vector3*)(&val4))/*cast due to .constrained prefix*/).ToString();
obj[6] = " giroIsla=";
obj[7] = ((object)val2.eulerAngles/*cast due to .constrained prefix*/).ToString();
obj[8] = " escalaIsla=";
obj[9] = ((object)val2.lossyScale/*cast due to .constrained prefix*/).ToString();
log.LogInfo((object)string.Concat(obj));
}
log.LogInfo((object)("SILUETA: fin (" + num2 + " escondites cerca)"));
string text = "";
foreach (Sitio listum2 in Lista)
{
if (Posicion(listum2).HasValue && Mathf.Abs(Isla(listum2.Isla).position.y) <= 3f)
{
text = text + "\n" + listum2.Clave;
}
}
NotificationUi instance = NotificationUi.instance;
if (instance != null)
{
instance.ShowNotification("siluetas: " + num2 + text);
}
}
}
public class MapaTesoro : MonoBehaviour
{
public static readonly HashSet<MapaTesoro> Todos = new HashSet<MapaTesoro>();
public int Sitio;
public const float MarcaEncontrado = 7777f;
public ShipItem Item => ((Component)this).GetComponent<ShipItem>();
public bool Encontrado
{
get
{
ShipItem item = Item;
if ((Object)(object)item != (Object)null)
{
return item.health >= 7776f;
}
return false;
}
}
private void Awake()
{
Todos.Add(this);
}
private void OnDestroy()
{
Todos.Remove(this);
}
}
public static class Mapas
{
public const int Base = 24720;
public const int MapaViejo = 139;
private static readonly Dictionary<int, Texture2D> texturas = new Dictionary<int, Texture2D>();
private static GameObject almacen;
private static bool registrado;
private static readonly List<MapaTesoro> activos = new List<MapaTesoro>();
private static int scrambled = -1;
public static void CargarTexturas(string carpeta, ManualLogSource log)
{
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
for (int i = 0; i < Escondites.Lista.Count; i++)
{
byte[] array = null;
string text = "TesoroMod.mapas." + Escondites.Lista[i].Clave + ".jpg";
using (Stream stream = typeof(Mapas).Assembly.GetManifestResourceStream(text))
{
if (stream != null)
{
array = new byte[stream.Length];
int num;
for (int j = 0; j < array.Length; j += num)
{
num = stream.Read(array, j, array.Length - j);
if (num <= 0)
{
break;
}
}
}
}
string path = Path.Combine(carpeta, Escondites.Lista[i].Clave + ".jpg");
if (array == null && File.Exists(path))
{
array = File.ReadAllBytes(path);
}
if (array == null)
{
log.LogWarning((object)("MAPAS: falta el dibujo " + text));
continue;
}
Texture2D val = new Texture2D(2, 2, (TextureFormat)3, true);
if (!ImageConversion.LoadImage(val, array))
{
log.LogWarning((object)("MAPAS: no se pudo leer " + text));
continue;
}
((Object)val).name = "mapa tesoro " + Escondites.Lista[i].Clave;
((Texture)val).wrapMode = (TextureWrapMode)1;
((Texture)val).anisoLevel = 4;
try
{
val.Compress(true);
val.Apply(false, true);
}
catch (Exception ex)
{
log.LogWarning((object)("MAPAS: no se pudo comprimir " + text + ": " + ex.Message));
}
texturas[i] = val;
}
log.LogInfo((object)("MAPAS: " + texturas.Count + " dibujos cargados"));
}
public static void Registrar(PrefabsDirectory dir, ManualLogSource log)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Expected O, but got Unknown
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
if (registrado || dir.directory.Length <= 139 || (Object)(object)dir.directory[139] == (Object)null)
{
return;
}
registrado = true;
int num = 24720 + Escondites.Lista.Count;
if (dir.directory.Length < num)
{
GameObject[] array = (GameObject[])(object)new GameObject[num];
dir.directory.CopyTo(array, 0);
dir.directory = array;
}
almacen = new GameObject("VDM Treasure Hunt mapas");
almacen.SetActive(false);
Object.DontDestroyOnLoad((Object)(object)almacen);
foreach (KeyValuePair<int, Texture2D> textura in texturas)
{
int num2 = 24720 + textura.Key;
if ((Object)(object)dir.directory[num2] != (Object)null)
{
log.LogError((object)("MAPAS: la posicion " + num2 + " ya esta ocupada"));
continue;
}
GameObject val = Object.Instantiate<GameObject>(dir.directory[139], almacen.transform);
((Object)val).name = "treasure map " + Escondites.Lista[textura.Key].Clave;
bool flag = false;
Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val2 in componentsInChildren)
{
if (!((Object)(object)((Component)val2).gameObject == (Object)(object)val) && !((Object)(object)val2.sharedMaterial == (Object)null) && !((Object)(object)val2.sharedMaterial.mainTexture == (Object)null))
{
Material val3 = new Material(val2.sharedMaterial);
val3.mainTexture = (Texture)(object)textura.Value;
if (val3.HasProperty("_Color"))
{
val3.color = Color.white;
}
val2.sharedMaterial = val3;
flag = true;
}
}
if (!flag)
{
log.LogWarning((object)("MAPAS: no encuentro donde pintar el dibujo en " + ((Object)val).name));
}
ShipItem component = val.GetComponent<ShipItem>();
component.name = "treasure map";
component.value = 60;
component.amount = 0f;
component.health = 0f;
SaveablePrefab component2 = val.GetComponent<SaveablePrefab>();
if ((Object)(object)component2 != (Object)null)
{
component2.prefabIndex = num2;
}
val.AddComponent<MapaTesoro>().Sitio = textura.Key;
dir.directory[num2] = val;
}
log.LogInfo((object)("MAPAS: " + texturas.Count + " mapas del tesoro registrados desde " + 24720));
}
public static List<MapaTesoro> Activos()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
activos.Clear();
foreach (MapaTesoro todo in MapaTesoro.Todos)
{
if ((Object)(object)todo == (Object)null)
{
continue;
}
Scene scene = ((Component)todo).gameObject.scene;
if (((Scene)(ref scene)).IsValid() && (!((Object)(object)almacen != (Object)null) || !((Component)todo).transform.IsChildOf(almacen.transform)))
{
ShipItem item = todo.Item;
if (!((Object)(object)item == (Object)null) && item.sold && !todo.Encontrado)
{
activos.Add(todo);
}
}
}
return activos;
}
public static bool ConScrambledSeas()
{
if (scrambled < 0)
{
scrambled = 0;
foreach (PluginInfo value in Chainloader.PluginInfos.Values)
{
if (value != null && value.Metadata != null && value.Metadata.Name != null && value.Metadata.Name.ToLower().Contains("scrambled"))
{
scrambled = 1;
break;
}
}
}
return scrambled == 1;
}
public static int ElegirSitio()
{
HashSet<int> hashSet = new HashSet<int>();
foreach (MapaTesoro item in Activos())
{
hashSet.Add(item.Sitio);
}
List<int> list = new List<int>();
bool flag = ConScrambledSeas();
foreach (int key in texturas.Keys)
{
if (!hashSet.Contains(key) && (!flag || key >= Escondites.Lista.Count || !Escondites.Lista[key].Isla.ToLower().Contains("lagoon")))
{
list.Add(key);
}
}
if (list.Count != 0)
{
return list[Random.Range(0, list.Count)];
}
return -1;
}
}