Browse Source

Attach console to an explicitly defined PID

pull/65/head
Meivyn 3 years ago
parent
commit
d286b43c81
No known key found for this signature in database GPG Key ID: 8BDD3E48158B2F71
3 changed files with 31 additions and 6 deletions
  1. +17
    -2
      IPA.Injector/Injector.cs
  2. +4
    -4
      IPA.Loader/Logging/ConsoleWindow.cs
  3. +10
    -0
      docs/articles/command-line.md

+ 17
- 2
IPA.Injector/Injector.cs View File

@ -43,8 +43,23 @@ namespace IPA.Injector
try try
{ {
if (Environment.GetCommandLineArgs().Contains("--verbose"))
WinConsole.Initialize();
var cmd = Environment.GetCommandLineArgs();
if (cmd.Contains("--verbose"))
{
var arg = string.Empty;
for (var i = 0; i < cmd.Length; i++)
{
if (cmd[i] == "-pid")
{
arg = cmd[i + 1];
break;
}
}
WinConsole.Initialize(uint.TryParse(arg, out uint pid) ? pid : WinConsole.AttachParent);
}
SetupLibraryLoading(); SetupLibraryLoading();


+ 4
- 4
IPA.Loader/Logging/ConsoleWindow.cs View File

@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -22,11 +22,11 @@ namespace IPA.Logging
internal static bool IsInitialized; internal static bool IsInitialized;
public static void Initialize(bool alwaysCreateNewConsole = false)
public static void Initialize(uint pid, bool alwaysCreateNewConsole = false)
{ {
bool consoleAttached = true; bool consoleAttached = true;
if (alwaysCreateNewConsole if (alwaysCreateNewConsole
|| (AttachConsole(AttachParent) == 0
|| (AttachConsole(pid) == 0
&& Marshal.GetLastWin32Error() != ErrorAccessDenied)) && Marshal.GetLastWin32Error() != ErrorAccessDenied))
{ {
consoleAttached = AllocConsole() != 0; consoleAttached = AllocConsole() != 0;
@ -155,7 +155,7 @@ namespace IPA.Logging
private const uint FileAttributeNormal = 0x80; private const uint FileAttributeNormal = 0x80;
private const uint ErrorAccessDenied = 5; private const uint ErrorAccessDenied = 5;
private const uint AttachParent = 0xFFFFFFFF;
public const uint AttachParent = 0xFFFFFFFF;
#endregion #endregion
} }

+ 10
- 0
docs/articles/command-line.md View File

@ -26,6 +26,16 @@ Here's a quick list of what they are and what they do.
> Makes a console appear with log information at startup. > Makes a console appear with log information at startup.
> >
> Optionally, to start Beat Saber with an external console, an explicit `-pid` can be specified. This allows the game to be launched without being interrupted by Steam's "Allow game launch?" popup when directly launching `Beat Saber.exe` with arguments.
> - Using PowerShell:
> ```powershell
> .\steam -applaunch 620980 --verbose -pid $PID
> ```
> - Using Command Prompt:
> ```powershell
> powershell -c ".\steam -applaunch 620980 --verbose -pid (Get-CimInstance Win32_Process -Filter ProcessId=$PID).ParentProcessId"
> ```
>
- `--debug` - `--debug`


Loading…
Cancel
Save