[TOOL] A script to launch X4, follow the debug logs and filter out extraneous log lines

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Makeshift
Posts: 2
Joined: Sun, 24. Sep 23, 01:03
x4

[TOOL] A script to launch X4, follow the debug logs and filter out extraneous log lines

Post by Makeshift » Sun, 8. Oct 23, 01:06

I found a couple of posts with powershell scripts that launch the game with arguments, but I hadn't found one that helps you keep an eye on the game as it runs and helps filter out log lines that you're not looking for, so here's my go at it.

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

Return to “X4: Foundations - Scripts and Modding”