mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge branch 'master' of github.com:goaaats/Dalamud
This commit is contained in:
commit
e54c405f5c
6 changed files with 78 additions and 13 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup Label="Target">
|
<PropertyGroup Label="Target">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<TargetFramework>net471</TargetFramework>
|
<TargetFramework>net48</TargetFramework>
|
||||||
<LangVersion>7.2</LangVersion>
|
<LangVersion>8.0</LangVersion>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Label="Build">
|
<PropertyGroup Label="Build">
|
||||||
|
|
@ -26,4 +26,4 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Dalamud\Dalamud.csproj" />
|
<ProjectReference Include="..\Dalamud\Dalamud.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ namespace Dalamud {
|
||||||
|
|
||||||
public readonly DalamudConfiguration Configuration;
|
public readonly DalamudConfiguration Configuration;
|
||||||
|
|
||||||
|
internal readonly WinSockHandlers WinSock2;
|
||||||
|
|
||||||
public Dalamud(DalamudStartInfo info) {
|
public Dalamud(DalamudStartInfo info) {
|
||||||
this.StartInfo = info;
|
this.StartInfo = info;
|
||||||
this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);
|
this.Configuration = DalamudConfiguration.Load(info.ConfigurationPath);
|
||||||
|
|
@ -75,7 +77,9 @@ namespace Dalamud {
|
||||||
this.PluginManager = new PluginManager(this, info.PluginDirectory, info.DefaultPluginDirectory);
|
this.PluginManager = new PluginManager(this, info.PluginDirectory, info.DefaultPluginDirectory);
|
||||||
|
|
||||||
this.IconReplacer = new IconReplacer(this, this.sigScanner);
|
this.IconReplacer = new IconReplacer(this, this.sigScanner);
|
||||||
|
|
||||||
|
this.WinSock2 = new WinSockHandlers();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.PluginManager.LoadPlugins();
|
this.PluginManager.LoadPlugins();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
@ -109,6 +113,8 @@ namespace Dalamud {
|
||||||
|
|
||||||
this.unloadSignal.Dispose();
|
this.unloadSignal.Dispose();
|
||||||
|
|
||||||
|
this.WinSock2.Dispose();
|
||||||
|
|
||||||
if (this.Configuration.ComboPresets != CustomComboPreset.None)
|
if (this.Configuration.ComboPresets != CustomComboPreset.None)
|
||||||
this.IconReplacer.Dispose();
|
this.IconReplacer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup Label="Target">
|
<PropertyGroup Label="Target">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<TargetFramework>net471</TargetFramework>
|
<TargetFramework>net48</TargetFramework>
|
||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>8.0</LangVersion>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Label="Build">
|
<PropertyGroup Label="Build">
|
||||||
|
|
@ -68,4 +68,4 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Configuration\" />
|
<Folder Include="Configuration\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ using Serilog;
|
||||||
namespace Dalamud.Game.Internal.Gui {
|
namespace Dalamud.Game.Internal.Gui {
|
||||||
public sealed class ChatGui : IDisposable {
|
public sealed class ChatGui : IDisposable {
|
||||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||||
private delegate void PrintMessageDelegate(IntPtr manager, XivChatType chatType, IntPtr senderName,
|
private delegate IntPtr PrintMessageDelegate(IntPtr manager, XivChatType chatType, IntPtr senderName,
|
||||||
IntPtr message,
|
IntPtr message,
|
||||||
uint senderId, IntPtr parameter);
|
uint senderId, IntPtr parameter);
|
||||||
|
|
||||||
|
|
@ -79,8 +79,10 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandlePrintMessageDetour(IntPtr manager, XivChatType chattype, IntPtr pSenderName, IntPtr pMessage,
|
private IntPtr HandlePrintMessageDetour(IntPtr manager, XivChatType chattype, IntPtr pSenderName, IntPtr pMessage,
|
||||||
uint senderid, IntPtr parameter) {
|
uint senderid, IntPtr parameter) {
|
||||||
|
IntPtr retVal = IntPtr.Zero;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var senderName = StdString.ReadFromPointer(pSenderName);
|
var senderName = StdString.ReadFromPointer(pSenderName);
|
||||||
var message = StdString.ReadFromPointer(pMessage);
|
var message = StdString.ReadFromPointer(pMessage);
|
||||||
|
|
@ -105,7 +107,7 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
|
|
||||||
// Print the original chat if it's handled.
|
// Print the original chat if it's handled.
|
||||||
if (!isHandled)
|
if (!isHandled)
|
||||||
this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter);
|
retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter);
|
||||||
|
|
||||||
if (this.baseAddress == IntPtr.Zero)
|
if (this.baseAddress == IntPtr.Zero)
|
||||||
this.baseAddress = manager;
|
this.baseAddress = manager;
|
||||||
|
|
@ -113,8 +115,10 @@ namespace Dalamud.Game.Internal.Gui {
|
||||||
allocatedString?.Dispose();
|
allocatedString?.Dispose();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.Error(ex, "Exception on OnChatMessage hook.");
|
Log.Error(ex, "Exception on OnChatMessage hook.");
|
||||||
this.printMessageHook.Original(manager, chattype, pSenderName, pMessage, senderid, parameter);
|
retVal = this.printMessageHook.Original(manager, chattype, pSenderName, pMessage, senderid, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
55
Dalamud/Game/Network/WinSockHandlers.cs
Normal file
55
Dalamud/Game/Network/WinSockHandlers.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
using Dalamud.Hooking;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Dalamud.Game
|
||||||
|
{
|
||||||
|
internal sealed class WinSockHandlers : IDisposable
|
||||||
|
{
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||||
|
private delegate IntPtr SocketDelegate(int af, int type, int protocol);
|
||||||
|
private Hook<SocketDelegate> ws2SocketHook;
|
||||||
|
|
||||||
|
[DllImport("ws2_32.dll", CallingConvention = CallingConvention.Winapi)]
|
||||||
|
private static extern int setsockopt(IntPtr socket, SocketOptionLevel level, SocketOptionName optName, ref IntPtr optVal, int optLen);
|
||||||
|
|
||||||
|
public WinSockHandlers() {
|
||||||
|
ws2SocketHook = Hook<SocketDelegate>.FromSymbol("ws2_32.dll", "socket", new SocketDelegate(OnSocket));
|
||||||
|
ws2SocketHook.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IntPtr OnSocket(int af, int type, int protocol)
|
||||||
|
{
|
||||||
|
var socket = ws2SocketHook.Original(af, type, protocol);
|
||||||
|
|
||||||
|
// IPPROTO_TCP
|
||||||
|
if (type == 1)
|
||||||
|
{
|
||||||
|
// INVALID_SOCKET
|
||||||
|
if (socket != new IntPtr(-1))
|
||||||
|
{
|
||||||
|
// In case you're not aware of it: (albeit you should)
|
||||||
|
// https://linux.die.net/man/7/tcp
|
||||||
|
// https://assets.extrahop.com/whitepapers/TCP-Optimization-Guide-by-ExtraHop.pdf
|
||||||
|
var value = new IntPtr(1);
|
||||||
|
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);
|
||||||
|
setsockopt(socket, SocketOptionLevel.Tcp, (SocketOptionName)12, ref value, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
ws2SocketHook.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using EasyHook;
|
using EasyHook;
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Dalamud.Hooking {
|
||||||
/// This class is basically a thin wrapper around the LocalHook type to provide helper functions.
|
/// This class is basically a thin wrapper around the LocalHook type to provide helper functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Delegate type to represents a function prototype. This must be the same prototype as original function do.</typeparam>
|
/// <typeparam name="T">Delegate type to represents a function prototype. This must be the same prototype as original function do.</typeparam>
|
||||||
public sealed class Hook<T> : IDisposable where T : class {
|
public sealed class Hook<T> : IDisposable where T : Delegate {
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
|
|
||||||
private readonly IntPtr address;
|
private readonly IntPtr address;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue