Modify the variable at the top to the correct directory for your game install, save to a .ps1 file and run with powershell. I included my default filters (the $filters variable) and launch args ($ArgList), but you're welcome to modify them as you wish.
There's also a function that will create a shortcut to replace the one in the start menu with this script, but it requires the script to be run as administrator so I commented it out. Feel free to turn that back on if you like.
Public gist
Edit: Modified it to optionally output the filtered and unfiltered logs to different files.
Code: Select all
###### 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 -FilePath $LogFileName
}
}
}
#Make-Shortcut
Start-X4
Write-Output "Waiting for game to start..."
Start-Sleep -s 15
Tail-Log