Files
ADOFAIRenderer/Patch/Game/scrFloorPatch.cs
T

73 lines
3.0 KiB
C#

using ADOFAIRenderer.Core;
using HarmonyLib;
namespace ADOFAIRenderer.Patch.Game;
/// <summary>
/// Prevents the end portal from being spawned on level tiles for the "non-tile" render option.
/// <para>
/// Patched member: <c>scrFloor.SpawnPortalParticles()</c>, which instantiates the animated portal prefab
/// (<c>scrPortalParticles</c>: glow, particles, cap and icon) as a child of the floor. The game calls it from
/// <c>scrLevelMaker</c>, <c>scrController</c> and <c>scrFloor</c> for the portal floor.
/// </para>
/// <para>
/// Active from stage Load when <c>AdvancedConfig.NonTile</c> is enabled, and only for floors that belong to
/// <c>scrLevelMaker.listFloors</c> (the level's tiles). See <see cref="scnGamePatch.ProcessFloors"/> for the other tile renderers.
/// </para>
/// </summary>
[HarmonyPatch(typeof(scrFloor))]
// ReSharper disable once InconsistentNaming
public class scrFloorPatch
{
/// <summary>Prefix of <c>scrFloor.SpawnPortalParticles</c>.</summary>
/// <param name="__instance">The floor that would receive the portal.</param>
/// <returns>True to run the original method (spawn the portal); false to skip it (non-tile render, level floor).</returns>
[HarmonyPrefix]
[HarmonyPatch("SpawnPortalParticles")]
// ReSharper disable once InconsistentNaming
public static bool SkipPortalSpawn(scrFloor __instance)
{
if (!scrLevelMaker.instance.listFloors.Contains(__instance)) return true;
var nonTile = RenderManager.Instance.stage >= RenderStage.Load &&
RenderManager.Instance.Configuration.AdvancedConfig.NonTile;
return !nonTile;
}
/// <summary>
/// Postfix of <c>scrFloor.Start</c>.
/// The game sets <c>enabled = isVisible</c> in Start(), which disables all off-screen tiles right at spawn.
/// When <c>DisableTileCulling</c> is enabled, force every floor to remain enabled.
/// </summary>
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void ForceEnableOnStart(scrFloor __instance)
{
if (RenderManager.Instance &&
RenderManager.Instance.stage >= RenderStage.Load &&
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
{
__instance.enabled = true;
}
}
/// <summary>
/// Prefix of <c>scrFloor.OnBecameInvisible</c>.
/// Skips disabling the floor component (<c>enabled = false</c>) while rendering with
/// <c>AdvancedConfig.DisableTileCulling</c> enabled, preventing the 1-frame update lag/glitch
/// when tiles enter the camera view.
/// </summary>
[HarmonyPrefix]
[HarmonyPatch("OnBecameInvisible")]
// ReSharper disable once InconsistentNaming
public static bool PreventTileCulling(scrFloor __instance)
{
if (RenderManager.Instance &&
RenderManager.Instance.stage >= RenderStage.Load &&
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
{
return false;
}
return true;
}
}