Nordgaren / Elden-Ring-Debug-Tool

Debug tool for Elden Ring modding
GNU General Public License v3.0
108 stars 18 forks source link

Cannot hook process on linux (solution proposal inside) #65

Open daniele-bondi opened 1 week ago

daniele-bondi commented 1 week ago

Running the tool via wine works (I can interact with the window) but the elden ring process cannot be found. Looking through the code I traced the issue back to this line:

Hook = new ErdHook(5000, 1000, p => p.MainWindowTitle is "ELDEN RING™" or "ELDEN RING");

On linux, Process.MainWindowTitle always returns an empty string.

If you have a linux system, you can test it with the following simple program

```csharp using System.Diagnostics; internal class Program { private static void Main(string[] args) { foreach (var proc in Process.GetProcesses()) Console.WriteLine($"{proc.ProcessName} : {proc.MainWindowTitle}"); } } ```


I would like to ask to add some other criterion to detect the process. I would suggest to replace the processSelector argument with something like this

        public MainWindowViewModel()
        {
            static bool ProcessSelector(Process process)
            {
                if (string.Equals(process.MainWindowTitle, "ELDEN RING™", StringComparison.OrdinalIgnoreCase))
                    return true;
                if (string.Equals(process.MainWindowTitle, "ELDEN RING", StringComparison.OrdinalIgnoreCase))
                    return true;
                // For linux compatibility, since Process.MainWindowTitle always returns an empty string on linux.
                if (string.Equals(process.ProcessName, "eldenring.exe", StringComparison.OrdinalIgnoreCase))
                    return true;
                return false;
            }

            Hook = new ErdHook(5000, 1000, ProcessSelector);
            Hook.OnSetup += Hook_OnSetup;
            ...

I cannot test the change on my own because I cannot build a project targeting a windows-specific framework on linux, and I don't have a windows computer available. However, I checked that Process.ProcessName does in fact return the string "eldenring.exe".

Alternatively, some manner of manual process selection would be fine too. Maybe clicking the "Not Hooked" status message brings up a process listing where you can select the PID to hook, or a numeric field where you can enter the PID directly.

Nano-Ocelot commented 4 days ago

Perhaps a "Linux testing branch" and pull request could be created to easily allow someone else to test this change?

daniele-bondi commented 4 days ago

I can make a PR, but it feels a bit silly when I can't even build it. Also I'm not sure that this is the only thing that's stopping the tool from working on linux, so a PR just for this could end up being pointless.

Nano-Ocelot commented 4 days ago

If I get time this week I can try to build and test it. I still have windows installed. I just don't know how to make the change you mentioned here. Did you just replace that line 47 with your code mentioned above?

daniele-bondi commented 4 days ago

That's correct.

SirGFM commented 1 day ago

I was able to cross compile the tool from Linux, but those changes weren't enough to make it hook to the game process.

I ran into a few issues while trying to build the tool and its dependencies, so I had to make a few minor changes to their configurations/imports. You'll need these patches to be able to build everything successfully:

Here's how I got to build the tool:

  1. Clone and initialize the repository
git clone https://github.com/Nordgaren/Elden-Ring-Debug-Tool
cd Elden-Ring-Debug-Tool
git submodule update --init --recursive
  1. Fix building on Linux:
git apply <Elden-Ring-Debug-Tool.patch>
cd src/Erd-Tools/
git apply <Erd-Tools.patch>
cd src/PropertyHook/
git apply <PropertyHook.patch>
cd ../../../../
  1. Build it using Microsoft's .NET docker image:
docker pull mcr.microsoft.com/dotnet/sdk:6.0
docker run --rm -ti -v `pwd`:/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 bash

# Inside the container

# install .NET Frameworkd v4.6.1
apt-get update && apt-get -y install nuget
nuget install Microsoft.NETFramework.ReferenceAssemblies.net461

# Build the tool
dotnet publish '.\src\Elden-Ring-Debug-Tool-WPF\Elden-Ring-Debug-Tool-WPF.csproj' -c Release /p:PublishProfile=FolderProfile

# The tool will be in src/Elden-Ring-Debug-Tool-WPF/bin/Publish/win-x64/

After doing all that, I tested the application and checked that it was opening, and only then I applied @daniele-bondi's changes... However, as I mentioned earlier, it didn't solve the issue for me.