Skip to content

Commit

Permalink
Fix when players cannot join the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
DiFFoZ committed Sep 20, 2020
1 parent 6d8626d commit f0d5f78
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dummy/Dummy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<Compile Remove="Commands\Actions\CommandDummyJump.cs" />
<Compile Remove="Patches\Patch_PlayerInput_askInput.cs" />
<Compile Remove="Patches\Patch_PlayerTool_getSteamPlayer.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -31,6 +32,7 @@
<ItemGroup>
<None Include="Commands\Actions\CommandDummyJump.cs" />
<None Include="Patches\Patch_PlayerInput_askInput.cs" />
<None Include="Patches\Patch_PlayerTool_getSteamPlayer.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions Dummy/Patches/Patch_PlayerTool_getSteamPlayer.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion Dummy/Patches/Patch_Provider_receiveServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions Dummy/Providers/DummyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ private async UniTask RemoveRigidBody(PlayerMovement movement)
await UniTask.Delay(1500);
await UniTask.SwitchToMainThread();
UnityEngine.Object.Destroy(movement.GetComponent<Rigidbody>());
movement.controller.Move(Vector3.down);
}

public async Task<bool> RemoveDummyAsync(CSteamID id)
Expand Down
8 changes: 4 additions & 4 deletions Dummy/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SDG.Unturned;
using Steamworks;
using SDG.NetTransport;
using SDG.Unturned;
using System;
using System.Reflection;

Expand All @@ -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()
Expand Down

0 comments on commit f0d5f78

Please sign in to comment.