using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.Mono;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("WildAlbatross")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WildAlbatross")]
[assembly: AssemblyTitle("WildAlbatross")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace WildAlbatross
{
[BepInPlugin("com.howtofish.wildalbatross", "Wild Albatross", "1.0.0")]
public sealed class Plugin : BaseUnityPlugin
{
private sealed class DropTrack
{
public Component Albatross;
public Object MeatPrefab;
public Vector3 LastPosition;
public bool Spawned;
public bool SeenAlive;
}
public const string Guid = "com.howtofish.wildalbatross";
public const string Name = "Wild Albatross";
public const string Version = "1.0.0";
internal static ManualLogSource Log;
internal static bool BlockBossUi;
internal static bool PendingWildSpawn;
internal static Vector3 PendingWildPosition;
internal static float PendingWildUntil;
private static readonly HashSet<int> WildInstanceIds = new HashSet<int>();
private Harmony _harmony;
private ConfigEntry<bool> _enabled;
private ConfigEntry<string> _excludedScenes;
private ConfigEntry<float> _spawnMin;
private ConfigEntry<float> _spawnMax;
private ConfigEntry<int> _hp;
private ConfigEntry<int> _meleeDamage;
private ConfigEntry<int> _poopDamage;
private ConfigEntry<int> _meatCount;
private ConfigEntry<int> _meatWorth;
private ConfigEntry<float> _spawnHeight;
private string _sceneName;
private float _nextSpawn = -1f;
private float _graceUntil;
private GameObject _spawnerGo;
private Component _spawner;
private Component _current;
private bool _wasAlive;
private bool _currentWildConfirmedAlive;
private readonly List<DropTrack> _drops = new List<DropTrack>();
private float _nextDropCheck;
private void Awake()
{
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Expected O, but got Unknown
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Expected O, but got Unknown
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Activa el Wild Albatross.");
_excludedScenes = ((BaseUnityPlugin)this).Config.Bind<string>("Spawn", "ExcludedScenes", "Island1", "Escenas separadas por coma donde NO debe aparecer.");
_spawnMin = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "MinSpawnInterval", 30f, "Tiempo mínimo entre Wild Albatross.");
_spawnMax = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "MaxSpawnInterval", 60f, "Tiempo máximo entre Wild Albatross.");
_spawnHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "SpawnHeightAbovePlayer", 28f, "Altura de spawn sobre el jugador.");
_hp = ((BaseUnityPlugin)this).Config.Bind<int>("Stats", "Health", 120, "Vida máxima.");
_meleeDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Stats", "MeleeDamage", 8, "Daño del ataque físico.");
_poopDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Stats", "ProjectileDamage", 5, "Daño del proyectil.");
_meatCount = ((BaseUnityPlugin)this).Config.Bind<int>("Drops", "MeatDropCount", 1, "Número de trozos de carne al morir. 0 desactiva el drop.");
_meatWorth = ((BaseUnityPlugin)this).Config.Bind<int>("Drops", "MeatValue", 40, "Valor de CADA trozo de carne.");
_harmony = new Harmony("com.howtofish.wildalbatross");
PatchWildAlbatrossBirth();
PatchBossRegistration();
PatchBossUi();
SceneManager.sceneUnloaded += OnSceneUnloaded;
ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Wild Albatross");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" cargado.");
}
logger.LogInfo(val);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Wild Albatross public release 1.0.0.");
ManualLogSource logger2 = ((BaseUnityPlugin)this).Logger;
val = new BepInExInfoLogInterpolatedStringHandler(30, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Spawn=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(_spawnMin.Value, "0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("-");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(_spawnMax.Value, "0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s, HP=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_hp.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("meat=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_meatCount.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" x worth ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_meatWorth.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
logger2.LogInfo(val);
}
private void OnDestroy()
{
SceneManager.sceneUnloaded -= OnSceneUnloaded;
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
CleanupSpawner();
BlockBossUi = false;
PendingWildSpawn = false;
WildInstanceIds.Clear();
}
private void Update()
{
if (_enabled.Value)
{
UpdateSpawner();
UpdateDrops();
}
}
private void UpdateSpawner()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Expected O, but got Unknown
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Expected O, but got Unknown
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
Scene gameplayIslandScene = GetGameplayIslandScene();
string text = ((((Scene)(ref gameplayIslandScene)).IsValid() && ((Scene)(ref gameplayIslandScene)).isLoaded) ? ((Scene)(ref gameplayIslandScene)).name : null);
bool flag = ((Scene)(ref gameplayIslandScene)).IsValid() && ((Scene)(ref gameplayIslandScene)).isLoaded && !IsExcluded(text);
bool flag2 = default(bool);
if (!string.Equals(_sceneName, text, StringComparison.OrdinalIgnoreCase))
{
CleanupSpawner();
_drops.Clear();
_sceneName = text;
_wasAlive = false;
_currentWildConfirmedAlive = false;
BlockBossUi = false;
_nextSpawn = (flag ? (Time.unscaledTime + RandomDelay()) : (-1f));
if (flag)
{
ManualLogSource log = Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(43, 2, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[SPAWN] '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': siguiente Wild Albatross en ~");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(_nextSpawn - Time.unscaledTime, "0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s.");
}
log.LogInfo(val);
}
}
if (!flag)
{
return;
}
if ((Object)(object)_current == (Object)null)
{
_current = GetSpawnedAlbatross(_spawner);
}
bool flag3 = (Object)(object)_current != (Object)null && (Object)(object)_current.gameObject != (Object)null;
bool flag4 = flag3 && _current.gameObject.activeInHierarchy;
bool flag5 = flag3 && ReadBool(_current, "_localIsDead") == true;
if (flag4 && !flag5)
{
_currentWildConfirmedAlive = true;
_wasAlive = true;
}
else if (_currentWildConfirmedAlive && (!flag3 || !flag4 || flag5))
{
_wasAlive = false;
_currentWildConfirmedAlive = false;
BlockBossUi = false;
CleanupSpawner();
_nextSpawn = Time.unscaledTime + RandomDelay();
ManualLogSource log2 = Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(67, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[SPAWN] Wild Albatross realmente muerto/eliminado. ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Siguiente en ~");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(_nextSpawn - Time.unscaledTime, "0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s.");
}
log2.LogInfo(val);
}
else
{
if (_nextSpawn < 0f)
{
_nextSpawn = Time.unscaledTime + RandomDelay();
}
if (Time.unscaledTime >= _nextSpawn && (Object)(object)_spawner == (Object)null)
{
SpawnWildAlbatross(gameplayIslandScene);
_nextSpawn = Time.unscaledTime + 15f;
}
}
}
private float RandomDelay()
{
float num = Mathf.Max(1f, _spawnMin.Value);
float num2 = Mathf.Max(num, _spawnMax.Value);
return Random.Range(num, num2);
}
private bool IsExcluded(string sceneName)
{
if (string.IsNullOrWhiteSpace(sceneName))
{
return true;
}
return (from x in _excludedScenes.Value.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
select x.Trim()).Any((string x) => string.Equals(x, sceneName, StringComparison.OrdinalIgnoreCase));
}
private Scene GetGameplayIslandScene()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < SceneManager.sceneCount; i++)
{
Scene sceneAt = SceneManager.GetSceneAt(i);
if (((Scene)(ref sceneAt)).IsValid() && ((Scene)(ref sceneAt)).isLoaded)
{
string text = ((Scene)(ref sceneAt)).name ?? "";
if (text.StartsWith("Island", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "DevIsland", StringComparison.OrdinalIgnoreCase) || text.StartsWith("HTFE_Island", StringComparison.OrdinalIgnoreCase))
{
return sceneAt;
}
}
}
return default(Scene);
}
private void SpawnWildAlbatross(Scene scene)
{
//IL_0041: 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_006b: Expected O, but got Unknown
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Expected O, but got Unknown
//IL_00c5: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: 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_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Expected O, but got Unknown
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
Type type = AccessTools.TypeByName("ItemSpawner");
Type type2 = AccessTools.TypeByName("Albatross");
if (type == null || type2 == null)
{
Log.LogWarning((object)"[SPAWN] ItemSpawner/Albatross no encontrado.");
return;
}
Object val = FindAlbatrossPrefab(type2);
Transform val2 = FindPlayerWorldTransform(scene);
bool flag = default(bool);
if (val == (Object)null || (Object)(object)val2 == (Object)null)
{
ManualLogSource log = Log;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(25, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[SPAWN] prefab=");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(val != (Object)null);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", player=");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>((Object)(object)val2 != (Object)null);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(".");
}
log.LogWarning(val3);
return;
}
GameObject val4 = new GameObject("WildAlbatross_Spawner");
SceneManager.MoveGameObjectToScene(val4, scene);
val4.transform.position = val2.position + Vector3.up * _spawnHeight.Value;
val4.SetActive(false);
BoxCollider val5 = val4.AddComponent<BoxCollider>();
((Collider)val5).isTrigger = true;
val5.size = new Vector3(36f, 10f, 36f);
Component val6 = val4.AddComponent(type);
SetField(val6, "_isActive", true);
SetField(val6, "_itemToSpawn", val);
SetField(val6, "_spawnsDeadCreature", false);
SetField(val6, "_useRandomRotation", true);
SetField(val6, "_maxItemsSpawned", 1);
SetField(val6, "_spawnInstant", true);
SetField(val6, "_onlySpawnOnce", true);
SetField(val6, "_spawnInAir", true);
SetField(val6, "_spawnDelay", 9999f);
SetField(val6, "_spawnCount", 1);
SetField(val6, "_spawnBox", val5);
SetField(val6, "_hasSpawned", false);
ResetSpawnerList(val6);
_spawnerGo = val4;
_spawner = val6;
_current = null;
_currentWildConfirmedAlive = false;
_graceUntil = Time.unscaledTime + 3f;
PendingWildSpawn = true;
PendingWildPosition = val4.transform.position;
PendingWildUntil = Time.unscaledTime + 3f;
val4.SetActive(true);
((MonoBehaviour)this).StartCoroutine(TuneSpawnedAfterDelay());
ManualLogSource log2 = Log;
BepInExInfoLogInterpolatedStringHandler val7 = new BepInExInfoLogInterpolatedStringHandler(31, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val7).AppendLiteral("[SPAWN] solicitado en '");
((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<string>(((Scene)(ref scene)).name);
((BepInExLogInterpolatedStringHandler)val7).AppendLiteral("', pos=");
((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<Vector3>(val4.transform.position);
((BepInExLogInterpolatedStringHandler)val7).AppendLiteral(".");
}
log2.LogInfo(val7);
}
private IEnumerator TuneSpawnedAfterDelay()
{
float until = Time.unscaledTime + 3f;
while (Time.unscaledTime < until)
{
Component spawnedAlbatross = GetSpawnedAlbatross(_spawner);
if ((Object)(object)spawnedAlbatross != (Object)null)
{
_current = spawnedAlbatross;
WildInstanceIds.Add(((Object)spawnedAlbatross).GetInstanceID());
PendingWildSpawn = false;
ConfigureWildAlbatross(spawnedAlbatross);
if (ReadBool(spawnedAlbatross, "_localIsDead") != true)
{
_currentWildConfirmedAlive = true;
}
yield break;
}
yield return (object)new WaitForSeconds(0.1f);
}
PendingWildSpawn = false;
Log.LogWarning((object)"[SPAWN] no pude localizar la instancia creada en 3s.");
}
private void ConfigureWildAlbatross(Component a)
{
//IL_00cd: 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)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02bb: Expected O, but got Unknown
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Expected O, but got Unknown
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_033f: Expected O, but got Unknown
int num = Mathf.Max(1, _hp.Value);
SetEnumField(a, "_bossType", "None");
SetField(a, "_maxHp", num);
SetField(a, "_bossHpMultiplier", 1f);
SetField(a, "_localHp", num);
SetField(a, "<Hp>k__BackingField", num);
TrySetProperty(a, "Hp", num);
SetSyncVarValue(a, "_hp", num);
SetField(a, "_meleeDamage", Mathf.Max(0, _meleeDamage.Value));
SetField(a, "_damageRange", 1.3f);
SetField(a, "_attackIntervalMinMax", (object)new Vector2(4f, 8f));
SetField(a, "_poopCount", 1);
SetField(a, "_poopRate", 0.55f);
SetField(a, "_poopTimerMinMax", (object)new Vector2(9f, 16f));
FieldInfo fieldInfo = FindField(((object)a).GetType(), "_poopInfo");
if (fieldInfo != null)
{
object? value = fieldInfo.GetValue(a);
Object val = (Object)((value is Object) ? value : null);
if (val != (Object)null)
{
Object val2 = Object.Instantiate(val);
val2.name = "WildAlbatross_PoopInfo";
SetField(val2, "<ProjectileDamage>k__BackingField", Mathf.Max(0, _poopDamage.Value));
SetField(val2, "_projectileDamage", Mathf.Max(0, _poopDamage.Value));
TrySetProperty(val2, "ProjectileDamage", Mathf.Max(0, _poopDamage.Value));
fieldInfo.SetValue(a, val2);
}
}
Object val3 = null;
FieldInfo fieldInfo2 = FindField(((object)a).GetType(), "_meat");
if (fieldInfo2 != null)
{
object? value2 = fieldInfo2.GetValue(a);
val3 = (Object)((value2 is Object) ? value2 : null);
}
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val4;
if (val3 != (Object)null && _meatCount.Value > 0)
{
RegisterDrop(a, val3);
ManualLogSource log = Log;
val4 = new BepInExInfoLogInterpolatedStringHandler(40, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[DROP] preparado: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(_meatCount.Value);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("x '");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(val3.name);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("', worth=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(_meatWorth.Value);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" cada uno.");
}
log.LogInfo(val4);
}
else
{
ManualLogSource log2 = Log;
val4 = new BepInExInfoLogInterpolatedStringHandler(59, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[DROP] desactivado o prefab no encontrado. count=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(_meatCount.Value);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", prefab=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<bool>(val3 != (Object)null);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(".");
}
log2.LogInfo(val4);
}
SetField(a, "_spawnOnDeath", null);
SetField(a, "_meat", null);
BlockBossUi = true;
HideBossUiOnce();
ManualLogSource log3 = Log;
val4 = new BepInExInfoLogInterpolatedStringHandler(48, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[WILD ALBATROSS] convertido: HP=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", melee=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(_meleeDamage.Value);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", poop=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(_poopDamage.Value);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(".");
}
log3.LogInfo(val4);
}
private void RegisterDrop(Component a, Object meat)
{
//IL_004b: 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)
_drops.RemoveAll((DropTrack x) => x == null || (Object)(object)x.Albatross == (Object)null);
_drops.Add(new DropTrack
{
Albatross = a,
MeatPrefab = meat,
LastPosition = a.transform.position,
Spawned = false,
SeenAlive = (ReadBool(a, "_localIsDead") != true)
});
}
private void UpdateDrops()
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
if (Time.unscaledTime < _nextDropCheck)
{
return;
}
_nextDropCheck = Time.unscaledTime + 0.1f;
for (int num = _drops.Count - 1; num >= 0; num--)
{
DropTrack dropTrack = _drops[num];
if (dropTrack == null || dropTrack.Spawned)
{
_drops.RemoveAt(num);
}
else
{
bool flag = false;
if ((Object)(object)dropTrack.Albatross != (Object)null && (Object)(object)dropTrack.Albatross.gameObject != (Object)null)
{
dropTrack.LastPosition = dropTrack.Albatross.transform.position;
bool valueOrDefault = ReadBool(dropTrack.Albatross, "_localIsDead") == true;
if (!valueOrDefault && dropTrack.Albatross.gameObject.activeInHierarchy)
{
dropTrack.SeenAlive = true;
}
flag = dropTrack.SeenAlive && valueOrDefault;
}
else
{
flag = dropTrack.SeenAlive;
}
if (flag)
{
dropTrack.Spawned = true;
SpawnMeatDrops(dropTrack.LastPosition, dropTrack.MeatPrefab);
_drops.RemoveAt(num);
}
}
}
}
private void SpawnMeatDrops(Vector3 position, Object meatPrefab)
{
//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_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
int num = Mathf.Max(0, _meatCount.Value);
if (num == 0 || meatPrefab == (Object)null)
{
return;
}
Scene gameplayIslandScene = GetGameplayIslandScene();
if (!((Scene)(ref gameplayIslandScene)).IsValid() || !((Scene)(ref gameplayIslandScene)).isLoaded)
{
Log.LogWarning((object)"[DROP] no hay escena de isla cargada.");
return;
}
for (int i = 0; i < num; i++)
{
((MonoBehaviour)this).StartCoroutine(SpawnOneMeat(gameplayIslandScene, position, meatPrefab, i, num));
}
}
private IEnumerator SpawnOneMeat(Scene scene, Vector3 position, Object meatPrefab, int index, int total)
{
//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)
//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)
Type type = AccessTools.TypeByName("ItemSpawner");
if (type == null)
{
yield break;
}
GameObject go = new GameObject($"WildAlbatross_Meat_{index + 1}");
SceneManager.MoveGameObjectToScene(go, scene);
float num = ((total <= 1) ? 0f : (MathF.PI * 2f * (float)index / (float)total));
Vector3 val = new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * ((total <= 1) ? 0f : 0.45f);
go.transform.position = position + Vector3.up * 0.75f + val;
go.SetActive(false);
BoxCollider val2 = go.AddComponent<BoxCollider>();
((Collider)val2).isTrigger = true;
val2.size = Vector3.one * 0.8f;
Component spawner = go.AddComponent(type);
SetField(spawner, "_isActive", true);
SetField(spawner, "_itemToSpawn", meatPrefab);
SetField(spawner, "_spawnsDeadCreature", false);
SetField(spawner, "_useRandomRotation", true);
SetField(spawner, "_maxItemsSpawned", 1);
SetField(spawner, "_spawnInstant", true);
SetField(spawner, "_onlySpawnOnce", true);
SetField(spawner, "_spawnInAir", true);
SetField(spawner, "_spawnDelay", 9999f);
SetField(spawner, "_spawnCount", 1);
SetField(spawner, "_spawnBox", val2);
SetField(spawner, "_hasSpawned", false);
ResetSpawnerList(spawner);
go.SetActive(true);
float timeout = Time.unscaledTime + 2f;
bool flag = default(bool);
while (Time.unscaledTime < timeout)
{
Object firstSpawnedObject = GetFirstSpawnedObject(spawner);
Component val3 = (Component)(object)((firstSpawnedObject is Component) ? firstSpawnedObject : null);
if ((Object)(object)val3 != (Object)null)
{
SetField(val3, "_worth", Mathf.Max(0, _meatWorth.Value));
ManualLogSource log = Log;
BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(30, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[DROP] carne ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(index + 1);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("/");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(total);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" creada, worth=");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(_meatWorth.Value);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(".");
}
log.LogInfo(val4);
break;
}
yield return (object)new WaitForSeconds(0.05f);
}
yield return (object)new WaitForSeconds(1f);
if ((Object)(object)go != (Object)null)
{
Object.Destroy((Object)(object)go);
}
}
private void PatchWildAlbatrossBirth()
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
try
{
Type type = AccessTools.TypeByName("Albatross");
MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Awake", (Type[])null, (Type[])null) : null);
if (methodInfo == null)
{
Log.LogWarning((object)"[PRE-AWAKE] Albatross.Awake no encontrado.");
return;
}
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "WildAlbatrossAwakePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.LogInfo((object)"[PRE-AWAKE] Albatross.Awake parcheado.");
}
catch (Exception ex)
{
ManualLogSource log = Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[PRE-AWAKE] No pude parchear Awake: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
}
private static void WildAlbatrossAwakePrefix(object __instance)
{
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
//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)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
bool flag = default(bool);
try
{
Component val = (Component)((__instance is Component) ? __instance : null);
if ((Object)(object)val == (Object)null || !PendingWildSpawn || Time.unscaledTime > PendingWildUntil)
{
return;
}
float num = Vector3.Distance(val.transform.position, PendingWildPosition);
if (!(num > 60f))
{
WildInstanceIds.Add(((Object)val).GetInstanceID());
SetEnumField(val, "_bossType", "None");
ManualLogSource log = Log;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(86, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[PRE-AWAKE] Wild Albatross reconocido ANTES de Awake: ");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val.gameObject).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("', distSpawner=");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(num, "0.0");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", bossType=None.");
}
log.LogInfo(val2);
}
}
catch (Exception ex)
{
ManualLogSource log2 = Log;
if (log2 != null)
{
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(26, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[PRE-AWAKE] Prefix error: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val3);
}
}
}
private void PatchBossRegistration()
{
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
try
{
Type type = AccessTools.TypeByName("BossManager");
if (type == null)
{
Log.LogWarning((object)"[BOSS REGISTER] BossManager no encontrado.");
return;
}
MethodInfo methodInfo = type.GetProperty("Boss", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetSetMethod(nonPublic: true);
if (methodInfo == null)
{
Log.LogWarning((object)"[BOSS REGISTER] BossManager.Boss setter no encontrado.");
return;
}
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "WildAlbatrossBossSetterPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.LogInfo((object)"[BOSS REGISTER] BossManager.Boss setter parcheado.");
}
catch (Exception ex)
{
ManualLogSource log = Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(23, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[BOSS REGISTER] Error: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
}
private static bool WildAlbatrossBossSetterPrefix(object __0)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
try
{
Component val = (Component)((__0 is Component) ? __0 : null);
if ((Object)(object)val == (Object)null)
{
return true;
}
int instanceID = ((Object)val).GetInstanceID();
if (!WildInstanceIds.Contains(instanceID))
{
return true;
}
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(53, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[BOSS REGISTER] Registro como Boss BLOQUEADO para '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val.gameObject).name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'.");
}
log.LogInfo(val2);
return false;
}
catch
{
return true;
}
}
private void PatchBossUi()
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.TypeByName("BossUI")?.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo x) => x.Name == "ToggleBossUI" && x.GetParameters().Length == 1 && x.GetParameters()[0].ParameterType == typeof(bool));
if (methodInfo == null)
{
Log.LogWarning((object)"[BOSS UI] ToggleBossUI(bool) no encontrado.");
}
else
{
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "BossUiPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private static bool BossUiPrefix(bool to)
{
return !(BlockBossUi && to);
}
private void HideBossUiOnce()
{
Type type = AccessTools.TypeByName("BossUI");
if (type == null)
{
return;
}
Object[] array = Resources.FindObjectsOfTypeAll(type);
foreach (Object obj in array)
{
Component val = (Component)(object)((obj is Component) ? obj : null);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.gameObject == (Object)null) && val.gameObject.activeInHierarchy)
{
MethodInfo methodInfo = AccessTools.Method(type, "ToggleBossUI", new Type[1] { typeof(bool) }, (Type[])null);
try
{
methodInfo?.Invoke(val, new object[1] { false });
}
catch
{
}
object? obj3 = FindField(type, "_bossCanvasLerped")?.GetValue(val);
CanvasGroup val2 = (CanvasGroup)((obj3 is CanvasGroup) ? obj3 : null);
if ((Object)(object)val2 != (Object)null)
{
val2.alpha = 0f;
val2.interactable = false;
val2.blocksRaycasts = false;
}
}
}
}
private Object FindAlbatrossPrefab(Type type)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
Object[] array = Resources.FindObjectsOfTypeAll(type);
foreach (Object obj in array)
{
Component val = (Component)(object)((obj is Component) ? obj : null);
if ((Object)(object)val == (Object)null || (Object)(object)val.gameObject == (Object)null)
{
continue;
}
Scene scene = val.gameObject.scene;
if (((Scene)(ref scene)).IsValid())
{
scene = val.gameObject.scene;
if (((Scene)(ref scene)).isLoaded)
{
continue;
}
}
if (((Object)val.gameObject).name.IndexOf("Albatross", StringComparison.OrdinalIgnoreCase) >= 0)
{
return (Object)(object)val;
}
}
return null;
}
private Transform FindPlayerWorldTransform(Scene island)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: 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_0136: 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_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Vector3.zero;
if (((Scene)(ref island)).IsValid())
{
Bounds val2 = default(Bounds);
bool flag = false;
GameObject[] rootGameObjects = ((Scene)(ref island)).GetRootGameObjects();
for (int i = 0; i < rootGameObjects.Length; i++)
{
Collider[] componentsInChildren = rootGameObjects[i].GetComponentsInChildren<Collider>(true);
foreach (Collider val3 in componentsInChildren)
{
if (!((Object)(object)val3 == (Object)null) && !val3.isTrigger)
{
if (!flag)
{
val2 = val3.bounds;
flag = true;
}
else
{
((Bounds)(ref val2)).Encapsulate(val3.bounds);
}
}
}
}
if (flag)
{
val = ((Bounds)(ref val2)).center;
}
}
Camera val4 = null;
float num = float.MaxValue;
Camera[] array = Resources.FindObjectsOfTypeAll<Camera>();
foreach (Camera val5 in array)
{
if ((Object)(object)val5 == (Object)null || (Object)(object)((Component)val5).gameObject == (Object)null)
{
continue;
}
Scene scene = ((Component)val5).gameObject.scene;
if (!((Scene)(ref scene)).IsValid() || !((Component)val5).gameObject.activeInHierarchy)
{
continue;
}
Vector3 position = ((Component)val5).transform.position;
if (!(Mathf.Abs(position.y - val.y) > 250f))
{
Vector2 val6 = new Vector2(position.x, position.z) - new Vector2(val.x, val.z);
float sqrMagnitude = ((Vector2)(ref val6)).sqrMagnitude;
if (sqrMagnitude < num)
{
num = sqrMagnitude;
val4 = val5;
}
}
}
if (!((Object)(object)val4 != (Object)null))
{
return null;
}
return ((Component)val4).transform;
}
private Component GetSpawnedAlbatross(Component spawner)
{
Object firstSpawnedObject = GetFirstSpawnedObject(spawner);
if (firstSpawnedObject == (Object)null)
{
return null;
}
Type type = AccessTools.TypeByName("Albatross");
Component val = (Component)(object)((firstSpawnedObject is Component) ? firstSpawnedObject : null);
if ((Object)(object)val != (Object)null)
{
return val.GetComponent(type);
}
GameObject val2 = (GameObject)(object)((firstSpawnedObject is GameObject) ? firstSpawnedObject : null);
if (!((Object)(object)val2 != (Object)null))
{
return null;
}
return val2.GetComponent(type);
}
private Object GetFirstSpawnedObject(Component spawner)
{
if ((Object)(object)spawner == (Object)null)
{
return null;
}
if (!(FindField(((object)spawner).GetType(), "_itemsSpawned")?.GetValue(spawner) is IEnumerable enumerable))
{
return null;
}
foreach (object item in enumerable)
{
Object val = (Object)((item is Object) ? item : null);
if (val != null)
{
return val;
}
}
return null;
}
private void ResetSpawnerList(Component spawner)
{
FieldInfo fieldInfo = FindField(((object)spawner).GetType(), "_itemsSpawned");
if (fieldInfo == null)
{
return;
}
try
{
fieldInfo.SetValue(spawner, Activator.CreateInstance(fieldInfo.FieldType));
}
catch
{
}
}
private void CleanupSpawner()
{
if ((Object)(object)_current != (Object)null)
{
try
{
WildInstanceIds.Remove(((Object)_current).GetInstanceID());
}
catch
{
}
}
_spawner = null;
_current = null;
_currentWildConfirmedAlive = false;
if ((Object)(object)_spawnerGo != (Object)null)
{
Object.Destroy((Object)(object)_spawnerGo);
}
_spawnerGo = null;
}
private void OnSceneUnloaded(Scene scene)
{
if (string.Equals(((Scene)(ref scene)).name, _sceneName, StringComparison.OrdinalIgnoreCase))
{
CleanupSpawner();
_drops.Clear();
_sceneName = null;
_nextSpawn = -1f;
_wasAlive = false;
BlockBossUi = false;
}
}
private static FieldInfo FindField(Type type, string name)
{
Type type2 = type;
while (type2 != null)
{
FieldInfo field = type2.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
return field;
}
type2 = type2.BaseType;
}
return null;
}
private static void SetField(object target, string name, object value)
{
if (target == null)
{
return;
}
FieldInfo fieldInfo = FindField(target.GetType(), name);
if (fieldInfo == null)
{
return;
}
try
{
object value2 = value;
if (value != null && !fieldInfo.FieldType.IsInstanceOfType(value))
{
value2 = Convert.ChangeType(value, fieldInfo.FieldType);
}
fieldInfo.SetValue(target, value2);
}
catch
{
}
}
private static int? ReadInt(object target, string name)
{
try
{
FieldInfo fieldInfo = FindField(target.GetType(), name);
return (fieldInfo != null && fieldInfo.FieldType == typeof(int)) ? ((int?)fieldInfo.GetValue(target)) : ((int?)null);
}
catch
{
return null;
}
}
private static bool? ReadBool(object target, string name)
{
try
{
FieldInfo fieldInfo = FindField(target.GetType(), name);
return (fieldInfo != null && fieldInfo.FieldType == typeof(bool)) ? ((bool?)fieldInfo.GetValue(target)) : ((bool?)null);
}
catch
{
return null;
}
}
private static void TrySetProperty(object target, string name, object value)
{
try
{
PropertyInfo property = target.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null && property.CanWrite)
{
property.SetValue(target, value, null);
}
}
catch
{
}
}
private static void SetEnumField(object target, string name, string enumName)
{
try
{
FieldInfo fieldInfo = FindField(target.GetType(), name);
if (fieldInfo != null && fieldInfo.FieldType.IsEnum)
{
fieldInfo.SetValue(target, Enum.Parse(fieldInfo.FieldType, enumName, ignoreCase: true));
}
}
catch
{
}
}
private static void SetSyncVarValue(object target, string fieldName, int value)
{
try
{
object obj = FindField(target.GetType(), fieldName)?.GetValue(target);
if (obj != null)
{
PropertyInfo property = obj.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null && property.CanWrite)
{
property.SetValue(obj, value, null);
}
}
}
catch
{
}
}
}
}