dnSpyEx / dnSpy

Unofficial revival of the well known .NET debugger and assembly editor, dnSpy
GNU General Public License v3.0
7.02k stars 462 forks source link

Support custom environment variables #312

Closed Eiim closed 7 months ago

Eiim commented 7 months ago

Problem Description

Steam passes environment variables to games. For example, when I run Human Fall Flat, the executable has these (among other) variables to it:

SteamAppId  477160
SteamAppUser    esc_20
SteamClientLaunch   1
SteamEnv    1
SteamGameId 477160
SteamOverlayGameId  477160
SteamPath   C:\Program Files (x86)\Steam
SteamStreamingHardwareEncodingAMD   1
SteamStreamingHardwareEncodingIntel 1
SteamStreamingHardwareEncodingNVIDIA    1

Some games rely on these variables to work properly, especially online functionality.

Proposal

It would be helpful, if, when running Debug Program, a list of environment variables could be passed, similar to how custom arguments can currently be passed.

Alternatives

A debug build can be created for Unity games, and then a debug build run via Steam can be connected to.

Additional Context

No response

ElektroKill commented 7 months ago

Please let me know if the changes proposed in https://github.com/dnSpyEx/dnSpy/pull/320 solve your problem!

Eiim commented 7 months ago

That looks great! One issue that prevents me from more thoroughly testing it: when I build dnSpy, the 32-bit version doesn't even have a debug menu, or a few other features. Am I using the wrong executable, or is there something weird with the build process, or something? image

ElektroKill commented 7 months ago

That looks great! One issue that prevents me from more thoroughly testing it: when I build dnSpy, the 32-bit version doesn't even have a debug menu, or a few other features. Am I using the wrong executable, or is there something weird with the build process, or something? image

You need to build the entire solution when using Visual Studio with default settings. Clicking the run/debug button in VS will only build dnSpy main project and all direct references. This is problematic as dnSpy does not use direct references for components like the debugger or decompiler.

If you use Rider the build solution workaround will work but you can also do this automatically by editing the run configuration like so: image

Hope this helps!

Eiim commented 7 months ago

I'm not using Visual Studio or Rider, I don't even have either installed, I just ran ./build.ps1 -NoMsbuild per the README instructions.

ElektroKill commented 7 months ago

I'm not using Visual Studio or Rider, I don't even have either installed, I just ran ./build.ps1 -NoMsbuild per the README instructions.

Oh that' interesting. It should work as the CI uses this exact script and it produces correct artifacts. Does the build log contain any errors or warnings?

Eiim commented 7 months ago

There are a few... in the "Building .NET x64 binaries MSBuild version 17.9.8+b34f75857 for .NET" section, there's a few access errors like this:

C:\Program Files\dotnet\sdk\8.0.204\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(351,5): warning MSB3026: Could not copy "C:\Users\ethan\.nuget\packages\microsoft.windowsdesktop.app.runtime.win-x64\8.0.4\runtimes\win-x64\lib\net8.0\System.Drawing.Common.dll" to "..\dnSpy\bin\Release\net8.0-windows\win-x64\publish\System.Drawing.Common.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\System.Drawing.Common.dll' because it is being used by another process.  [C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy.Console\dnSpy.Console.csproj::TargetFramework=net8.0-windows]
C:\Program Files\dotnet\sdk\8.0.204\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(351,5): warning MSB3026: Could not copy "C:\Users\ethan\.nuget\packages\microsoft.windowsdesktop.app.runtime.win-x64\8.0.4\runtimes\win-x64\lib\net8.0\System.Diagnostics.PerformanceCounter.dll" to "..\..\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\System.Diagnostics.PerformanceCounter.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\System.Diagnostics.PerformanceCounter.dll' because it is being used by another process. [C:\Users\ethan\Documents\GitHub\dnSpy\Extensions\dnSpy.Analyzer\dnSpy.Analyzer.csproj::TargetFramework=net8.0-windows]
ElektroKill commented 7 months ago

C:\Program Files\dotnet\sdk\8.0.204\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(351,5): warning MSB3026: Could not copy "C:\Users\ethan.nuget\packages\microsoft.windowsdesktop.app.runtime.win-x64\8.0.4\runtimes\win-x64\lib\net8.0\System.Diagnostics.PerformanceCounter.dll" to "....\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\System.Diagnostics.PerformanceCounter.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\System.Diagnostics.PerformanceCounter.dll' because it is being used by another process. [C:\Users\ethan\Documents\GitHub\dnSpy\Extensions\dnSpy.Analyzer\dnSpy.Analyzer.csproj::TargetFramework=net8.0-windows]

The files appear to be locked by a different process. Are you sure you do not have an instance of dnSpy running form the output directory already or that any sort of other software is accessing said files?

Eiim commented 7 months ago

There definitely wasn't any other dnSpys running. I had a cmd in the root dnSpy directory but that shouldn't affect anything. To be sure, I rebuilt with that window closed to no luck. I'm still not certain exactly which executable I should be running, as best as I can tell there's about eight of them built. However, any dnSpy-x86.exe seems to simply not run, and any dnSpy.exe in C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy-x86\ exhibits the above behavior.

ElektroKill commented 7 months ago

Just to make sure, here are the correct output paths for the completely compiled binaries:

.NET Framework: dnSpy\dnSpy\bin\Release\net48\dnSpy.exe and dnSpy\dnSpy\bin\Release\net48\dnSpy-x86.exe for the two different architectures. .NET 8: dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\dnSpy.exe for the .NET 8 64 bit version. dnSpy\dnSpy\bin\Release\net8.0-windows\win-x86\publish\dnSpy.exe for the .NET 8 32 bit version.

Other directories are either temporary and used by the compiler or produce incomplete outputs. Please ensure you are using files from the appropriate directories and that the build log contains not errors. If the errors persist try to reboot your computer and try to build again before opening any other software which could interfere with the directory.

Eiim commented 7 months ago

Thank you so much for your work and patience. I can confirm that it works as intended. I was indeed using the wrong location for the 32-bit exe. I was working off the last lines of the build output, which are:

  dnSpy -> C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\
  dnSpy-x86 -> C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy-x86\bin\Release\net8.0-windows\win-x64\dnSpy-x86.dll
  dnSpy-x86 -> C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy-x86\bin\Release\net8.0-windows\win-x64\publish\

As such I had completely overlooked dnSpy\dnSpy\bin\Release\net8.0-windows\win-x86\. It's probably a fairly standard thing but I've never done any .NET development so I was definitely confused by the release structure.

Anyways, I'm super impressed with how well this works, and dnSpyEx in general! Thanks again!

ElektroKill commented 7 months ago

Thank you so much for your work and patience. I can confirm that it works as intended. I was indeed using the wrong location for the 32-bit exe. I was working off the last lines of the build output, which are:

  dnSpy -> C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy\bin\Release\net8.0-windows\win-x64\publish\
  dnSpy-x86 -> C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy-x86\bin\Release\net8.0-windows\win-x64\dnSpy-x86.dll
  dnSpy-x86 -> C:\Users\ethan\Documents\GitHub\dnSpy\dnSpy\dnSpy-x86\bin\Release\net8.0-windows\win-x64\publish\

As such I had completely overlooked dnSpy\dnSpy\bin\Release\net8.0-windows\win-x86\. It's probably a fairly standard thing but I've never done any .NET development so I was definitely confused by the release structure.

Anyways, I'm super impressed with how well this works, and dnSpyEx in general! Thanks again!

Great to hear that you got your build working and that the feature is working well. I went ahead and merged it into master and the CI is currently building the latest version which you can grab from the link below which includes all changes from master and the environment variable editor. https://github.com/dnSpyEx/dnSpy/actions/runs/8869926845