forked from crosire/reshade
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathws2_32.cpp
More file actions
126 lines (96 loc) · 4.16 KB
/
Copy pathws2_32.cpp
File metadata and controls
126 lines (96 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Copyright (C) 2014 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/reshade#license
*/
#include "hook_manager.hpp"
#include <Windows.h>
#include <Winsock2.h>
volatile long g_network_traffic = 0;
HOOK_EXPORT int WSAAPI HookWSASend(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent, DWORD dwFlags, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
static const auto trampoline = reshade::hooks::call(&HookWSASend);
for (DWORD i = 0; i < dwBufferCount; ++i)
{
InterlockedAdd(&g_network_traffic, lpBuffers[i].len);
}
return trampoline(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine);
}
HOOK_EXPORT int WSAAPI HookWSASendTo(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent, DWORD dwFlags, const struct sockaddr *lpTo, int iToLen, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
static const auto trampoline = reshade::hooks::call(&HookWSASendTo);
for (DWORD i = 0; i < dwBufferCount; ++i)
{
InterlockedAdd(&g_network_traffic, lpBuffers[i].len);
}
return trampoline(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpTo, iToLen, lpOverlapped, lpCompletionRoutine);
}
HOOK_EXPORT int WSAAPI HookWSARecv(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd, LPDWORD lpFlags, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
static const auto trampoline = reshade::hooks::call(&HookWSARecv);
const auto status = trampoline(s, lpBuffers, dwBufferCount, lpNumberOfBytesRecvd, lpFlags, lpOverlapped, lpCompletionRoutine);
if (status == 0 && lpNumberOfBytesRecvd != nullptr)
{
InterlockedAdd(&g_network_traffic, *lpNumberOfBytesRecvd);
}
return status;
}
HOOK_EXPORT int WSAAPI HookWSARecvEx(SOCKET s, char *buf, int len, int *flags)
{
static const auto trampoline = reshade::hooks::call(&HookWSARecvEx);
const int recieved = trampoline(s, buf, len, flags);
if (recieved > 0)
{
InterlockedAdd(&g_network_traffic, recieved);
}
return recieved;
}
HOOK_EXPORT int WSAAPI HookWSARecvFrom(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd, LPDWORD lpFlags, struct sockaddr *lpFrom, LPINT lpFromlen, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
static const auto trampoline = reshade::hooks::call(&HookWSARecvFrom);
const auto status = trampoline(s, lpBuffers, dwBufferCount, lpNumberOfBytesRecvd, lpFlags, lpFrom, lpFromlen, lpOverlapped, lpCompletionRoutine);
if (status == 0 && lpNumberOfBytesRecvd != nullptr)
{
InterlockedAdd(&g_network_traffic, *lpNumberOfBytesRecvd);
}
return status;
}
HOOK_EXPORT int WSAAPI HookSend(SOCKET s, const char *buf, int len, int flags)
{
static const auto trampoline = reshade::hooks::call(&HookSend);
const auto num_bytes_send = trampoline(s, buf, len, flags);
if (num_bytes_send != SOCKET_ERROR)
{
InterlockedAdd(&g_network_traffic, num_bytes_send);
}
return num_bytes_send;
}
HOOK_EXPORT int WSAAPI HookSendTo(SOCKET s, const char *buf, int len, int flags, const struct sockaddr *to, int tolen)
{
static const auto trampoline = reshade::hooks::call(&HookSendTo);
const auto num_bytes_send = trampoline(s, buf, len, flags, to, tolen);
if (num_bytes_send != SOCKET_ERROR)
{
InterlockedAdd(&g_network_traffic, num_bytes_send);
}
return num_bytes_send;
}
HOOK_EXPORT int WSAAPI HookRecv(SOCKET s, char *buf, int len, int flags)
{
static const auto trampoline = reshade::hooks::call(&HookRecv);
const auto num_bytes_recieved = trampoline(s, buf, len, flags);
if (num_bytes_recieved != SOCKET_ERROR)
{
InterlockedAdd(&g_network_traffic, num_bytes_recieved);
}
return num_bytes_recieved;
}
HOOK_EXPORT int WSAAPI HookRecvFrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen)
{
static const auto trampoline = reshade::hooks::call(&HookRecvFrom);
const auto num_bytes_recieved = trampoline(s, buf, len, flags, from, fromlen);
if (num_bytes_recieved != SOCKET_ERROR)
{
InterlockedAdd(&g_network_traffic, num_bytes_recieved);
}
return num_bytes_recieved;
}