Guest User

Untitled

a guest
Apr 11th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. using BepInEx;
  8. using HarmonyLib;
  9. using Mimics.API;
  10. using System.Reflection;
  11. using System.Reflection.Emit;
  12. using DunGen;
  13. using ScarletMansion.GamePatch.FixValues;
  14. using UnityEngine.Events;
  15. using GameNetcodeStuff;
  16. using Mimics;
  17. using ScarletMansion.GamePatch.Components;
  18.  
  19. namespace ScarletMansion.ModPatch {
  20.   public class MimicsPatch : ModPatch {
  21.  
  22.     public MimicsPatch(string guid) : base(guid) { }
  23.  
  24.     public override void AddPatch() {
  25.       MimicsAPI.GetAPI().RegisterMimicEventHandler(new SDMMimicEventHandler());
  26.       Plugin.Instance.harmony.PatchAll(typeof(MimicsPatch));
  27.     }
  28.  
  29.     public class SDMMimicEventHandler : MimicEventHandler
  30.     {
  31.       public override string ModGUID => Plugin.modGUID;
  32.  
  33.       public override bool IsMyInteriorLoaded => DunGenPatch.Patch.active;
  34.  
  35.       public override void OnMimicCreated(MimicDoor mimicDoor, Doorway doorway) {
  36.       var c = doorway.transform.parent.GetComponentInChildren<DunGenPatch.Doorways.DoorwayCleanup>();
  37.       if (c != null) {
  38.         c.overrideConnector = true;
  39.         c.overrideNoDoorway = true;
  40.       }
  41.  
  42.       var fixfireexit = doorway.GetComponentInChildren<FixFireExit>(true);
  43.       fixfireexit.ForcefullyEnableDoorway();
  44.  
  45.       var mimicDoorMesh = Utility.FindChildRecurvisely(mimicDoor.transform, "DoorMesh");
  46.       var mimicFrame = Utility.FindChildRecurvisely(mimicDoor.transform, "Frame");
  47.       var mimicLight = Utility.FindChildRecurvisely(mimicDoor.transform, "Light");
  48.  
  49.       if (fixfireexit.EnableVanillaFireExit){
  50.         FixDoorwayForVanillaFireExit(fixfireexit, mimicDoorMesh, mimicFrame, mimicLight);
  51.       } else {
  52.         FixDoorwayForSDMFireExit(fixfireexit, mimicDoorMesh, mimicFrame, mimicLight);
  53.       }
  54.  
  55.       Plugin.logger.LogInfo("Fixed a doorway for a mimic");
  56.       }
  57.  
  58.       public override void OnMimicAttackStart(MimicDoor mimicDoor, PlayerControllerB playerToAttack) {
  59.         var doorway = mimicDoor.GetComponentInParent<Doorway>();
  60.         var fireexit = doorway.GetComponentInChildren<ScarletFireExit>();
  61.         fireexit.DisableEnablePortal();
  62.       }
  63.     }
  64.  
  65.     private static bool colorBlindModeLastValue;
  66.  
  67.     [HarmonyPrefix]
  68.     [HarmonyPatch("Mimics.Mimics+RoundManagerPatch, Mimics", "SetExitIDsPatch")]
  69.     public static void SetExitIDsPatchPrefix(){
  70.       colorBlindModeLastValue = Mimics.Mimics.ColorBlindMode;
  71.     }
  72.  
  73.     [HarmonyPostfix]
  74.     [HarmonyPatch("Mimics.Mimics+RoundManagerPatch, Mimics", "SetExitIDsPatch")]
  75.     public static void SetExitIDsPatchPostfix(){
  76.       Mimics.Mimics.ColorBlindMode = colorBlindModeLastValue;
  77.     }
  78.  
  79.     private static void FixDoorwayForVanillaFireExit(FixFireExit fixFireExit, Transform mimicDoorMesh, Transform mimicFrame, Transform mimicLight){
  80.       if (mimicDoorMesh != null) {
  81.         mimicDoorMesh.localPosition = new Vector3(-0.07f, 0f, 0.06f);
  82.         var sc = mimicDoorMesh.localScale;
  83.         sc.y = -0.0002f;
  84.         sc.z = -0.000161f;
  85.         mimicDoorMesh.localScale = sc;
  86.       } else {
  87.         Plugin.logger.LogWarning("Could not find DoorMesh in mimic gameobject. It will look weird but nothing should break");
  88.       }
  89.  
  90.       if (mimicFrame != null) {
  91.         mimicFrame.localPosition = new Vector3(0f, -0.02f, 0.07f);
  92.         mimicFrame.localScale = new Vector3(1.08f, 1.008f, 1.02f);
  93.       } else {
  94.         Plugin.logger.LogWarning("Could not find Frame in mimic gameobject. It will look weird but nothing should break");
  95.       }
  96.     }
  97.  
  98.     private static void FixDoorwayForSDMFireExit(FixFireExit fixFireExit, Transform mimicDoorMesh, Transform mimicFrame, Transform mimicLight){
  99.       Mimics.Mimics.ColorBlindMode = true;
  100.       fixFireExit.ForcefullyEnableSDMRender();
  101.       fixFireExit.sdmFireExit.enablePortalAnimation = true;
  102.  
  103.       if (mimicDoorMesh != null) mimicDoorMesh.gameObject.SetActive(false);
  104.       else Plugin.logger.LogWarning("Could not find DoorMesh in mimic gameobject. It will look weird but nothing should break");
  105.  
  106.       if (mimicFrame != null) mimicFrame.gameObject.SetActive(false);
  107.       else Plugin.logger.LogWarning("Could not find Frame in mimic gameobject. It will look weird but nothing should break");
  108.  
  109.       if (mimicLight != null) mimicLight.gameObject.SetActive(false);
  110.       else Plugin.logger.LogWarning("Could not find Light in mimic gameobject. It will look weird but nothing should break");
  111.     }
  112.  
  113.   }
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment