using HarmonyLib; using QSB.EchoesOfTheEye.Ghosts.WorldObjects; using QSB.Patches; using QSB.Utility; using QSB.WorldSync; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace QSB.EchoesOfTheEye.Ghosts.Patches; [HarmonyPatch(typeof(GhostBrain))] internal class GhostBrainPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.GetCurrentActionName))] public static bool GetCurrentActionName(GhostBrain __instance, ref GhostAction.Name __result) { if (!QSBWorldSync.AllObjectsReady) { return true; } __result = __instance.GetWorldObject().GetCurrentActionName(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.GetCurrentAction))] public static bool GetCurrentAction(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.GetAction))] public static bool GetAction(GhostBrain __instance, GhostAction.Name actionName) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.GetThreatAwareness))] public static bool GetThreatAwareness(GhostBrain __instance, ref GhostData.ThreatAwareness __result) { if (!QSBWorldSync.AllObjectsReady) { return true; } __result = __instance.GetWorldObject().GetThreatAwareness(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.GetEffects))] public static bool GetEffects(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.CheckDreadAudioConditions))] public static bool CheckDreadAudioConditions(GhostBrain __instance, ref bool __result) { if (!QSBWorldSync.AllObjectsReady) { return true; } __result = __instance.GetWorldObject().CheckDreadAudioConditions(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.CheckFearAudioConditions))] public static bool CheckFearAudioConditions(GhostBrain __instance, bool fearAudioAlreadyPlaying, ref bool __result) { if (!QSBWorldSync.AllObjectsReady) { return true; } __result = __instance.GetWorldObject().CheckFearAudioConditions(fearAudioAlreadyPlaying); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.Awake))] public static bool Awake(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().Awake(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.Start))] public static bool Start(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().Start(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnDestroy))] public static bool OnDestroy(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().OnDestroy(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.TabulaRasa))] public static bool TabulaRasa(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().TabulaRasa(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.Die))] public static bool Die(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().Die(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.EscalateThreatAwareness))] public static bool EscalateThreatAwareness(GhostBrain __instance, GhostData.ThreatAwareness newThreatAwareness) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().EscalateThreatAwareness(newThreatAwareness); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.WakeUp))] public static bool WakeUp(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().WakeUp(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.HearGhostCall))] public static bool HearGhostCall(GhostBrain __instance, Vector3 playerLocalPosition, float reactDelay, bool playResponseAudio, ref bool __result) { if (!QSBWorldSync.AllObjectsReady) { return true; } __result = __instance.GetWorldObject().HearGhostCall(playerLocalPosition, reactDelay, playResponseAudio); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.HearCallForHelp))] public static bool HearCallForHelp(GhostBrain __instance, Vector3 playerLocalPosition, float reactDelay, ref bool __result) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.HintPlayerLocation), new Type[] { })] public static bool HintPlayerLocation(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.HintPlayerLocation), typeof(Vector3), typeof(float))] public static bool HintPlayerLocation(GhostBrain __instance, Vector3 localPosition, float informationTime) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.FixedUpdate))] public static bool FixedUpdate(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().FixedUpdate(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.Update))] public static bool Update(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().Update(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.FixedUpdate_ThreatAwareness))] public static bool FixedUpdate_ThreatAwareness(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().FixedUpdate_ThreatAwareness(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.EvaluateActions))] public static bool EvaluateActions(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().EvaluateActions(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.ChangeAction), typeof(GhostAction.Name))] public static bool ChangeAction(GhostBrain __instance, GhostAction.Name actionName) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.ChangeAction), typeof(GhostAction))] public static bool ChangeAction(GhostBrain __instance, GhostAction action) { if (!QSBWorldSync.AllObjectsReady) { return true; } DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.ClearPendingAction))] public static bool ClearPendingAction(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().ClearPendingAction(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnArriveAtPosition))] public static bool OnArriveAtPosition(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().OnArriveAtPosition(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnTraversePathNode))] public static bool OnTraversePathNode(GhostBrain __instance, GhostNode node) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().OnTraversePathNode(node); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnFaceNode))] public static bool OnFaceNode(GhostBrain __instance, GhostNode node) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().OnFaceNode(node); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnFinishFaceNodeList))] public static bool OnFinishFaceNodeList(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().OnFinishFaceNodeList(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnCallForHelp))] public static bool OnCallForHelp(GhostBrain __instance) { if (!QSBWorldSync.AllObjectsReady) { return true; } __instance.GetWorldObject().OnCallForHelp(); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnEnterDreamWorld))] public static bool OnEnterDreamWorld(GhostBrain __instance) { DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } [HarmonyPrefix] [HarmonyPatch(nameof(GhostBrain.OnExitDreamWorld))] public static bool OnExitDreamWorld(GhostBrain __instance) { DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error); return false; } }