-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dfcda7
commit 8147322
Showing
19 changed files
with
185 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Dark Souls 3 - Open Server | ||
* Copyright (C) 2021 Tim Leonard | ||
* | ||
* This program is free software; licensed under the MIT license. | ||
* You should have received a copy of the license along with this program. | ||
* If not, see <https://opensource.org/licenses/MIT>. | ||
*/ | ||
|
||
#include "Injector/Hooks/ReplaceServerPortHook.h" | ||
#include "Injector/Injector/Injector.h" | ||
#include "Shared/Core/Utils/Logging.h" | ||
#include "Shared/Core/Utils/Strings.h" | ||
#include "ThirdParty/detours/src/detours.h" | ||
|
||
#include <vector> | ||
#include <iterator> | ||
#include <WinSock2.h> | ||
|
||
namespace | ||
{ | ||
using connect_p = int(WSAAPI*)(SOCKET s, const sockaddr* name, int namelen); | ||
connect_p s_original_connect; | ||
|
||
int WSAAPI ConnectHook(SOCKET s, const sockaddr* name, int namelen) | ||
{ | ||
sockaddr_in* addr = (sockaddr_in*)name; | ||
|
||
if (addr->sin_port == htons(50050)) | ||
{ | ||
const RuntimeConfig& Config = Injector::Instance().GetConfig(); | ||
|
||
Log("Attempt to connect to login server, patching port to '%i'.", Config.ServerPort); | ||
addr->sin_port = ntohs(Config.ServerPort); | ||
} | ||
|
||
return s_original_connect(s, name, namelen); | ||
} | ||
}; | ||
|
||
bool ReplaceServerPortHook::Install(Injector& injector) | ||
{ | ||
DetourTransactionBegin(); | ||
DetourUpdateThread(GetCurrentThread()); | ||
|
||
s_original_connect = reinterpret_cast<connect_p>(connect); | ||
DetourAttach(&(PVOID&)s_original_connect, ConnectHook); | ||
|
||
DetourTransactionCommit(); | ||
|
||
return true; | ||
} | ||
|
||
void ReplaceServerPortHook::Uninstall() | ||
{ | ||
|
||
} | ||
|
||
const char* ReplaceServerPortHook::GetName() | ||
{ | ||
return "Replace Server Port"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Dark Souls 3 - Open Server | ||
* Copyright (C) 2021 Tim Leonard | ||
* | ||
* This program is free software; licensed under the MIT license. | ||
* You should have received a copy of the license along with this program. | ||
* If not, see <https://opensource.org/licenses/MIT>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Injector/Hooks/Hook.h" | ||
|
||
// Hooks the connection call and swaps out the port number for the one we care about. | ||
class ReplaceServerPortHook : public Hook | ||
{ | ||
public: | ||
virtual bool Install(Injector& injector) override; | ||
virtual void Uninstall() override; | ||
virtual const char* GetName() override; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.