Last active
February 7, 2025 13:43
-
-
Save Makeshift/203dc31c97bee31cba1282da34b7ea8f to your computer and use it in GitHub Desktop.
Run X4 with debug on, keeps the powershell window open following the main debug log file, and filters out some spam that usually isn't helpful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### Config ###### | |
$X4InstallDir = "C:\GOG Games\X4 Foundations" | |
# Saves the filtered logfile to $LogFileName, and the unfiltered logfile to $LogFileName-verbose | |
$SeparateVerboseLogs = $true | |
#$MakeShortcutPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\X4 - Foundations [GOG.com]\X4 - Foundations.lnk" | |
# Define filters to remove the spam from the output | |
$filters = @( | |
"======================================" | |
"Failed to verify the file signature" | |
"VROProtectRandomStationSCA" | |
".sig" | |
"ui_mon_eve_money_down_3.wav" | |
"ERR: 40962 AL_INVALID_ENUM" | |
"Economy_Verbose" | |
) | |
$X4Executable = (Get-ChildItem -path "$X4InstallDir\X4.exe").Fullname | |
$TimeStamp = Get-Date -Format "yyyy_MM_dd__hh_mm_ss" | |
$UserDocsDir = [Environment]::GetFolderPath("MyDocuments") | |
$X4UserDocsDir = Join-Path $UserDocsDir "Egosoft/X4" | |
$LogFileName = "x4-game-$TimeStamp.log" | |
$ArgLogFileName = If ($SeparateVerboseLogs) { "x4-game-$TimeStamp-verbose.log" } Else { $LogFileName } | |
$LogsDir = Join-Path $X4UserDocsDir "logs" | |
# Define arguments to pass to X4 | |
$ArgList = @( | |
"-nosoundthrottle" | |
"-nocputhrottle" | |
"-showfps" | |
"-debug all" | |
"-scriptlogfiles" | |
"-logfile $ArgLogFileName" | |
) | |
function Get-Child-Logs { | |
Get-ChildItem -Path $LogPath -Recurse -Exclude $ExcludeScriptLogs | |
} | |
# function Make-Shortcut { | |
# $ScriptPath = "$CurrentDir\$($MyInvocation.MyCommand.Name)" | |
# $WshShell = New-Object -comObject WScript.Shell | |
# $Shortcut = $WshShell.CreateShortcut("$MakeShortcutPath") | |
# $Shortcut.IconLocation = "$X4Executable, 0" | |
# $Shortcut.TargetPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" | |
# $Shortcut.Arguments = "-ExecutionPolicy ByPass -File ""$ScriptPath""" | |
# $Shortcut.Save() | |
# } | |
function Start-X4 { | |
Start-Process -WorkingDirectory $X4InstallDir -FilePath $X4Executable -ArgumentList $ArgList | |
} | |
function Tail-Log { | |
Write-Output "Tailing log file $ArgLogFileName..." | |
Get-Content "$ArgLogFileName" -wait -tail 1000 | ForEach-Object { | |
$line = $_ | |
$notMatching = $true | |
foreach ($pattern in $filters) { | |
if ($line -match $pattern) { | |
$notMatching = $false | |
break | |
} | |
} | |
if ($notMatching) { | |
Write-Output $line | |
} | |
if ($SeparateVerboseLogs) { | |
Write-Output $line | Out-File -Append -FilePath $LogFileName | |
} | |
} | |
} | |
#Make-Shortcut | |
Start-X4 | |
Write-Output "Waiting for game to start..." | |
Start-Sleep -s 15 | |
Tail-Log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edited it to optionally output the filtered and unfiltered logs to different files.