Bunch of changes
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\xunit.runner.visualstudio.3.0.2\build\net472\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.3.0.2\build\net472\xunit.runner.visualstudio.props')" />
|
||||
<Import Project="..\packages\xunit.core.2.9.3\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.9.3\build\xunit.core.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -45,7 +43,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony, Version=2.9.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\MelonLoader\0Harmony.dll</HintPath>
|
||||
<HintPath>A:\SteamLibrary\steamapps\common\BONEWORKS\BONEWORKS\MelonLoader\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\MelonLoader\Managed\Assembly-CSharp.dll</HintPath>
|
||||
@@ -57,24 +55,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\MelonLoader\MelonLoader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -99,18 +82,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\MelonLoader\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.assert, Version=2.9.3.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.assert.2.9.3\lib\netstandard1.1\xunit.assert.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.core, Version=2.9.3.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.core.2.9.3\lib\net452\xunit.core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.execution.desktop, Version=2.9.3.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.execution.2.9.3\lib\net452\xunit.execution.desktop.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Networking\Messages\ObjectDamageMessage.cs" />
|
||||
@@ -288,30 +259,13 @@
|
||||
<Compile Include="Networking\ByteEncoder.cs" />
|
||||
<Compile Include="Sync\SceneSync.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\xunit.analyzers.1.18.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
|
||||
<Analyzer Include="..\packages\xunit.analyzers.1.18.0\analyzers\dotnet\cs\xunit.analyzers.fixes.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Facepunch.Steamworks\LICENSE.txt" />
|
||||
<EmbeddedResource Include="steam_api.dll" />
|
||||
<EmbeddedResource Include="steam_api64.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy /Y "$(TargetPath)" "C:\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\Mods\"</PostBuildEvent>
|
||||
<PostBuildEvent>xcopy /Y "$(TargetPath)" "A:\SteamLibrary\steamapps\common\BONEWORKS\BONEWORKS\Mods\"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\xunit.core.2.9.3\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.9.3\build\xunit.core.props'))" />
|
||||
<Error Condition="!Exists('..\packages\xunit.core.2.9.3\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.9.3\build\xunit.core.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.3.0.2\build\net472\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.3.0.2\build\net472\xunit.runner.visualstudio.props'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\xunit.core.2.9.3\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.9.3\build\xunit.core.targets')" />
|
||||
</Project>
|
||||
@@ -27,8 +27,6 @@ namespace BoneSync
|
||||
{
|
||||
SteamClient.Init(823500, true);
|
||||
|
||||
PatchAll();
|
||||
|
||||
SteamLobbyManager steamLobbyManager = new SteamLobbyManager();
|
||||
|
||||
lobby = steamLobbyManager;
|
||||
@@ -36,6 +34,8 @@ namespace BoneSync
|
||||
|
||||
SceneSync.Initialize();
|
||||
NetworkMessage.RegisterPacketTypes();
|
||||
|
||||
PatchAll();
|
||||
}
|
||||
|
||||
public static void PatchAll()
|
||||
|
||||
@@ -3,7 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if TEST
|
||||
using Xunit;
|
||||
#endif
|
||||
|
||||
namespace BoneSync.Networking.Messages
|
||||
{
|
||||
@@ -40,7 +43,7 @@ namespace BoneSync.Networking.Messages
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#if TEST
|
||||
public class LobbyInfoMessageTests
|
||||
{
|
||||
[Fact]
|
||||
@@ -58,4 +61,5 @@ namespace BoneSync.Networking.Messages
|
||||
Assert.Equal(5, newMessage.CurrentPlayers);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StressLevelZero.Combat;
|
||||
using BoneSync.Sync;
|
||||
using StressLevelZero.Combat;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -40,7 +41,7 @@ namespace BoneSync.Networking.Messages
|
||||
public ObjectHealthInfo objectHealthInfo;
|
||||
}
|
||||
|
||||
[PacketType(PacketType.ObjectEvent), PacketReliability(PacketReliability.Reliable)]
|
||||
[PacketType(PacketType.ObjectEvent), PacketReliability(PacketReliability.UnreliableNoDelay)]
|
||||
public class ObjectDamageMessage : NetworkMessage
|
||||
{
|
||||
public ObjectDamageInfo objectEventInfo => _objectEventInfo;
|
||||
@@ -57,6 +58,7 @@ namespace BoneSync.Networking.Messages
|
||||
byteEncoder.WriteVector3(_objectEventInfo.objectHealthInfo.normal);
|
||||
byteEncoder.WriteFloat(_objectEventInfo.objectHealthInfo.damage);
|
||||
byteEncoder.WriteBool(_objectEventInfo.objectHealthInfo.crit);
|
||||
byteEncoder.WriteByte((byte)_objectEventInfo.objectHealthInfo.attackType);
|
||||
}
|
||||
|
||||
public ObjectDamageMessage(Packet packet)
|
||||
@@ -70,11 +72,12 @@ namespace BoneSync.Networking.Messages
|
||||
_objectEventInfo.objectHealthInfo.normal = byteEncoder.ReadVector3();
|
||||
_objectEventInfo.objectHealthInfo.damage = byteEncoder.ReadFloat();
|
||||
_objectEventInfo.objectHealthInfo.crit = byteEncoder.ReadBool();
|
||||
_objectEventInfo.objectHealthInfo.attackType = (AttackType)byteEncoder.ReadByte();
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
|
||||
ObjectSync.OnObjectDamageMessage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
#if TEST
|
||||
using Xunit;
|
||||
#endif
|
||||
|
||||
namespace BoneSync.Networking
|
||||
{
|
||||
@@ -98,7 +100,7 @@ namespace BoneSync.Networking
|
||||
}
|
||||
public static NetworkMessage ParsePacket(Packet packet)
|
||||
{
|
||||
MelonLogger.Msg("Received packet of type " + packet.Info.packetType + " from " + packet.Info.senderId + " Length: " + packet.Data.Length);
|
||||
//MelonLogger.Msg("Received packet of type " + packet.Info.packetType + " from " + packet.Info.senderId + " Length: " + packet.Data.Length);
|
||||
// find a class that can parse this packet using Reflection
|
||||
// and return it
|
||||
if (!PacketTypeMap.ContainsKey(packet.Info.packetType))
|
||||
@@ -126,6 +128,11 @@ namespace BoneSync.Networking
|
||||
{
|
||||
Send(TransportBase.BORADCAST_ID);
|
||||
}
|
||||
|
||||
public void SendToHost()
|
||||
{
|
||||
Send(BoneSync.lobby.GetHostId());
|
||||
}
|
||||
public void Send(ulong receiverId)
|
||||
{
|
||||
if (BoneSync.lobby.IsConnected() == false)
|
||||
@@ -145,6 +152,7 @@ namespace BoneSync.Networking
|
||||
}
|
||||
|
||||
}
|
||||
#if TEST
|
||||
public class NetworkMessageTests
|
||||
{
|
||||
[Fact]
|
||||
@@ -154,4 +162,5 @@ namespace BoneSync.Networking
|
||||
Assert.NotEmpty(NetworkMessage.PacketTypeMap);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
#if TEST
|
||||
using Xunit;
|
||||
#endif
|
||||
|
||||
namespace BoneSync.Networking
|
||||
{
|
||||
@@ -98,7 +100,7 @@ namespace BoneSync.Networking
|
||||
return new Random().Next();
|
||||
}
|
||||
}
|
||||
|
||||
#if TEST
|
||||
public class PacketTests
|
||||
{
|
||||
[Fact]
|
||||
@@ -127,4 +129,5 @@ namespace BoneSync.Networking
|
||||
Assert.NotEqual(bytes, randomDataBytes);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -31,13 +31,17 @@ namespace BoneSync.Patching
|
||||
allowPatchedMethodCall = false;
|
||||
}
|
||||
|
||||
public static GameObject PoolSpawn(Pool __instance, Vector3 position, Quaternion rotation, Vector3 scale)
|
||||
public static Poolee InstantiatePoolee(Pool pool, Vector3 position, Quaternion rotation, Vector3 scale)
|
||||
{
|
||||
allowPatchedMethodCall = true;
|
||||
Il2CppSystem.Nullable<Vector3> scaleNullable = new Il2CppSystem.Nullable<Vector3>(scale);
|
||||
GameObject result = __instance.Spawn(position, rotation, scaleNullable, new Il2CppSystem.Nullable<bool>(true));
|
||||
Poolee poolee = pool.InstantiatePoolee(position, rotation);
|
||||
poolee.transform.position = position;
|
||||
poolee.transform.rotation = rotation;
|
||||
poolee.transform.localScale = scale;
|
||||
poolee.transform.parent = null;
|
||||
poolee.gameObject.SetActive(true);
|
||||
allowPatchedMethodCall = false;
|
||||
return result;
|
||||
return poolee;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,8 @@ namespace BoneSync.Patching
|
||||
public static void OnEnablePatch(InteractableHost __instance)
|
||||
{
|
||||
//MelonLoader.MelonLogger.Msg("InteractableHost enabled: " + __instance.name + " Manager: " + __instance?.manager?.name);
|
||||
ObjectSync.MakeOrGetSyncable(__instance);
|
||||
}
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance);
|
||||
|
||||
[HarmonyPatch(nameof(InteractableHost.OnDestroy)), HarmonyPostfix]
|
||||
public static void OnDestroyPatch(InteractableHost __instance)
|
||||
{
|
||||
MelonLogger.Msg("InteractableHost destroyed: " + __instance.name);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(InteractableHost.AttachHand)), HarmonyPostfix]
|
||||
|
||||
@@ -14,6 +14,7 @@ using UnityEngine;
|
||||
|
||||
namespace BoneSync.Patching
|
||||
{
|
||||
|
||||
[HarmonyPatch(typeof(ObjectDestructable))]
|
||||
public class ObjectDestructablePatches
|
||||
{
|
||||
@@ -23,10 +24,11 @@ namespace BoneSync.Patching
|
||||
{
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||
MelonLoader.MelonLogger.Msg("ObjectDestructable.TakeDamage: " + damage);
|
||||
Syncable syncable = ObjectSync.GetSyncableFromCache(__instance.gameObject);
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
||||
if (syncable != null)
|
||||
{
|
||||
if (!syncable.Registered) return true;
|
||||
if (damage > 0.5f) syncable.RegisterSyncable();
|
||||
if (!syncable.isOwner) return true;
|
||||
MelonLoader.MelonLogger.Msg("Patch: ObjectDestructable.TakeDamage: " + damage + " " + syncable.gameObject.name);
|
||||
ObjectHealthInfo objectHealthInfo = new ObjectHealthInfo(__instance._health, __instance._hits, normal, damage, crit, attackType);
|
||||
|
||||
@@ -47,10 +49,11 @@ namespace BoneSync.Patching
|
||||
{
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||
MelonLoader.MelonLogger.Msg("Prop_Health.TAKEDAMAGE: " + damage);
|
||||
Syncable syncable = ObjectSync.GetSyncableFromCache(__instance.gameObject);
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
||||
if (syncable != null)
|
||||
{
|
||||
if (!syncable.Registered) return true;
|
||||
if (damage > 0.5f) syncable.RegisterSyncable();
|
||||
if (!syncable.isOwner) return true;
|
||||
MelonLoader.MelonLogger.Msg("Patch: Prop_Health.TAKEDAMAGE: " + damage + " " + syncable.gameObject.name);
|
||||
ObjectHealthInfo objectHealthInfo = new ObjectHealthInfo(__instance.cur_Health, __instance.hits, Vector3.zero, damage, crit, attackType);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -6,61 +7,151 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BoneSync.Networking.Messages;
|
||||
using BoneSync.Sync;
|
||||
using BoneSync.Sync.Components;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using StressLevelZero;
|
||||
using StressLevelZero.Pool;
|
||||
using StressLevelZero.Props.Weapons;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BoneSync.Patching
|
||||
{
|
||||
|
||||
[HarmonyPatch(typeof(Pool))]
|
||||
internal class PoolPatches
|
||||
public static class PoolBlacklist
|
||||
{
|
||||
private static Dictionary<Pool, Boolean> _blacklistedCache = new Dictionary<Pool, bool>();
|
||||
|
||||
public readonly static string[] ignoredPools = new string[] {
|
||||
"RigidbodyProjectile",
|
||||
"VFX Despawn Mesh",
|
||||
"AudioPlayer",
|
||||
"Decal",
|
||||
"PopupText",
|
||||
};
|
||||
|
||||
public static bool IsIgnoredPool(string poolName)
|
||||
private static bool _isBlacklistedPool(Pool pool)
|
||||
{
|
||||
string lowercasePoolName = poolName.ToLower();
|
||||
foreach (string ignoredPool in ignoredPools)
|
||||
{
|
||||
if (lowercasePoolName.Contains(ignoredPool.ToLower()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (pool.name.Contains("RigidbodyProjectile")) return true;
|
||||
if (pool.name.Contains("VFX Despawn Mesh")) return true;
|
||||
if (pool.name.Contains("AudioPlayer")) return true;
|
||||
if (pool.name.Contains("Decal")) return true;
|
||||
if (pool.name.Contains("PopupText")) return true;
|
||||
|
||||
if (pool.Prefab.GetComponent<SpawnFragment>() != null) return true;
|
||||
if (pool.Prefab.GetComponent<SpawnFragmentArray>() != null) return true;
|
||||
if (pool.Prefab.GetComponent<Magazine>() != null) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(Pool.Spawn))]
|
||||
[HarmonyPostfix]
|
||||
private static void SpawnPatchPost(Pool __instance, ref GameObject __result)
|
||||
public static bool isBlacklistedPool(Pool pool)
|
||||
{
|
||||
//MelonLogger.Msg("Spawned object: " + __result.name);
|
||||
if (_blacklistedCache.ContainsKey(pool))
|
||||
return _blacklistedCache[pool];
|
||||
_blacklistedCache[pool] = _isBlacklistedPool(pool);
|
||||
return _blacklistedCache[pool];
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(Pool.Spawn))]
|
||||
[HarmonyPatch(typeof(Pool))]
|
||||
public static class PoolPatches
|
||||
{
|
||||
[HarmonyPatch(nameof(Pool.InstantiatePoolee))]
|
||||
[HarmonyPrefix]
|
||||
private static bool SpawnPatchPre(Pool __instance, ref Vector3 position, ref Quaternion rotation, ref Il2CppSystem.Nullable<Vector3> scale, ref Il2CppSystem.Nullable<bool> autoEnable)
|
||||
private static bool InstantiatePooleePatchPre(Pool __instance)
|
||||
{
|
||||
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
|
||||
}
|
||||
if (!__instance.Prefab)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(Pool.InstantiatePoolee))]
|
||||
[HarmonyPostfix]
|
||||
private static void InstantiatePooleePatchPost(Pool __instance, Poolee __result, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
if (__instance == null) return;
|
||||
if (PoolBlacklist.isBlacklistedPool(__instance)) return;
|
||||
MelonLogger.Msg("Patched Instantiating object in pool: " + __instance.name);
|
||||
__result.onSpawnDelegate = Il2CppSystem.Delegate.Combine(__result.onSpawnDelegate, (Il2CppSystem.Action<GameObject>)((g) => { PooleePatches.OnSpawnPatchPost(__result); })).Cast<Il2CppSystem.Action<GameObject>>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*[HarmonyPatch(nameof(Pool.Spawn))]
|
||||
[HarmonyPostfix]
|
||||
private static void SpawnPatchPost(Pool __instance, ref GameObject __result)
|
||||
{
|
||||
if (__instance == null) return;
|
||||
if (__instance.Prefab == null) return;
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return;
|
||||
if (PoolBlacklist.isBlacklistedPool(__instance)) return;
|
||||
if (BoneSync.lobby.IsConnected())
|
||||
{
|
||||
MelonLogger.Msg("Patched Spawning object in pool: " + __instance.name);
|
||||
bool isHost = BoneSync.lobby.IsHost;
|
||||
if (!isHost) GameObject.DestroyImmediate(__result);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*[HarmonyPatch(nameof(Pool.Spawn))]
|
||||
[HarmonyPrefix]
|
||||
private static bool SpawnPatchPre(Pool __instance, ref Vector3 position, ref Quaternion rotation, ref Il2CppSystem.Nullable<Vector3> scale, ref Il2CppSystem.Nullable<bool> autoEnable)
|
||||
{
|
||||
if (__instance == null) return true;
|
||||
if (__instance.Prefab == null) return true;
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||
if (PoolBlacklist.isBlacklistedPool(__instance)) 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
|
||||
}
|
||||
__instance.
|
||||
return true;
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
[HarmonyPatch(typeof(Poolee))]
|
||||
public static class PooleePatches
|
||||
{
|
||||
|
||||
public static void OnSpawnPatchPost(Poolee __instance)
|
||||
{
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return;
|
||||
if (__instance.pool == null) return;
|
||||
if (PoolBlacklist.isBlacklistedPool(__instance.pool)) return;
|
||||
MelonLogger.Msg("Poolee.OnSpawn: " + __instance.gameObject.transform.GetPath());
|
||||
if (!BoneSync.lobby.IsConnected()) return;
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance);
|
||||
|
||||
if (BoneSync.lobby.IsHost)
|
||||
{
|
||||
//syncable.RegisterSyncable();
|
||||
} else
|
||||
{
|
||||
MelonCoroutines.Start(OnSpawnClient(__instance));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator OnSpawnClient(Poolee poolee)
|
||||
{
|
||||
GameObject go = poolee.gameObject;
|
||||
if (SceneLoader.loading)
|
||||
{
|
||||
while (SceneLoader.loading)
|
||||
{
|
||||
go.SetActive(false);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
go.SetActive(false);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static IEnumerator OnSpawnHost(Poolee poolee)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,23 +31,6 @@ namespace BoneSync.Sync.Components
|
||||
return "/" + current.name;
|
||||
return current.parent.GetPath() + "/" + current.name;
|
||||
}
|
||||
|
||||
public static Transform FromPath(string path)
|
||||
{
|
||||
Transform current = null;
|
||||
foreach (string name in path.Split('/'))
|
||||
{
|
||||
if (current == null)
|
||||
{
|
||||
current = GameObject.Find(name).transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
current = current.Find(name);
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
[RegisterTypeInIl2Cpp]
|
||||
@@ -76,13 +59,26 @@ namespace BoneSync.Sync.Components
|
||||
public bool isStale => Time.time - _lastSyncTime > 5f;
|
||||
public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId();
|
||||
|
||||
public bool IsHolding()
|
||||
{
|
||||
if (interactableManager)
|
||||
{
|
||||
return interactableManager.grabbedHosts.Count > 0;
|
||||
}
|
||||
if (interactableHost)
|
||||
{
|
||||
return interactableHost.isAttached;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ShouldSendSync()
|
||||
{
|
||||
if (!Registered) return false;
|
||||
if (!isOwner) return false;
|
||||
if (isStale) return true;
|
||||
|
||||
return false;
|
||||
if (AllRigidbodiesSleeping()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public ushort GetSyncId() => _syncId;
|
||||
@@ -111,13 +107,17 @@ namespace BoneSync.Sync.Components
|
||||
private AIBrain aiBrain;
|
||||
private PuppetMaster puppetMaster;
|
||||
|
||||
private SpawnFragment spawnFragment;
|
||||
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
syncablesCache[gameObject] = this;
|
||||
|
||||
FindComponents();
|
||||
|
||||
bool shouldAutoSync = CheckIfShouldAutoSync();
|
||||
if (shouldAutoSync)
|
||||
if (shouldAutoSync && BoneSync.lobby.IsHost)
|
||||
{
|
||||
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
||||
RegisterSyncable();
|
||||
@@ -140,7 +140,7 @@ namespace BoneSync.Sync.Components
|
||||
}
|
||||
if (interactableHost || interactableManager)
|
||||
{
|
||||
return transform.GetPath();
|
||||
return transform.GetPath().Replace(" ", "[]");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -157,6 +157,7 @@ namespace BoneSync.Sync.Components
|
||||
gun = GetComponent<Gun>();
|
||||
magazine = GetComponent<Magazine>();
|
||||
plugs = GetComponentsInChildren<Plug>();
|
||||
spawnFragment = GetComponent<SpawnFragment>();
|
||||
//rigidbodies = GetComponentsInChildren<Rigidbody>();
|
||||
UpdateTransformList();
|
||||
|
||||
@@ -165,6 +166,7 @@ namespace BoneSync.Sync.Components
|
||||
|
||||
public bool CanBeSynced()
|
||||
{
|
||||
if (spawnFragment) return false; // if has spawn fragment, don't sync
|
||||
FindComponents();
|
||||
if (rigidbodies.Length > 0) return true;
|
||||
|
||||
@@ -174,7 +176,7 @@ namespace BoneSync.Sync.Components
|
||||
public void OnDestroy()
|
||||
{
|
||||
DiscardSyncable();
|
||||
MelonLogger.Msg("Syncable destroyed: " + transform.GetPath());
|
||||
//MelonLogger.Msg("Syncable destroyed: " + transform.GetPath());
|
||||
}
|
||||
|
||||
public void DiscardSyncable()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MelonLoader;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -16,24 +17,24 @@ namespace BoneSync.Sync.Components
|
||||
_lastSyncTime = Time.time;
|
||||
ObjectSync.SendObjectSyncMessage(this);
|
||||
}
|
||||
public async Task SyncCoroutineAsync()
|
||||
public IEnumerator SyncCoroutineAsync()
|
||||
{
|
||||
MelonLogger.Msg("Running sync coroutine for: " + transform.GetPath());
|
||||
if (_syncCoroutineRunning) return;
|
||||
if (_syncCoroutineRunning) yield break;
|
||||
_syncCoroutineRunning = true;
|
||||
while (isOwner)
|
||||
{
|
||||
if (ShouldSendSync()) SendObjectSync();
|
||||
await Task.Delay(!Registered ? 1000 : 1000 / SYNC_FPS);
|
||||
yield return new WaitForSeconds(!Registered ? 1 : 1 / SYNC_FPS);
|
||||
}
|
||||
_syncCoroutineRunning = false;
|
||||
return;
|
||||
yield break;
|
||||
}
|
||||
public void SetOwner(ulong ownerId)
|
||||
{
|
||||
MelonLogger.Msg("Setting owner for " + _syncId + " to " + ownerId);
|
||||
_ownerId = ownerId;
|
||||
_ = SyncCoroutineAsync();
|
||||
MelonCoroutines.Start(SyncCoroutineAsync());
|
||||
UpdateKinematic();
|
||||
}
|
||||
private void _SendRegisterSync()
|
||||
@@ -42,5 +43,15 @@ namespace BoneSync.Sync.Components
|
||||
SetOwner(BoneSync.lobby.GetLocalId());
|
||||
SetSyncId(ObjectSync.SendRegisterSyncableMessage(this));
|
||||
}
|
||||
|
||||
public void OnOwnershipTransferRequest(ulong newOwnerId)
|
||||
{
|
||||
MelonLogger.Msg("Ownership transfer request for " + _syncId + " to " + newOwnerId);
|
||||
if (isOwner)
|
||||
{
|
||||
MelonLogger.Msg("Sending ownership transfer for " + _syncId + " to " + newOwnerId);
|
||||
//BoneSync.lobby.SendOwnershipTransferMessage(_syncId, newOwnerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,15 @@ namespace BoneSync.Sync.Components
|
||||
{
|
||||
public partial class Syncable : MonoBehaviour
|
||||
{
|
||||
|
||||
public bool AllRigidbodiesSleeping()
|
||||
{
|
||||
foreach (Rigidbody rb in rigidbodies)
|
||||
{
|
||||
if (!rb.IsSleeping()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void SetKinematic(bool kinematic)
|
||||
{
|
||||
foreach (Rigidbody rb in rigidbodies)
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace BoneSync.Sync
|
||||
ownerId = syncable._ownerId,
|
||||
};
|
||||
}
|
||||
else if (syncable.poolee && syncable.poolee.pool)
|
||||
else if (syncable.poolee && syncable.poolee.pool && BoneSync.lobby.IsHost)
|
||||
{
|
||||
info = new RegisterSyncableInfo()
|
||||
{
|
||||
@@ -65,20 +65,14 @@ namespace BoneSync.Sync
|
||||
|
||||
|
||||
|
||||
RegisterSyncableMessage message = new RegisterSyncableMessage(info);
|
||||
if (BoneSync.lobby.IsHost)
|
||||
{
|
||||
info.id = GetNextId();
|
||||
message.Broadcast();
|
||||
}
|
||||
else
|
||||
new RegisterSyncableMessage(info).Broadcast();
|
||||
} else
|
||||
{
|
||||
if (message.senderId != BoneSync.lobby.GetHostId())
|
||||
{
|
||||
MelonLogger.Warning("Non host tried to send register syncable message");
|
||||
}
|
||||
info.id = 0;
|
||||
message.Send(BoneSync.lobby.GetHostId());
|
||||
new RegisterSyncableMessage(info).SendToHost();
|
||||
}
|
||||
|
||||
MelonLogger.Msg("Sending register syncable message for: " + syncable.transform.name + " with id: " + info.id + " and type : " + info.type);
|
||||
@@ -139,6 +133,20 @@ namespace BoneSync.Sync
|
||||
return syncable;
|
||||
}
|
||||
|
||||
public static Syncable MakeOrGetSyncable(GameObject gameObject)
|
||||
{
|
||||
Syncable syncable = GetSyncableFromCache(gameObject);
|
||||
if (syncable == null)
|
||||
{
|
||||
syncable = _MakeOrGetSyncable(gameObject);
|
||||
}
|
||||
return syncable;
|
||||
}
|
||||
public static Syncable MakeOrGetSyncable(Poolee poolee)
|
||||
{
|
||||
return _MakeOrGetSyncable(poolee.gameObject);
|
||||
}
|
||||
|
||||
public static Syncable MakeOrGetSyncable(InteractableHost interactableHost)
|
||||
{
|
||||
if (interactableHost.manager) return MakeOrGetSyncable(interactableHost.manager);
|
||||
@@ -150,19 +158,29 @@ namespace BoneSync.Sync
|
||||
return _MakeOrGetSyncable(interactableHostManager.gameObject);
|
||||
}
|
||||
|
||||
public static Syncable SpawnPooleeAndMakeSyncable(string poolName, RegisterSyncableInfo info)
|
||||
public static Syncable SpawnPooleeAndMakeSyncable(RegisterSyncableInfo info)
|
||||
{
|
||||
SimpleTransform spawnLocation = info.spawnInfo.Value.spawnLocation;
|
||||
Pool pool = PoolManager.GetPool(poolName);
|
||||
if (pool == null)
|
||||
|
||||
SpawnPoolableInfo spawnInfo = info.spawnInfo.Value;
|
||||
SimpleTransform spawnLocation = spawnInfo.spawnLocation;
|
||||
|
||||
// !! This is a bit of a hack, but it works for now
|
||||
// if pool starts with "pool - " remove it
|
||||
if (spawnInfo.poolName.StartsWith("pool - "))
|
||||
{
|
||||
MelonLogger.Warning("Pool not found: " + poolName);
|
||||
spawnInfo.poolName = spawnInfo.poolName.Substring(7);
|
||||
}
|
||||
|
||||
Pool pool = PoolManager.GetPool(spawnInfo.poolName);
|
||||
if (!pool)
|
||||
{
|
||||
MelonLogger.Warning("[SpawnPooleeAndMakeSyncable] Failed to find pool: " + spawnInfo.poolName);
|
||||
return null;
|
||||
}
|
||||
GameObject spawned = CallPatchedMethods.PoolSpawn(pool, spawnLocation.position, spawnLocation.rotation, spawnLocation.scale);
|
||||
MelonLogger.Msg("Spawned object: " + spawned.transform.GetPath() + " in pool: " + poolName);
|
||||
Poolee poolee = spawned.GetComponent<Poolee>();
|
||||
return _MakeOrGetSyncable(poolee.gameObject);
|
||||
Poolee poolee = CallPatchedMethods.InstantiatePoolee(pool, spawnLocation.position, spawnLocation.rotation, pool.Prefab.transform.localScale);
|
||||
|
||||
Syncable syncable = MakeOrGetSyncable(poolee);
|
||||
return syncable;
|
||||
}
|
||||
public static void OnRegisterSyncMessage(RegisterSyncableMessage registerSyncableMessage)
|
||||
{
|
||||
@@ -172,6 +190,13 @@ namespace BoneSync.Sync
|
||||
{
|
||||
info.id = GetNextId();
|
||||
new RegisterSyncableMessage(info).Broadcast();
|
||||
} else
|
||||
{
|
||||
if (registerSyncableMessage.senderId != BoneSync.lobby.GetHostId())
|
||||
{
|
||||
MelonLogger.Warning("Received register sync message from non-host: " + registerSyncableMessage.senderId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (info.type)
|
||||
@@ -182,7 +207,7 @@ namespace BoneSync.Sync
|
||||
break;
|
||||
case RegisterSyncType.RegisterAndSpawn:
|
||||
MelonLogger.Msg("Registering and spawning syncable from pool: " + info.spawnInfo.Value.poolName + " with id: " + info.id);
|
||||
syncable = SpawnPooleeAndMakeSyncable(info.spawnInfo.Value.poolName, info);
|
||||
syncable = SpawnPooleeAndMakeSyncable(info);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace BoneSync.Sync
|
||||
|
||||
public static void AddSyncable(Syncable syncable)
|
||||
{
|
||||
string path = syncable.transform.GetPath();
|
||||
string path = syncable.GetSyncableWorldPath();
|
||||
if (path != null && path != "")
|
||||
{
|
||||
_pathToSyncable[path] = syncable;
|
||||
@@ -44,9 +44,10 @@ namespace BoneSync.Sync
|
||||
|
||||
public static void RemoveSyncable(Syncable syncable)
|
||||
{
|
||||
if (syncable.transform)
|
||||
string path = syncable.GetSyncableWorldPath();
|
||||
if (path != null && path != "")
|
||||
{
|
||||
_pathToSyncable.Remove(syncable.transform.GetPath());
|
||||
_pathToSyncable.Remove(path);
|
||||
}
|
||||
if (syncable.GetSyncId() != 0)
|
||||
{
|
||||
@@ -69,13 +70,6 @@ namespace BoneSync.Sync
|
||||
public static void UpdateSyncId(Syncable syncable)
|
||||
{
|
||||
// remove other enties where value is the same
|
||||
foreach (KeyValuePair<ushort, Syncable> entry in _idToSyncable)
|
||||
{
|
||||
if (entry.Value == syncable)
|
||||
{
|
||||
_idToSyncable.Remove(entry.Key);
|
||||
}
|
||||
}
|
||||
ushort id = syncable.GetSyncId();
|
||||
if (_idToSyncable.ContainsKey(id))
|
||||
{
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.TestPlatform.ObjectModel" version="17.12.0" targetFramework="net472" />
|
||||
<package id="MSTest.Analyzers" version="3.8.2" targetFramework="net472" developmentDependency="true" />
|
||||
<package id="MSTest.TestFramework" version="3.8.2" targetFramework="net472" />
|
||||
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net472" />
|
||||
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net472" />
|
||||
<package id="xunit" version="2.9.3" targetFramework="net472" />
|
||||
<package id="xunit.abstractions" version="2.0.3" targetFramework="net472" />
|
||||
<package id="xunit.analyzers" version="1.20.0" targetFramework="net472" developmentDependency="true" />
|
||||
<package id="xunit.assert" version="2.9.3" targetFramework="net472" />
|
||||
<package id="xunit.core" version="2.9.3" targetFramework="net472" />
|
||||
<package id="xunit.extensibility.core" version="2.9.3" targetFramework="net472" />
|
||||
<package id="xunit.extensibility.execution" version="2.9.3" targetFramework="net472" />
|
||||
<package id="xunit.runner.visualstudio" version="3.0.2" targetFramework="net472" developmentDependency="true" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user