using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RoaringKnightMod;
[BepInPlugin("com.alvap.roaringknightadvanced", "Roaring Knight Avanzado", "4.0.0")]
public class Plugin : BaseUnityPlugin
{
private bool hasSpawned;
private float debugTimer;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"¡Cerebro Avanzado del Roaring Knight Inyectado!");
Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, (string)null);
}
private void Update()
{
//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_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
if (!((Object)(object)main != (Object)null))
{
return;
}
debugTimer += Time.deltaTime;
if (debugTimer > 5f)
{
ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
Vector3 position = ((Component)main).transform.position;
logger.LogInfo((object)("DEBUG - Coordenadas actuales de tu cámara: " + ((Vector3)(ref position)).ToString("F2")));
debugTimer = 0f;
}
Vector3 spawnPos = default(Vector3);
((Vector3)(ref spawnPos))..ctor(146.25f, 10.75f, 58.61f);
Vector3 spawnPos2 = default(Vector3);
((Vector3)(ref spawnPos2))..ctor(-0.24f, 33.01f, -21.99f);
if (!hasSpawned && ((Component)main).transform.position.y < 80f)
{
bool flag = false;
Type type = Type.GetType("DivingBell, Assembly-CSharp");
if (type != null)
{
Object val = Object.FindAnyObjectByType(type);
if (val != (Object)null)
{
FieldInfo field = type.GetField("opened", BindingFlags.Instance | BindingFlags.Public);
FieldInfo field2 = type.GetField("onSurface", BindingFlags.Instance | BindingFlags.Public);
FieldInfo field3 = type.GetField("m_isMovingDoor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
bool flag2 = field != null && (bool)field.GetValue(val);
bool flag3 = field2 != null && (bool)field2.GetValue(val);
bool flag4 = field3 != null && (bool)field3.GetValue(val);
((BaseUnityPlugin)this).Logger.LogInfo((object)("[BellDebug] opened=" + flag2 + " onSurface=" + flag3 + " m_isMovingDoor=" + flag4));
if ((flag2 || flag4) && !flag3)
{
flag = true;
}
}
}
if (flag)
{
hasSpawned = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Puerta de campana abierta bajo el agua. Spawneando Roaring Knight en ambas ubicaciones.");
CreateKnight(spawnPos);
CreateKnight(spawnPos2);
}
}
if (hasSpawned && ((Component)main).transform.position.y > 100f)
{
hasSpawned = false;
}
if (hasSpawned)
{
Type type2 = Type.GetType("DivingBell, Assembly-CSharp");
if (type2 != null)
{
Object val2 = Object.FindAnyObjectByType(type2);
if (val2 != (Object)null)
{
FieldInfo field4 = type2.GetField("onSurface", BindingFlags.Instance | BindingFlags.Public);
if (field4 != null && (bool)field4.GetValue(val2))
{
hasSpawned = false;
}
}
}
}
if (Input.GetKeyDown((KeyCode)286))
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Spawn forzado de prueba con F5");
SpawnKnight2D();
hasSpawned = true;
}
}
private void SpawnKnight2D()
{
//IL_0010: 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_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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_0045: 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_0066: 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)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
if (!((Object)(object)main == (Object)null))
{
Vector3 onUnitSphere = Random.onUnitSphere;
onUnitSphere.y = 0f;
Vector3 val = ((Component)main).transform.position + ((Vector3)(ref onUnitSphere)).normalized * 25f;
Vector3 spawnPos = val;
NavMeshHit val2 = default(NavMeshHit);
if (NavMesh.SamplePosition(val, ref val2, 30f, -1))
{
spawnPos = ((NavMeshHit)(ref val2)).position;
}
else if (NavMesh.SamplePosition(((Component)main).transform.position, ref val2, 15f, -1))
{
spawnPos = ((NavMeshHit)(ref val2)).position;
}
CreateKnight(spawnPos);
}
}
private void CreateKnight(Vector3 spawnPos)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0011: 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_0078: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("RoaringKnight2D");
val.transform.position = spawnPos;
SpriteRenderer val2 = val.AddComponent<SpriteRenderer>();
((Component)val2).transform.localScale = new Vector3(3f, 3f, 3f);
val.AddComponent<Billboard>();
val.AddComponent<RoaringKnightContentProvider>();
CapsuleCollider val3 = val.AddComponent<CapsuleCollider>();
val3.height = 6f;
val3.radius = 2f;
val3.center = new Vector3(0f, 3f, 0f);
RoaringKnightAI roaringKnightAI = val.AddComponent<RoaringKnightAI>();
roaringKnightAI.pluginPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
roaringKnightAI.spawnPosition = spawnPos;
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Concat("¡Roaring Knight IA Natural invocado con éxito en: ", spawnPos, "!"));
}
}
public class Billboard : MonoBehaviour
{
private void LateUpdate()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Camera main = Camera.main;
if ((Object)(object)main != (Object)null)
{
((Component)this).transform.forward = ((Component)main).transform.forward;
}
}
}
public class RoaringKnightContentProvider : ContentProvider
{
public override void GetContent(List<ContentEventFrame> list, float distance, Camera cam, float time)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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_0048: Unknown result type (might be due to invalid IL or missing references)
BombsContentEvent val = new BombsContentEvent();
((MonsterContentEvent)val).viewID = 9999;
((MonsterContentEvent)val).worldPosition = ((Component)this).transform.position;
list.Add(new ContentEventFrame
{
contentEvent = (ContentEvent)(object)val,
time = time,
seenAmount = 1f
});
}
}
[HarmonyPatch(typeof(BombsContentEvent))]
public class RoaringKnightEventPatch
{
[HarmonyPrefix]
[HarmonyPatch("GetContentValue")]
public static bool GetContentValuePrefix(BombsContentEvent __instance, ref float __result)
{
if (((MonsterContentEvent)__instance).viewID == 9999)
{
__result = 1200f;
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("GetName")]
public static bool GetNamePrefix(BombsContentEvent __instance, ref string __result)
{
if (((MonsterContentEvent)__instance).viewID == 9999)
{
__result = "Roaring Knight";
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("GetAllComments")]
public static bool GetAllCommentsPrefix(BombsContentEvent __instance, ref string[] __result)
{
if (((MonsterContentEvent)__instance).viewID == 9999)
{
__result = new string[6] { "El roaring knight?", "Que aura", "QUE ES ESA COSA GIGANTE", "¿Alguien más ha visto cómo levitaba?", "Corre por tu vida bro", "bro is floating \ud83d\udc80" };
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("GenerateComment")]
public static bool GenerateCommentPrefix(BombsContentEvent __instance, ref Comment __result)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
if (((MonsterContentEvent)__instance).viewID == 9999)
{
string[] array = new string[6] { "El roaring knight?", "Que aura", "QUE ES ESA COSA GIGANTE", "¿Alguien más ha visto cómo levitaba?", "Corre por tu vida bro", "bro is floating \ud83d\udc80" };
string text = array[Random.Range(0, array.Length)];
__result = new Comment(text);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(CommentUI))]
public class CommentUIPatch
{
[HarmonyPrefix]
[HarmonyPatch("GetLocalizedText")]
public static bool GetLocalizedTextPrefix(Comment comment, ref string __result)
{
if (comment.Text != null && (comment.Text.Contains("roaring knight") || comment.Text.Contains("Que aura") || comment.Text.Contains("QUE ES ESA COSA GIGANTE") || comment.Text.Contains("¿Alguien más ha visto cómo levitaba?") || comment.Text.Contains("Corre por tu vida bro") || comment.Text.Contains("bro is floating")))
{
__result = comment.Text;
return false;
}
return true;
}
}
public class RoaringKnightAI : MonoBehaviour
{
private enum State
{
Farming_Aura,
Idle,
Flee,
Chase,
Taunt,
Kidnap_Charge,
Kidnap_Carry
}
public string pluginPath;
public Vector3 spawnPosition;
private SpriteRenderer spriteRenderer;
private Sprite[] idleFrames;
private Sprite[] walkFrames;
private Sprite[] tauntFrames;
private Sprite[] auraFarmFrames;
private AudioSource audioSource;
private static AudioClip clipProvocacion;
private static AudioClip clipSecuestroCarga;
private static AudioClip clipSecuestroMusica;
private static AudioClip clipAuraFarm;
private static bool loadingAudio = false;
private int currentFrameIndex;
private float frameTimer;
public float fps = 15f;
private State currentState;
private NavMeshAgent agent;
private Transform target;
private Transform playerRoot;
private float tauntTimer;
private float carryTimer;
private GameObject kidnapDestinationEnemy;
private FixedJoint kidnappingJoint;
private List<Collider> disabledColliders = new List<Collider>();
private MethodInfo fnMoveRigs;
private MethodInfo fnAddForce;
private MethodInfo fnTeleport;
private FieldInfo fnRagdollField;
private MonoBehaviour playerLocalMono;
private bool reflectionDone;
private void Start()
{
spriteRenderer = ((Component)this).GetComponent<SpriteRenderer>();
idleFrames = LoadSprites("Knight_battle_idle");
walkFrames = LoadSprites("Knight_flying(walking)");
tauntFrames = LoadSprites("Knight_taunt", 109.58904f);
auraFarmFrames = LoadSprites("Knight_aurafarm", 191.78082f);
agent = ((Component)this).gameObject.AddComponent<NavMeshAgent>();
agent.speed = 8f;
agent.stoppingDistance = 2f;
agent.updateRotation = false;
agent.acceleration = 12f;
agent.autoBraking = false;
((Behaviour)agent).enabled = false;
audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
audioSource.spatialBlend = 1f;
audioSource.minDistance = 3f;
audioSource.maxDistance = 20f;
audioSource.rolloffMode = (AudioRolloffMode)1;
if ((Object)(object)clipProvocacion == (Object)null && !loadingAudio)
{
loadingAudio = true;
((MonoBehaviour)this).StartCoroutine(LoadAudioClips());
}
target = ((Component)Camera.main).transform;
playerRoot = target.root;
SetupPlayerReflection();
}
private Sprite[] LoadSprites(string folderName, float pixelsPerUnit = 100f)
{
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
//IL_0122: 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)
string path = Path.Combine(pluginPath, folderName);
if (!Directory.Exists(path))
{
return (Sprite[])(object)new Sprite[0];
}
string[] array = (from f in Directory.GetFiles(path, "*.*")
where f.EndsWith(".png") || f.EndsWith(".jpg")
orderby f
select f).ToArray();
List<Sprite> list = new List<Sprite>();
string[] array2 = array;
foreach (string path2 in array2)
{
byte[] array3 = File.ReadAllBytes(path2);
Texture2D val = new Texture2D(2, 2);
MethodInfo method = typeof(ImageConversion).GetMethod("LoadImage", new Type[2]
{
typeof(Texture2D),
typeof(byte[])
});
if (method != null)
{
method.Invoke(null, new object[2] { val, array3 });
}
((Texture)val).filterMode = (FilterMode)0;
Sprite item = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0f), pixelsPerUnit);
list.Add(item);
}
return list.ToArray();
}
private IEnumerator LoadAudioClips()
{
string pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string basePath = Path.Combine(pluginPath, "Sounds");
yield return ((MonoBehaviour)this).StartCoroutine(LoadClip(Path.Combine(basePath, "provocacion.wav"), (AudioType)20, delegate(AudioClip clip)
{
clipProvocacion = clip;
}));
yield return ((MonoBehaviour)this).StartCoroutine(LoadClip(Path.Combine(basePath, "secuestro.wav"), (AudioType)20, delegate(AudioClip clip)
{
clipSecuestroCarga = clip;
}));
yield return ((MonoBehaviour)this).StartCoroutine(LoadClip(Path.Combine(basePath, "Musica_mientras estas_siendo_secuestrado.mp3"), (AudioType)13, delegate(AudioClip clip)
{
clipSecuestroMusica = clip;
}));
yield return ((MonoBehaviour)this).StartCoroutine(LoadClip(Path.Combine(basePath, "AuraFarm.mp3"), (AudioType)13, delegate(AudioClip clip)
{
clipAuraFarm = clip;
}));
Debug.Log((object)"¡Audios del Roaring Knight cargados!");
}
private IEnumerator LoadClip(string path, AudioType type, Action<AudioClip> onLoaded)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (!File.Exists(path))
{
Debug.LogWarning((object)("Audio no encontrado en: " + path));
yield break;
}
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file:///" + path, type);
try
{
yield return www.SendWebRequest();
if ((int)www.result == 2 || (int)www.result == 3)
{
Debug.LogError((object)("Error cargando audio: " + www.error));
}
else
{
onLoaded(DownloadHandlerAudioClip.GetContent(www));
}
}
finally
{
((IDisposable)www)?.Dispose();
}
}
private void LateUpdate()
{
//IL_0015: 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_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: 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_0082: Unknown result type (might be due to invalid IL or missing references)
//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_0095: 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)
//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
//IL_04de: Unknown result type (might be due to invalid IL or missing references)
//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0240: Unknown result type (might be due to invalid IL or missing references)
//IL_075e: Unknown result type (might be due to invalid IL or missing references)
//IL_0533: Unknown result type (might be due to invalid IL or missing references)
//IL_053e: Unknown result type (might be due to invalid IL or missing references)
//IL_0549: Unknown result type (might be due to invalid IL or missing references)
//IL_054e: Unknown result type (might be due to invalid IL or missing references)
//IL_0553: Unknown result type (might be due to invalid IL or missing references)
//IL_0557: Unknown result type (might be due to invalid IL or missing references)
//IL_0561: Unknown result type (might be due to invalid IL or missing references)
//IL_0566: Unknown result type (might be due to invalid IL or missing references)
//IL_056b: Unknown result type (might be due to invalid IL or missing references)
//IL_0573: Unknown result type (might be due to invalid IL or missing references)
//IL_0442: Unknown result type (might be due to invalid IL or missing references)
//IL_044d: Unknown result type (might be due to invalid IL or missing references)
//IL_0452: Unknown result type (might be due to invalid IL or missing references)
//IL_0457: Unknown result type (might be due to invalid IL or missing references)
//IL_045b: Unknown result type (might be due to invalid IL or missing references)
//IL_0460: Unknown result type (might be due to invalid IL or missing references)
//IL_0468: Unknown result type (might be due to invalid IL or missing references)
//IL_046d: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0303: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Unknown result type (might be due to invalid IL or missing references)
//IL_0327: Unknown result type (might be due to invalid IL or missing references)
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_037b: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)target == (Object)null)
{
return;
}
float num = Vector3.Distance(((Component)this).transform.position, target.position);
if (currentState == State.Kidnap_Charge)
{
if ((Object)(object)agent != (Object)null && ((Behaviour)agent).enabled)
{
((Behaviour)agent).enabled = false;
}
Vector3 val = target.position - ((Component)this).transform.position;
Vector3 normalized = ((Vector3)(ref val)).normalized;
Transform transform = ((Component)this).transform;
transform.position += normalized * 12f * Time.deltaTime;
if (num < 2.5f)
{
currentState = State.Kidnap_Carry;
carryTimer = 0f;
FindKidnapDestination();
Rigidbody playerHipRigidbody = GetPlayerHipRigidbody();
if ((Object)(object)playerHipRigidbody != (Object)null)
{
if ((Object)(object)agent != (Object)null)
{
((Behaviour)agent).enabled = false;
}
Rigidbody val2 = ((Component)this).gameObject.GetComponent<Rigidbody>();
if ((Object)(object)val2 == (Object)null)
{
val2 = ((Component)this).gameObject.AddComponent<Rigidbody>();
}
val2.isKinematic = true;
val2.useGravity = false;
kidnappingJoint = ((Component)playerHipRigidbody).gameObject.AddComponent<FixedJoint>();
((Joint)kidnappingJoint).connectedBody = val2;
((Joint)kidnappingJoint).autoConfigureConnectedAnchor = false;
((Joint)kidnappingJoint).connectedAnchor = new Vector3(0f, 2f, 0f);
((Joint)kidnappingJoint).breakForce = float.PositiveInfinity;
((Joint)kidnappingJoint).breakTorque = float.PositiveInfinity;
disabledColliders.Clear();
Collider[] array = (Collider[])(((Object)(object)playerLocalMono != (Object)null) ? ((Array)((Component)playerLocalMono).GetComponentsInChildren<Collider>(true)) : ((Array)new Collider[0]));
Collider[] array2 = array;
foreach (Collider val3 in array2)
{
if (val3.enabled && !val3.isTrigger)
{
val3.enabled = false;
disabledColliders.Add(val3);
}
}
}
}
}
else if (currentState == State.Kidnap_Carry)
{
carryTimer += Time.deltaTime;
if (carryTimer > 24f)
{
TerminarSecuestroFisico(playerRoot.position);
return;
}
Vector3 val4;
if ((Object)(object)kidnapDestinationEnemy != (Object)null)
{
val4 = kidnapDestinationEnemy.transform.position + Vector3.up * 1.5f;
}
else
{
val4 = ((Component)this).transform.position + ((Component)this).transform.forward * 5f + Vector3.up * 2f;
tauntTimer += Time.deltaTime;
if (tauntTimer > 3f)
{
TerminarSecuestroFisico(playerRoot.position);
return;
}
}
Vector3 val5 = val4 - ((Component)this).transform.position;
Vector3 normalized2 = ((Vector3)(ref val5)).normalized;
Transform transform2 = ((Component)this).transform;
transform2.position += normalized2 * 8f * Time.deltaTime;
if ((Object)(object)kidnapDestinationEnemy != (Object)null)
{
float num2 = Vector3.Distance(((Component)this).transform.position, kidnapDestinationEnemy.transform.position);
if (num2 < 3f)
{
TerminarSecuestroFisico(kidnapDestinationEnemy.transform.position + Vector3.up);
return;
}
}
if ((Object)(object)clipSecuestroMusica != (Object)null && (Object)(object)audioSource.clip != (Object)(object)clipSecuestroMusica)
{
audioSource.clip = clipSecuestroMusica;
audioSource.loop = true;
audioSource.Play();
}
}
else if (currentState == State.Farming_Aura)
{
if ((Object)(object)clipAuraFarm != (Object)null && (Object)(object)audioSource.clip != (Object)(object)clipAuraFarm)
{
audioSource.clip = clipAuraFarm;
audioSource.loop = true;
audioSource.Play();
}
Vector3 val6 = ((Component)this).transform.position - target.position;
Vector3 normalized3 = ((Vector3)(ref val6)).normalized;
float num3 = Vector3.Dot(target.forward, normalized3);
if (num3 > 0.6f)
{
tauntTimer += Time.deltaTime;
if (tauntTimer >= 7f)
{
tauntTimer = 0f;
WakeUpFromAura();
}
}
else
{
tauntTimer = 0f;
}
}
else
{
Vector3 val7 = ((Component)this).transform.position - target.position;
Vector3 normalized4 = ((Vector3)(ref val7)).normalized;
float num4 = Vector3.Dot(target.forward, normalized4);
bool flag = num4 > 0.8f;
if (num < 10f)
{
currentState = State.Flee;
agent.isStopped = false;
Vector3 position = ((Component)this).transform.position;
Vector3 val8 = ((Component)this).transform.position - target.position;
Vector3 destination = position + ((Vector3)(ref val8)).normalized * 5f;
agent.SetDestination(destination);
tauntTimer = 0f;
}
else if (num > 15f)
{
currentState = State.Chase;
agent.isStopped = false;
agent.SetDestination(target.position);
tauntTimer = 0f;
}
else
{
agent.isStopped = true;
if (flag)
{
tauntTimer += Time.deltaTime;
if (tauntTimer > 1.5f)
{
currentState = State.Taunt;
if (tauntTimer > 3.5f)
{
currentState = State.Kidnap_Charge;
agent.speed = 35f;
agent.acceleration = 100f;
if ((Object)(object)clipSecuestroCarga != (Object)null)
{
audioSource.Stop();
audioSource.clip = clipSecuestroCarga;
audioSource.loop = false;
audioSource.Play();
}
}
else if (tauntTimer > 0f && !audioSource.isPlaying && (Object)(object)clipProvocacion != (Object)null)
{
audioSource.clip = clipProvocacion;
audioSource.loop = true;
audioSource.Play();
}
}
else
{
currentState = State.Idle;
if ((Object)(object)audioSource.clip == (Object)(object)clipProvocacion)
{
audioSource.Stop();
}
}
}
else
{
tauntTimer = 0f;
currentState = State.Idle;
if ((Object)(object)audioSource.clip == (Object)(object)clipProvocacion)
{
audioSource.Stop();
}
}
}
}
Sprite[] array3 = idleFrames;
((Component)spriteRenderer).transform.localScale = new Vector3(3f, 3f, 3f);
if (currentState == State.Chase || currentState == State.Flee || currentState == State.Kidnap_Charge || currentState == State.Kidnap_Carry)
{
array3 = walkFrames;
}
else if (currentState == State.Taunt)
{
array3 = tauntFrames;
((Component)spriteRenderer).transform.localScale = new Vector3(5f, 5f, 5f);
}
else if (currentState == State.Farming_Aura)
{
array3 = auraFarmFrames;
}
Animate(array3);
}
public void WakeUpFromAura()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if (currentState == State.Farming_Aura)
{
currentState = State.Taunt;
tauntTimer = 0f;
if ((Object)(object)audioSource != (Object)null && (Object)(object)audioSource.clip == (Object)(object)clipAuraFarm)
{
audioSource.Stop();
}
NavMeshHit val = default(NavMeshHit);
if (NavMesh.SamplePosition(((Component)this).transform.position, ref val, 100f, -1))
{
((Component)this).transform.position = ((NavMeshHit)(ref val)).position;
}
if ((Object)(object)agent != (Object)null)
{
((Behaviour)agent).enabled = true;
}
}
}
private void Animate(Sprite[] array)
{
if (array != null && array.Length > 0)
{
frameTimer += Time.deltaTime;
float num = ((currentState == State.Taunt) ? 6f : fps);
if (frameTimer >= 1f / num)
{
frameTimer = 0f;
currentFrameIndex = (currentFrameIndex + 1) % array.Length;
spriteRenderer.sprite = array[currentFrameIndex];
}
}
}
private void SetupPlayerReflection()
{
if (reflectionDone)
{
return;
}
reflectionDone = true;
Type type = null;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
type = assembly.GetType("Player");
if (type != null)
{
break;
}
}
if (type == null)
{
return;
}
Type type2 = null;
Assembly[] assemblies2 = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly2 in assemblies2)
{
type2 = assembly2.GetType("PlayerRagdoll");
if (type2 != null)
{
break;
}
}
FieldInfo field = type.GetField("localPlayer", BindingFlags.Static | BindingFlags.Public);
if (field != null)
{
ref MonoBehaviour reference = ref playerLocalMono;
object? value = field.GetValue(null);
reference = (MonoBehaviour)((value is MonoBehaviour) ? value : null);
}
if (type2 != null)
{
fnMoveRigs = type2.GetMethod("MoveAllRigsTo", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(Vector3) }, null);
fnAddForce = type2.GetMethod("AddForce", BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
{
typeof(Vector3),
typeof(ForceMode)
}, null);
fnTeleport = type2.GetMethod("CallFall", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(float) }, null);
fnRagdollField = type.GetField("ragdoll", BindingFlags.Instance | BindingFlags.Public);
}
}
private MonoBehaviour GetRagdoll()
{
if ((Object)(object)playerLocalMono == (Object)null || fnRagdollField == null)
{
return null;
}
object? value = fnRagdollField.GetValue(playerLocalMono);
return (MonoBehaviour)((value is MonoBehaviour) ? value : null);
}
private void GameThrowPlayer(Vector3 force)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
MonoBehaviour ragdoll = GetRagdoll();
if ((Object)(object)ragdoll != (Object)null && fnAddForce != null)
{
fnAddForce.Invoke(ragdoll, new object[2]
{
force,
(object)(ForceMode)2
});
}
if ((Object)(object)ragdoll != (Object)null && fnTeleport != null)
{
fnTeleport.Invoke(ragdoll, new object[1] { 3f });
}
}
private void FindKidnapDestination()
{
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
float num = float.PositiveInfinity;
MonoBehaviour[] array = Object.FindObjectsByType<MonoBehaviour>((FindObjectsSortMode)0);
foreach (MonoBehaviour val in array)
{
if ((Object)(object)((Component)val).gameObject == (Object)(object)((Component)this).gameObject || (Object)(object)((Component)val).transform.root == (Object)(object)playerRoot)
{
continue;
}
string text = ((object)val).GetType().Name.ToLower();
if (text.Contains("bot") || text.Contains("enemy") || text.Contains("monster"))
{
float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
if (num2 < num)
{
num = num2;
kidnapDestinationEnemy = ((Component)val).gameObject;
}
}
}
}
private Rigidbody GetPlayerHipRigidbody()
{
MonoBehaviour val = (((Object)(object)playerLocalMono != (Object)null) ? playerLocalMono : null);
if ((Object)(object)val == (Object)null)
{
return null;
}
Rigidbody[] componentsInChildren = ((Component)val).GetComponentsInChildren<Rigidbody>(true);
if (componentsInChildren == null || componentsInChildren.Length == 0)
{
componentsInChildren = ((Component)((Component)val).transform.root).GetComponentsInChildren<Rigidbody>(true);
}
if (componentsInChildren == null || componentsInChildren.Length == 0)
{
return null;
}
Rigidbody[] array = componentsInChildren;
foreach (Rigidbody val2 in array)
{
if (((Object)((Component)val2).gameObject).name.ToLower().Contains("hip"))
{
return val2;
}
}
return componentsInChildren[0];
}
private void TerminarSecuestroFisico(Vector3 dropPosition)
{
//IL_00a6: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: 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)
if ((Object)(object)audioSource != (Object)null)
{
audioSource.Stop();
}
if ((Object)(object)kidnappingJoint != (Object)null)
{
Object.Destroy((Object)(object)kidnappingJoint);
}
foreach (Collider disabledCollider in disabledColliders)
{
if ((Object)(object)disabledCollider != (Object)null)
{
disabledCollider.enabled = true;
}
}
disabledColliders.Clear();
Vector3 val;
if (!((Object)(object)kidnapDestinationEnemy != (Object)null))
{
val = Vector3.up * 10f;
}
else
{
Vector3 val2 = kidnapDestinationEnemy.transform.position - dropPosition;
val = ((Vector3)(ref val2)).normalized * 15f + Vector3.up * 5f;
}
Vector3 force = val;
GameThrowPlayer(force);
((Component)this).transform.position = spawnPosition;
if ((Object)(object)agent != (Object)null)
{
((Behaviour)agent).enabled = false;
}
currentState = State.Farming_Aura;
currentFrameIndex = 0;
carryTimer = 0f;
tauntTimer = 0f;
kidnapDestinationEnemy = null;
Debug.Log((object)("Roaring Knight ha vuelto a su posicion de spawn: " + spawnPosition));
}
}