Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DS2_ReplaceServerAddressHook.cpp #220

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 1 addition & 51 deletions .github/workflows/release.yml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, it was only for running in my GitHub action to test the package, didn't mean to commit this, i will re-add the code

Original file line number Diff line number Diff line change
Expand Up @@ -116,60 +116,10 @@ jobs:
with:
path: ./linux.zip
name: linux

build-docker:
name: Build Docker
runs-on: ubuntu-20.04

steps:
- name: Checkout respository
uses: actions/checkout@v2
with:
submodules: recursive

- name: Generate Solution
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:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- 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:
context: .
file: ./DarkSouls3.Dockerfile
push: true
no-cache: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ds3os:latest

- name: Build and push server docker
uses: docker/build-push-action@v2
with:
context: .
file: ./DarkSouls2.Dockerfile
push: true
no-cache: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ds2os:latest

make-release:
name: Make Release
needs: [ build-windows, build-linux, build-docker ]
needs: [ build-windows, build-linux]
runs-on: ubuntu-20.04

steps:
Expand Down
32 changes: 26 additions & 6 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))
{
continue;
//if i'm not running in wine do the check
if (winePrefix == nullptr) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of coding style issues:

  • braces go on next line
  • comments start with a space and a capital letter
  • variables are in PascalCase not camelCase

Log("you are using windows");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this please, it isn't needed.

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 the programm is running on wine
if(winePrefix != nullptr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if please, also the comment doesn't really add anything, please remove it.

{
continue;
Log("you are using wine");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the log please.

if (VirtualQuery((void*)key, &info, sizeof(info)) == 0) //wine doesn't emulate memory seafe features of windows {il TroncoNinja e' stato qui}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on previous line please - also please stick to english, even if its just a fun tag :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, what does wine actually return for the protection flags? I would expect it to return the same values as windows, as I can see a whole slew of compatibility issues if that wasn't the case.

Copy link
Contributor Author

@TroncoNinja TroncoNinja Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Flags are all correct, as far as my testing goes, the problem is in the info struct, more specifically the changes made in the info.Protect (in windows info.Protect=64, in wine/proton info.Protect = 128). The memory seems to have the PAGE_EXECUTE_WRITECOPY flag instead of PAGE_EXECUTE_READWRITE. the flags for memory safety in linux are different, as far as my research goes, wine has problems(design) translating the flags/translating memory managment

{
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
Loading