SDM_LethalCompany_Mod/MimicsPatch/ScarletMansionMimicsPatch/Patch.cs

119 lines
4.4 KiB
C#
Raw Normal View History

2024-04-28 21:41:33 +00:00

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;
2024-04-28 21:41:33 +00:00
using ScarletMansion.GamePatch.Components;
using ScarletMansion.DunGenPatch;
2024-04-28 21:41:33 +00:00
namespace ScarletMansionMimicsPatch {
2024-04-28 21:41:33 +00:00
public class Patch {
public static void Activate() {
MimicsAPI.GetAPI().RegisterMimicEventHandler(new Patch.SDMMimicEventHandler());
2024-04-28 21:41:33 +00:00
Plugin.Instance.harmony.PatchAll(typeof(Patch));
}
2024-04-28 21:41:33 +00:00
public class SDMMimicEventHandler : MimicEventHandler
{
2024-04-28 21:41:33 +00:00
public override string ModGUID => Plugin.modGUID;
public override bool IsMyInteriorLoaded => ScarletMansion.DunGenPatch.Patch.active;
2024-04-28 21:41:33 +00:00
public override void OnMimicCreated(MimicDoor mimicDoor, Doorway doorway) {
var c = doorway.transform.parent.GetComponentInChildren<DunGenPlus.Components.DoorwayCleanup>();
2024-04-28 21:41:33 +00:00
if (c != null) {
c.overrideConnector = true;
c.overrideNoDoorway = true;
}
var fixfireexit = doorway.GetComponentInChildren<FixFireExit>(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");
2024-04-28 21:41:33 +00:00
if (fixfireexit.EnableVanillaFireExit){
FixDoorwayForVanillaFireExit(fixfireexit, mimicDoorMesh, mimicFrame, mimicLight);
} else {
FixDoorwayForSDMFireExit(fixfireexit, mimicDoorMesh, mimicFrame, mimicLight);
}
Plugin.logger.LogDebug("Fixed a doorway for a mimic");
2024-04-28 21:41:33 +00:00
}
public override void OnMimicAttackStart(MimicDoor mimicDoor, PlayerControllerB playerToAttack) {
var doorway = mimicDoor.GetComponentInParent<Doorway>();
var fireexit = doorway.GetComponentInChildren<ScarletFireExit>();
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");
}
}
}