using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using BoneSync.Networking.Messages; using BoneSync.Sync; using HarmonyLib; using MelonLoader; using StressLevelZero; using StressLevelZero.Pool; using UnityEngine; namespace BoneSync.Patching { [HarmonyPatch(typeof(Pool))] internal class PoolPatches { public readonly static string[] ignoredPools = new string[] { "RigidbodyProjectile", "VFX Despawn Mesh", "AudioPlayer", "Decal", "PopupText", }; public static bool IsIgnoredPool(string poolName) { string lowercasePoolName = poolName.ToLower(); foreach (string ignoredPool in ignoredPools) { if (lowercasePoolName.Contains(ignoredPool.ToLower())) { return true; } } return false; } [HarmonyPatch(nameof(Pool.Spawn))] [HarmonyPostfix] private static void SpawnPatchPost(Pool __instance, ref GameObject __result) { //MelonLogger.Msg("Spawned object: " + __result.name); } [HarmonyPatch(nameof(Pool.Spawn))] [HarmonyPrefix] private static bool SpawnPatchPre(Pool __instance, ref Vector3 position, ref Quaternion rotation, ref Il2CppSystem.Nullable scale, ref Il2CppSystem.Nullable autoEnable) { if (CallPatchedMethods.allowPatchedMethodCall) return true; if (IsIgnoredPool(__instance.name)) return true; if (BoneSync.lobby.IsConnected()) { MelonLogger.Msg("Patched Spawning object in pool: " + __instance.name); return BoneSync.lobby.IsHost; // only allow host to spawn objects naturally } return true; } } }