zone patches

This commit is contained in:
Aaro Varis
2025-03-09 23:15:51 +02:00
parent 3b0c26a687
commit f9db5be09b

View File

@@ -8,9 +8,84 @@ using HarmonyLib;
using MelonLoader;
using StressLevelZero.Pool;
using StressLevelZero.Zones;
using UnityEngine;
namespace BoneSync.Patching
{
public static class ZoneTrackingUtilities
{
public static Dictionary<SceneZone, int> zoneCount = new Dictionary<SceneZone, int>();
public static Dictionary<PlayerTrigger, int> triggerCount = new Dictionary<PlayerTrigger, int>();
public static void Increment(SceneZone zone)
{
if (!zoneCount.ContainsKey(zone))
zoneCount.Add(zone, 0);
zoneCount[zone]++;
}
public static void Decrement(SceneZone zone)
{
if (!zoneCount.ContainsKey(zone))
zoneCount.Add(zone, 0);
zoneCount[zone]--;
zoneCount[zone] = Mathf.Clamp(zoneCount[zone], 0, int.MaxValue);
}
public static bool CanEnter(SceneZone zone)
{
if (!zoneCount.ContainsKey(zone))
return false;
return zoneCount[zone] <= 1;
}
public static bool CanExit(SceneZone zone)
{
if (!zoneCount.ContainsKey(zone))
return false;
return zoneCount[zone] <= 0;
}
public static void Increment(PlayerTrigger trigger)
{
if (!triggerCount.ContainsKey(trigger))
triggerCount.Add(trigger, 0);
triggerCount[trigger]++;
}
public static void Decrement(PlayerTrigger trigger)
{
if (!triggerCount.ContainsKey(trigger))
triggerCount.Add(trigger, 0);
triggerCount[trigger]--;
triggerCount[trigger] = Mathf.Clamp(triggerCount[trigger], 0, int.MaxValue);
}
public static bool CanEnter(PlayerTrigger trigger)
{
if (!triggerCount.ContainsKey(trigger))
return false;
return triggerCount[trigger] <= 1;
}
public static bool CanExit(PlayerTrigger trigger)
{
if (!triggerCount.ContainsKey(trigger))
return false;
return triggerCount[trigger] <= 0;
}
}
[HarmonyPatch(typeof(ZoneSpawner))]
public static class ZoneSpawnerPatch
{
@@ -50,4 +125,65 @@ namespace BoneSync.Patching
return false;
}
}
// SceneZone and PlayerTrigger patches are based on the ones from entanglement mod
[HarmonyPatch(typeof(SceneZone))]
public static class SceneZonePatch
{
[HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix]
public static bool EnterPrefix(SceneZone __instance, Collider other)
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Increment(__instance);
bool canEnter = ZoneTrackingUtilities.CanEnter(__instance);
return canEnter;
}
return true;
}
[HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix]
public static bool ExitPrefix(SceneZone __instance, Collider other)
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Decrement(__instance);
bool canExit = ZoneTrackingUtilities.CanExit(__instance);
return canExit;
}
return true;
}
}
[HarmonyPatch(typeof(PlayerTrigger))]
public static class PlayerTriggerPatch
{
[HarmonyPatch(nameof(PlayerTrigger.OnTriggerEnter)), HarmonyPrefix]
public static bool EnterPrefix(PlayerTrigger __instance, Collider other)
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Increment(__instance);
bool canEnter = ZoneTrackingUtilities.CanEnter(__instance);
return canEnter;
}
return true;
}
[HarmonyPatch(nameof(PlayerTrigger.OnTriggerExit)), HarmonyPrefix]
public static bool ExitPrefix(PlayerTrigger __instance, Collider other)
{
if (other.CompareTag("Player"))
{
ZoneTrackingUtilities.Decrement(__instance);
bool canExit = ZoneTrackingUtilities.CanExit(__instance);
return canExit;
}
return true;
}
}
}