using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using BepInEx; using HarmonyLib; using Mimics; using Mimics.API; using System.Reflection; using System.Reflection.Emit; using DunGen; using ScarletMansion.GamePatch.FixValues; using UnityEngine.Events; using GameNetcodeStuff; using ScarletMansion; using ScarletMansion.GamePatch.Components; using ScarletMansion.DunGenPatch; namespace ScarletMansionMimicsPatch { public class Patch { public static void Activate() { MimicsAPI.GetAPI().RegisterMimicEventHandler(new Patch.SDMMimicEventHandler()); Plugin.Instance.harmony.PatchAll(typeof(Patch)); } public class SDMMimicEventHandler : MimicEventHandler { public override string ModGUID => Plugin.modGUID; public override bool IsMyInteriorLoaded => ScarletMansion.DunGenPatch.Patch.active; public override void OnMimicCreated(MimicDoor mimicDoor, Doorway doorway) { var c = doorway.transform.parent.GetComponentInChildren(); if (c != null) { c.overrideConnector = true; c.overrideNoDoorway = true; } var fixfireexit = doorway.GetComponentInChildren(true); fixfireexit.ForcefullyEnableDoorway(); var mimicDoorMesh = ScarletMansion.Utility.FindChildRecurvisely(mimicDoor.transform, "DoorMesh"); var mimicFrame = ScarletMansion.Utility.FindChildRecurvisely(mimicDoor.transform, "Frame"); var mimicLight = ScarletMansion.Utility.FindChildRecurvisely(mimicDoor.transform, "Light"); if (fixfireexit.EnableVanillaFireExit){ FixDoorwayForVanillaFireExit(fixfireexit, mimicDoorMesh, mimicFrame, mimicLight); } else { FixDoorwayForSDMFireExit(fixfireexit, mimicDoorMesh, mimicFrame, mimicLight); } Plugin.logger.LogDebug("Fixed a doorway for a mimic"); } public override void OnMimicAttackStart(MimicDoor mimicDoor, PlayerControllerB playerToAttack) { var doorway = mimicDoor.GetComponentInParent(); var fireexit = doorway.GetComponentInChildren(); fireexit?.DisableEnablePortal(); } } private static bool colorBlindModeLastValue; [HarmonyPrefix] [HarmonyPatch("Mimics.Mimics+RoundManagerPatch, Mimics", "SetExitIDsPatch")] public static void SetExitIDsPatchPrefix(){ colorBlindModeLastValue = Mimics.Mimics.ColorBlindMode; } [HarmonyPostfix] [HarmonyPatch("Mimics.Mimics+RoundManagerPatch, Mimics", "SetExitIDsPatch")] public static void SetExitIDsPatchPostfix(){ Mimics.Mimics.ColorBlindMode = colorBlindModeLastValue; } private static void FixDoorwayForVanillaFireExit(FixFireExit fixFireExit, Transform mimicDoorMesh, Transform mimicFrame, Transform mimicLight){ if (mimicDoorMesh != null) { mimicDoorMesh.localPosition = new Vector3(-0.07f, 0f, 0.06f); var sc = mimicDoorMesh.localScale; sc.y = -0.0002f; sc.z = -0.000161f; mimicDoorMesh.localScale = sc; } else { Plugin.logger.LogWarning("Could not find DoorMesh in mimic gameobject. It will look weird but nothing should break"); } if (mimicFrame != null) { mimicFrame.localPosition = new Vector3(0f, -0.02f, 0.07f); mimicFrame.localScale = new Vector3(1.08f, 1.008f, 1.02f); } else { Plugin.logger.LogWarning("Could not find Frame in mimic gameobject. It will look weird but nothing should break"); } } private static void FixDoorwayForSDMFireExit(FixFireExit fixFireExit, Transform mimicDoorMesh, Transform mimicFrame, Transform mimicLight){ Mimics.Mimics.ColorBlindMode = true; fixFireExit.ForcefullyEnableSDMRender(); fixFireExit.sdmFireExit.enablePortalAnimation = true; if (mimicDoorMesh != null) mimicDoorMesh.gameObject.SetActive(false); else Plugin.logger.LogWarning("Could not find DoorMesh in mimic gameobject. It will look weird but nothing should break"); if (mimicFrame != null) mimicFrame.gameObject.SetActive(false); else Plugin.logger.LogWarning("Could not find Frame in mimic gameobject. It will look weird but nothing should break"); if (mimicLight != null) mimicLight.gameObject.SetActive(false); else Plugin.logger.LogWarning("Could not find Light in mimic gameobject. It will look weird but nothing should break"); } } }