113 lines
3.1 KiB
C#
113 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using BoneSync.Player;
|
|
using BoneSync.Sync.Components;
|
|
using HarmonyLib;
|
|
using MelonLoader;
|
|
using StressLevelZero.Pool;
|
|
using StressLevelZero.Zones;
|
|
using UnityEngine;
|
|
|
|
namespace BoneSync.Patching
|
|
{
|
|
|
|
[HarmonyPatch(typeof(ZoneSpawner))]
|
|
public static class ZoneSpawnerPatch
|
|
{
|
|
// this patch should catch most of the spawning, but the pool spawning patch should catch the rest
|
|
[HarmonyPatch(nameof(ZoneSpawner.Spawn)), HarmonyPrefix]
|
|
public static bool ZoneSpawnPrefix(ZoneSpawner __instance)
|
|
{
|
|
if (!BoneSync.IsConnected) return true; // do not block if not connected
|
|
|
|
MelonLogger.Msg("ZoneSpawner.Spawn: " + __instance.transform.GetPath());
|
|
|
|
if (BoneSync.lobby.IsHost)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false; // don't spawn if not host
|
|
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(ZoneEncounter))]
|
|
public static class ZoneEncounterPatch
|
|
{
|
|
[HarmonyPatch(nameof(ZoneEncounter.StartEncounter)), HarmonyPrefix]
|
|
public static bool ZoneEncounterSpawnPrefix(ZoneEncounter __instance)
|
|
{
|
|
if (!BoneSync.IsConnected) return true;
|
|
|
|
MelonLogger.Msg("ZoneEncounter.StartEncounter: " + __instance.transform.GetPath());
|
|
|
|
if (BoneSync.lobby.IsHost)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
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"))
|
|
{
|
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix]
|
|
public static bool ExitPrefix(SceneZone __instance, Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
|
}
|
|
|
|
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"))
|
|
{
|
|
|
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[HarmonyPatch(nameof(PlayerTrigger.OnTriggerExit)), HarmonyPrefix]
|
|
public static bool ExitPrefix(PlayerTrigger __instance, Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
|
|
return other.transform.IsChildOf(PlayerRig.localRigRoot);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|