Hook changes

This commit is contained in:
Raymond 2021-08-02 09:15:46 -04:00
parent 64065abc9d
commit 42be18965d
8 changed files with 472 additions and 109 deletions

View file

@ -3,8 +3,9 @@ using System.Net.Sockets;
using System.Runtime.InteropServices;
using Dalamud.Hooking;
using Dalamud.Hooking.Internal;
namespace Dalamud.Game
namespace Dalamud.Game.Network.Internal
{
/// <summary>
/// This class enables TCP optimizations in the game socket for better performance.
@ -18,8 +19,9 @@ namespace Dalamud.Game
/// </summary>
public WinSockHandlers()
{
this.ws2SocketHook = Hook<SocketDelegate>.FromSymbol("ws2_32.dll", "socket", new SocketDelegate(this.OnSocket));
this.ws2SocketHook.Enable();
this.ws2SocketHook = HookManager.DirtyLinuxUser ? null
: Hook<SocketDelegate>.FromSymbol("ws2_32.dll", "socket", this.OnSocket);
this.ws2SocketHook?.Enable();
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
@ -30,7 +32,7 @@ namespace Dalamud.Game
/// </summary>
public void Dispose()
{
this.ws2SocketHook.Dispose();
this.ws2SocketHook?.Dispose();
}
private IntPtr OnSocket(int af, int type, int protocol)
@ -47,11 +49,11 @@ namespace Dalamud.Game
// https://linux.die.net/man/7/tcp
// https://assets.extrahop.com/whitepapers/TCP-Optimization-Guide-by-ExtraHop.pdf
var value = new IntPtr(1);
NativeFunctions.SetSockOpt(socket, SocketOptionLevel.Tcp, SocketOptionName.NoDelay, ref value, 4);
_ = NativeFunctions.SetSockOpt(socket, SocketOptionLevel.Tcp, SocketOptionName.NoDelay, ref value, 4);
// Enable tcp_quickack option. This option is undocumented in MSDN but it is supported in Windows 7 and onwards.
value = new IntPtr(1);
NativeFunctions.SetSockOpt(socket, SocketOptionLevel.Tcp, SocketOptionName.AddMembership, ref value, 4);
_ = NativeFunctions.SetSockOpt(socket, SocketOptionLevel.Tcp, SocketOptionName.AddMembership, ref value, 4);
}
}