Skip to content

Commit

Permalink
Merge pull request #220 from TroncoNinja/main
Browse files Browse the repository at this point in the history
Update DS2_ReplaceServerAddressHook.cpp
  • Loading branch information
TLeonardUK authored Jul 23, 2024
2 parents df53f99 + f2a8f94 commit d28fb82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
with:
path: ./linux.zip
name: linux

build-docker:
name: Build Docker
runs-on: ubuntu-20.04
Expand All @@ -131,7 +131,7 @@ jobs:
shell: bash
working-directory: ${{github.workspace}}/Tools
run: ${{github.workspace}}/Tools/generate_make_release.sh

- name: Login to DockerHub
uses: docker/login-action@v1
with:
Expand All @@ -140,15 +140,15 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push master-server docker
uses: docker/build-push-action@v2
with:
context: ./Source/MasterServer/
file: ./Source/MasterServer/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ds3os-master:latest

- name: Build and push server docker
uses: docker/build-push-action@v2
with:
Expand All @@ -157,7 +157,7 @@ jobs:
push: true
no-cache: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ds3os:latest

- name: Build and push server docker
uses: docker/build-push-action@v2
with:
Expand All @@ -166,7 +166,7 @@ jobs:
push: true
no-cache: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ds2os:latest

make-release:
name: Make Release
needs: [ build-windows, build-linux, build-docker ]
Expand Down
30 changes: 25 additions & 5 deletions Source/Injector/Hooks/DarkSouls2/DS2_ReplaceServerAddressHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ bool DS2_ReplaceServerAddressHook::PatchHostname(Injector& injector)
std::wstring WideHostname = WidenString(Config.ServerHostname);
size_t CopyLength = (WideHostname.size() + 1) * 2;

char* WinePrefix = std::getenv("WINEPREFIX");

while (true)
{
std::vector<intptr_t> address_matches = injector.SearchString({
Expand All @@ -46,9 +48,13 @@ bool DS2_ReplaceServerAddressHook::PatchHostname(Injector& injector)
{
continue;
}
if (((info.Protect & PAGE_READWRITE) == 0 && (info.Protect & PAGE_EXECUTE_READWRITE) == 0))

if (WinePrefix == nullptr)
{
continue;
if (((info.Protect & PAGE_READWRITE) == 0 && (info.Protect & PAGE_EXECUTE_READWRITE) == 0))
{
continue;
}
}

wchar_t* ptr = (wchar_t*)key;
Expand Down Expand Up @@ -77,6 +83,8 @@ bool DS2_ReplaceServerAddressHook::PatchHostname(Injector& injector)

bool DS2_ReplaceServerAddressHook::PatchKey(Injector& injector)
{
char* WinePrefix = std::getenv("WINEPREFIX");

while (true)
{
const RuntimeConfig& Config = Injector::Instance().GetConfig();
Expand All @@ -99,10 +107,22 @@ bool DS2_ReplaceServerAddressHook::PatchKey(Injector& injector)
{
// If the memory is not writable yet, modify its protection (steam drm fucks with the protection during boot).
MEMORY_BASIC_INFORMATION info;
if (VirtualQuery((void*)key, &info, sizeof(info)) == 0 ||
((info.Protect & PAGE_READWRITE) == 0 && (info.Protect & PAGE_EXECUTE_READWRITE) == 0))

if (WinePrefix != nullptr)
{
continue;
// Do the check because Wine doesn't emulate memory seafe features of Windows
if (VirtualQuery((void*)key, &info, sizeof(info)) == 0)
{
continue;
}
}
else
{
if (VirtualQuery((void*)key, &info, sizeof(info)) == 0 ||
((info.Protect & PAGE_READWRITE) == 0 && (info.Protect & PAGE_EXECUTE_READWRITE) == 0))
{
continue;
}
}

memcpy((char*)key, Config.ServerPublicKey.c_str(), CopyLength);
Expand Down

0 comments on commit d28fb82

Please sign in to comment.