Skip to content

Instantly share code, notes, and snippets.

@Makeshift
Last active October 10, 2023 19:53
Show Gist options
  • Save Makeshift/203dc31c97bee31cba1282da34b7ea8f to your computer and use it in GitHub Desktop.
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
###### 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
@Makeshift
Copy link
Author

Edited it to optionally output the filtered and unfiltered logs to different files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment