SHA256
75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using ADOFAIRenderer.Core;
|
|
using HarmonyLib;
|
|
|
|
namespace ADOFAIRenderer.Patch.Game
|
|
{
|
|
[HarmonyPatch(typeof(EndscreenLanterns))]
|
|
// ReSharper disable once InconsistentNaming
|
|
public static class EndscreenLanternsPatch
|
|
{
|
|
[HarmonyPrefix]
|
|
[HarmonyPatch("Show")]
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static bool ForceHide(EndscreenLanterns __instance, ref int __result)
|
|
{
|
|
if (!RenderManager.IsActive) return true;
|
|
if (__instance != null)
|
|
{
|
|
__instance.Hide();
|
|
}
|
|
__result = 0; // Return 0 lanterns shown
|
|
return false; // Skip original Show method
|
|
}
|
|
|
|
[HarmonyPrefix]
|
|
[HarmonyPatch("Hide")]
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public static void PrefixHide(EndscreenLanterns __instance)
|
|
{
|
|
if (__instance == null) return;
|
|
if (!RenderManager.IsActive) return;
|
|
|
|
var traverse = Traverse.Create(__instance);
|
|
|
|
// Kill lampSequences (private Sequence[] lampSequences) via reflection
|
|
var lampSequencesField = traverse.Field("lampSequences");
|
|
var lampSequencesObj = lampSequencesField.GetValue();
|
|
if (lampSequencesObj is System.Array lampSequencesArray)
|
|
{
|
|
for (var i = 0; i < lampSequencesArray.Length; i++)
|
|
{
|
|
var item = lampSequencesArray.GetValue(i);
|
|
if (item == null) continue;
|
|
try
|
|
{
|
|
var killMethod = item.GetType().GetMethod("Kill", new[] { typeof(bool) });
|
|
killMethod?.Invoke(item, new object[] { false });
|
|
}
|
|
catch
|
|
{
|
|
// Ignore reflection errors
|
|
}
|
|
lampSequencesArray.SetValue(null, i);
|
|
}
|
|
}
|
|
|
|
// Kill chainSequence (private Sequence chainSequence) via reflection
|
|
var chainSequenceField = traverse.Field("chainSequence");
|
|
var chainSequenceObj = chainSequenceField.GetValue();
|
|
if (chainSequenceObj == null) return;
|
|
|
|
try
|
|
{
|
|
var killMethod = chainSequenceObj.GetType().GetMethod("Kill", new[] { typeof(bool) });
|
|
killMethod?.Invoke(chainSequenceObj, new object[] { false });
|
|
}
|
|
catch
|
|
{
|
|
// Ignore reflection errors
|
|
}
|
|
chainSequenceField.SetValue(null);
|
|
}
|
|
}
|
|
}
|