From f0d5f7880949f79f6a289042a271a9c66da92220 Mon Sep 17 00:00:00 2001 From: DiFFoZ <48765566+DiFFoZ@users.noreply.github.com> Date: Sun, 20 Sep 2020 22:34:50 +0700 Subject: [PATCH] Fix when players cannot join the server. --- Dummy/Dummy.csproj | 2 ++ .../Patch_PlayerTool_getSteamPlayer.cs | 24 +++++++++++++++++++ Dummy/Patches/Patch_Provider_receiveServer.cs | 2 +- Dummy/Providers/DummyProvider.cs | 1 + Dummy/Utils.cs | 8 +++---- 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Dummy/Patches/Patch_PlayerTool_getSteamPlayer.cs diff --git a/Dummy/Dummy.csproj b/Dummy/Dummy.csproj index 9771113..aed8f4c 100644 --- a/Dummy/Dummy.csproj +++ b/Dummy/Dummy.csproj @@ -17,6 +17,7 @@ + @@ -31,6 +32,7 @@ + diff --git a/Dummy/Patches/Patch_PlayerTool_getSteamPlayer.cs b/Dummy/Patches/Patch_PlayerTool_getSteamPlayer.cs new file mode 100644 index 0000000..7d4d127 --- /dev/null +++ b/Dummy/Patches/Patch_PlayerTool_getSteamPlayer.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using SDG.Unturned; +using Steamworks; +using System; + +namespace EvolutionPlugins.Dummy.Patches +{ + [HarmonyPatch(typeof(PlayerTool), "getSteamPlayer", new Type[] { typeof(CSteamID) })] + public static class Patch_PlayerTool_getSteamPlayer + { + internal static event NeedDummyProvider OnNeedDummyProvider; + + [HarmonyPostfix] + public static void getSteamPlayer(CSteamID steamID, ref SteamPlayer __result) + { + if (__result != null || OnNeedDummyProvider == null) return; + + if (OnNeedDummyProvider.Invoke().Dummies.TryGetValue(steamID, out var playerDummy)) + { + __result = playerDummy.Data.UnturnedUser.Player.SteamPlayer; + } + } + } +} diff --git a/Dummy/Patches/Patch_Provider_receiveServer.cs b/Dummy/Patches/Patch_Provider_receiveServer.cs index 1f4786b..99108fa 100644 --- a/Dummy/Patches/Patch_Provider_receiveServer.cs +++ b/Dummy/Patches/Patch_Provider_receiveServer.cs @@ -314,7 +314,7 @@ public static bool Prefix(ITransportConnection transportConnection, byte[] packe Provider.reject(/* 3.20.10.0 */ transportConnection, ESteamRejection.PING); return false; } - Utils.notifyClientPending(steamID); + Utils.notifyClientPending(transportConnection); SteamPending item = new SteamPending(/* 3.20.10.0 */ transportConnection, steamPlayerID, (bool)objects[9], (byte)objects[13], (byte)objects[14], (byte)objects[15], (Color)objects[16], (Color)objects[17], (Color)objects[18], (bool)objects[19], (ulong)objects[20], (ulong)objects[21], (ulong)objects[22], (ulong)objects[23], diff --git a/Dummy/Providers/DummyProvider.cs b/Dummy/Providers/DummyProvider.cs index 4c767e2..3306358 100644 --- a/Dummy/Providers/DummyProvider.cs +++ b/Dummy/Providers/DummyProvider.cs @@ -236,6 +236,7 @@ private async UniTask RemoveRigidBody(PlayerMovement movement) await UniTask.Delay(1500); await UniTask.SwitchToMainThread(); UnityEngine.Object.Destroy(movement.GetComponent()); + movement.controller.Move(Vector3.down); } public async Task RemoveDummyAsync(CSteamID id) diff --git a/Dummy/Utils.cs b/Dummy/Utils.cs index a2501cb..f4c9eed 100644 --- a/Dummy/Utils.cs +++ b/Dummy/Utils.cs @@ -1,5 +1,5 @@ -using SDG.Unturned; -using Steamworks; +using SDG.NetTransport; +using SDG.Unturned; using System; using System.Reflection; @@ -24,10 +24,10 @@ public static void checkBanStatus(SteamPlayerID playerID, uint remoteIP, out boo banRemainingDuration = (uint)parameters[4]; } - public static void notifyClientPending(CSteamID remoteSteamID) + public static void notifyClientPending(ITransportConnection transportConnection) { var dynMethod = typeof(Provider).GetMethod("notifyClientPending", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); - dynMethod.Invoke(typeof(Provider), new object[] { remoteSteamID }); + dynMethod.Invoke(typeof(Provider), new[] { transportConnection }); } public static void verifyNextPlayerInQueue()