Zone patches

This commit is contained in:
2025-03-04 18:50:41 +02:00
parent 7ab5f9779b
commit 03127bd810
5 changed files with 108 additions and 7 deletions

View File

@@ -99,6 +99,7 @@
<Compile Include="Patching\InteractableHostPatches.cs" />
<Compile Include="Patching\ObjectHealthPatches.cs" />
<Compile Include="Patching\PlugPatches.cs" />
<Compile Include="Patching\ZonePatches.cs" />
<Compile Include="Sync\Components\SyncableBase.cs" />
<Compile Include="Sync\Components\SyncableDamage.cs" />
<Compile Include="Sync\Components\SyncableNetworking.cs" />

View File

@@ -11,11 +11,10 @@ using StressLevelZero.Interaction;
namespace BoneSync.Patching
{
[HarmonyPatch(typeof(Socket))]
public class SocketPatches
/*[HarmonyPatch(typeof(Socket))]
public static class SocketPatches
{
[HarmonyPatch(nameof(Socket.OnPlugEnter)), HarmonyPostfix]
public static void SocketEnterPatch(Socket __instance, Plug plug)
public static void GenericSocketEnterPatch(Socket __instance, Plug plug)
{
if (!plug) return;
MelonLogger.Msg("Plug entered: " + __instance.name + " Plug: " + plug.name);
@@ -27,8 +26,7 @@ namespace BoneSync.Patching
}
[HarmonyPatch(nameof(Socket.OnPlugExit)), HarmonyPostfix]
public static void SocketExitPatch(Socket __instance, Plug plug)
public static void GenericSocketExitPatch(Socket __instance, Plug plug)
{
if (!plug) return;
MelonLogger.Msg("Plug exited: " + __instance.name + " Plug: " + plug.name);
@@ -38,8 +36,56 @@ namespace BoneSync.Patching
byte socketId = syncable.GetSocketId(__instance);
MelonLogger.Msg("Plug exited: " + __instance.transform.GetPath() + " Plug: " + plug.transform.GetPath() + " ID: " + plugId + " Socket ID: " + socketId);
}
[HarmonyPatch(nameof(Socket.OnPlugEnter)), HarmonyPostfix]
public static void SocketEnterPatch(Socket __instance, Plug plug)
{
GenericSocketEnterPatch(__instance, plug);
}
[HarmonyPatch(nameof(Socket.OnPlugExit)), HarmonyPostfix]
public static void SocketExitPatch(Socket __instance, Plug plug)
{
GenericSocketExitPatch(__instance, plug);
}
}
[HarmonyPatch(typeof(MagazineSocket))]
public static class MagazineSocketPatches
{
[HarmonyPatch(nameof(MagazineSocket.OnPlugEnter)), HarmonyPostfix]
public static void MagazineSocketEnterPatch(MagazineSocket __instance, Plug plug)
{
SocketPatches.GenericSocketEnterPatch(__instance, plug);
}
[HarmonyPatch(nameof(MagazineSocket.OnPlugExit)), HarmonyPostfix]
public static void SocketExitPatch(MagazineSocket __instance, Plug plug)
{
SocketPatches.GenericSocketExitPatch(__instance, plug);
}
}*/
[HarmonyPatch(typeof(AlignPlug))]
public static class AlignPlugPatches
{
[HarmonyPatch(nameof(AlignPlug.InsertPlug)), HarmonyPostfix]
public static void AlignPlugInsertPatch(AlignPlug __instance, Socket socket)
{
MelonLogger.Msg("AlignPlug inserted: " + __instance.transform.GetPath() + " Socket: " + socket.transform.GetPath());
}
[HarmonyPatch(nameof(AlignPlug.EjectPlug)), HarmonyPostfix]
public static void AlignPlugEjectPatch(AlignPlug __instance)
{
MelonLogger.Msg("AlignPlug ejected: " + __instance.transform.GetPath());
}
}
public class PlugPatches
{
/*[HarmonyPatch(typeof(Plug))]

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoneSync.Sync.Components;
using HarmonyLib;
using MelonLoader;
using StressLevelZero.Zones;
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.lobby.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.lobby.IsConnected()) return true;
MelonLogger.Msg("ZoneEncounter.StartEncounter: " + __instance.transform.GetPath());
if (BoneSync.lobby.IsHost)
{
return true;
}
return false;
}
}
}

View File

@@ -16,6 +16,7 @@ namespace BoneSync.Sync.Components
public bool AllRigidbodiesSleeping()
{
if (rigidbodies.Length == 0) return false;
foreach (Rigidbody rb in rigidbodies)
{
try
@@ -25,11 +26,11 @@ namespace BoneSync.Sync.Components
catch { } // ignore null rigidbodies
}
return true;
}
private void SetKinematic(bool kinematic)
{
if (!this) return;
foreach (Rigidbody rb in rigidbodies)
{
try

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnhollowerBaseLib;
using UnityEngine;
namespace BoneSync.Sync