Skip to content

Commit f12b0d3

Browse files
committed
Renamed dns_result and transport_dns functions
Hooked `transport_get_loopback_address`
1 parent 308ee84 commit f12b0d3

File tree

2 files changed

+101
-21
lines changed

2 files changed

+101
-21
lines changed

game/source/networking/transport/transport_address.cpp

Lines changed: 92 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
#include "cseries/cseries_events.hpp"
44
#include "game/players.hpp"
5+
#include "memory/byte_swapping.hpp"
56
#include "memory/module.hpp"
7+
#include "networking/transport/transport.hpp"
68
#include "networking/transport/transport_security.hpp"
79

810
#include <string.h>
11+
//#include <WinSock2.h>
912

1013
HOOK_DECLARE(0x0043F660, transport_address_equivalent);
1114
HOOK_DECLARE(0x0043F6F0, transport_address_get_string);
@@ -15,6 +18,7 @@ HOOK_DECLARE(0x0043F750, transport_address_to_string);
1518
HOOK_DECLARE(0x0043F860, transport_address_valid);
1619
HOOK_DECLARE(0x0043F8D0, transport_get_broadcast_address);
1720
HOOK_DECLARE(0x0043F8F0, transport_get_listen_address);
21+
HOOK_DECLARE(0x0043F910, transport_get_loopback_address);
1822

1923
transport_address::transport_address() :
2024
ipv4_address(0),
@@ -43,8 +47,78 @@ transport_address::transport_address(s_player_identifier const* player_identifie
4347
address_length = sizeof(uint32);
4448
}
4549

50+
bool __cdecl transport_dns_address_to_name(dns_result* result)
51+
{
52+
return INVOKE(0x0043B330, transport_dns_address_to_name, result);
53+
54+
//if (!transport_available())
55+
// return false;
56+
//
57+
//ASSERT(result != NULL);
58+
//
59+
//transport_address* address = &result->address[0];
60+
//
61+
//union
62+
//{
63+
// uint32 ipv4_address;
64+
// uint16 ipv6_address[8];
65+
//} ip_address;
66+
//
67+
//int32 type = 0;
68+
//int32 address_length = 0;
69+
//switch (address->address_length)
70+
//{
71+
//case 4:
72+
//{
73+
// type = AF_INET;
74+
// address_length = 4;
75+
//
76+
// ip_address.ipv4_address = bswap_uint32(result->address[0].ipv4_address);
77+
//}
78+
//break;
79+
//case 16:
80+
//{
81+
// type = AF_INET6;
82+
// address_length = 16;
83+
//
84+
// ip_address.ipv6_address[0] = bswap_uint16(address->ina6.words[0]);
85+
// ip_address.ipv6_address[1] = bswap_uint16(address->ina6.words[1]);
86+
// ip_address.ipv6_address[2] = bswap_uint16(address->ina6.words[2]);
87+
// ip_address.ipv6_address[3] = bswap_uint16(address->ina6.words[3]);
88+
// ip_address.ipv6_address[4] = bswap_uint16(address->ina6.words[4]);
89+
// ip_address.ipv6_address[5] = bswap_uint16(address->ina6.words[5]);
90+
// ip_address.ipv6_address[6] = bswap_uint16(address->ina6.words[6]);
91+
// ip_address.ipv6_address[7] = bswap_uint16(address->ina6.words[7]);
92+
//}
93+
//break;
94+
//default:
95+
//{
96+
// event(_event_error, "networking:transport:dns: reverse dns failed: bad address type");
97+
// return false;
98+
//}
99+
//break;
100+
//}
101+
//
102+
//hostent* host = gethostbyaddr((const char*)&ip_address, address_length, type);
103+
//if (!host || !*host->h_aliases)
104+
//{
105+
// return false;
106+
//}
107+
//
108+
//csstrnzcpy(result->name, *host->h_aliases, sizeof(result->name));
109+
//result->name[255] = 0;
110+
//return true;
111+
}
112+
113+
bool __cdecl transport_dns_name_to_address(dns_result* result)
114+
{
115+
return INVOKE(0x0043B460, transport_dns_name_to_address, result);
116+
}
117+
46118
bool __cdecl transport_address_equivalent(transport_address const* a, transport_address const* b)
47119
{
120+
//return INVOKE(0x0043F660, transport_address_equivalent, a, b);
121+
48122
ASSERT(a != NULL);
49123
ASSERT(b != NULL);
50124

@@ -73,13 +147,17 @@ void __cdecl transport_address_ipv4_build(transport_address* address, uint32 ip_
73147

74148
uint32 __cdecl transport_address_ipv4_extract(transport_address const* address)
75149
{
150+
//return INVOKE(0x0043F720, transport_address_ipv4_extract, address);
151+
76152
ASSERT(address);
77153

78154
return address->ipv4_address;
79155
}
80156

81157
bool __cdecl transport_address_is_loopback(transport_address const* address)
82158
{
159+
//return INVOKE(0x0043F730, transport_address_is_loopback, address);
160+
83161
ASSERT(address);
84162

85163
return address->address_length == sizeof(uint32) && address->ipv4_address == 0x7F000001;
@@ -164,6 +242,8 @@ char* __cdecl transport_address_to_string(transport_address const* address, s_tr
164242

165243
bool __cdecl transport_address_valid(transport_address const* address)
166244
{
245+
//return INVOKE(0x0043F860, transport_address_valid, address);
246+
167247
bool result = false;
168248
if (address)
169249
{
@@ -203,6 +283,8 @@ bool __cdecl transport_address_valid(transport_address const* address)
203283

204284
void __cdecl transport_get_broadcast_address(transport_address* address, uint16 port)
205285
{
286+
//INVOKE(0x0043F8D0, transport_get_broadcast_address, address, port);
287+
206288
ASSERT(address);
207289

208290
address->address_length = sizeof(uint32);
@@ -212,6 +294,8 @@ void __cdecl transport_get_broadcast_address(transport_address* address, uint16
212294

213295
void __cdecl transport_get_listen_address(transport_address* address, uint16 port)
214296
{
297+
//INVOKE(0x0043F8F0, transport_get_listen_address, address, port);
298+
215299
ASSERT(address);
216300

217301
address->address_length = sizeof(uint32);
@@ -221,6 +305,8 @@ void __cdecl transport_get_listen_address(transport_address* address, uint16 por
221305

222306
void __cdecl transport_get_loopback_address(transport_address* address, uint16 port)
223307
{
308+
//INVOKE(0x0043F910, transport_get_loopback_address, address, port);
309+
224310
ASSERT(address);
225311

226312
address->address_length = sizeof(uint32);
@@ -256,26 +342,13 @@ void transport_address_from_string(char const* str, transport_address& address)
256342
}
257343
}
258344

259-
struct s_transport_address_list
345+
void transport_address_from_host(char const* name, transport_address& address)
260346
{
261-
transport_address addresses[8];
262-
union
347+
dns_result result{};
348+
csstrnzcpy(result.name, name, sizeof(result.name));
349+
if (transport_dns_name_to_address(&result))
263350
{
264-
char hostname[256];
265-
c_static_string<256> host;
266-
};
267-
};
268-
269-
bool __cdecl sub_43B460(s_transport_address_list* list)
270-
{
271-
return INVOKE(0x0043B460, sub_43B460, list);
272-
}
273-
274-
void transport_address_from_host(char const* hostname, transport_address& address)
275-
{
276-
s_transport_address_list list{};
277-
list.host.set(hostname);
278-
if (sub_43B460(&list))
279-
address = list.addresses[0];
351+
address = result.address[0];
352+
}
280353
}
281354

game/source/networking/transport/transport_address.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "cseries/cseries.hpp"
44

55
struct s_player_identifier;
6+
struct s_transport_secure_address;
7+
68
struct transport_address
79
{
810
transport_address();
@@ -38,7 +40,12 @@ struct transport_address
3840
};
3941
static_assert(sizeof(transport_address) == 0x14);
4042

41-
struct s_transport_secure_address;
43+
struct dns_result
44+
{
45+
transport_address address[8];
46+
char name[256];
47+
};
48+
static_assert(sizeof(dns_result) == 0x1A0);
4249

4350
extern bool __cdecl transport_address_equivalent(transport_address const* a, transport_address const* b);
4451
extern char const* __cdecl transport_address_get_string(transport_address const* address);
@@ -53,5 +60,5 @@ extern void __cdecl transport_get_loopback_address(transport_address* address, u
5360

5461
extern void transport_address_from_string(wchar_t const* str, transport_address& address);
5562
extern void transport_address_from_string(char const* str, transport_address& address);
56-
extern void transport_address_from_host(char const* hostname, transport_address& address);
63+
extern void transport_address_from_host(char const* name, transport_address& address);
5764

0 commit comments

Comments
 (0)